From 790122e1644be8e13bebc67275f1ae87a5861211 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Tue, 18 Jun 2024 06:21:52 +0100 Subject: [PATCH 01/28] Added helm installation script. --- scripts/install-helm.sh | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 scripts/install-helm.sh diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh new file mode 100755 index 00000000..bb1cd786 --- /dev/null +++ b/scripts/install-helm.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Check if either oc or kubectl is installed +if command_exists oc; then + CLI="oc" +elif command_exists kubectl; then + CLI="kubectl" +else + echo "Error: Neither 'oc' nor 'kubectl' is installed. Please install one of them to proceed." + exit 1 +fi + +# Check if the user is logged into a cluster +if ! $CLI whoami >/dev/null 2>&1; then + echo "Error: You are not logged into a cluster. Please log in using '$CLI login' or '$CLI config set-context'." + exit 1 +fi + +# Function to detect cluster router base +detect_cluster_router_base() { + if [ "$CLI" == "oc" ]; then + ROUTER_BASE=$($CLI get route -n default | grep -m1 'console' | awk '{print $2}') + else + ROUTER_BASE=$($CLI get ingress -A | grep -m1 'default' | awk '{print $4}') + fi +} + +# Detect cluster router base +detect_cluster_router_base + +# If detection fails, prompt user for input +if [ -z "$ROUTER_BASE" ]; then + echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." + exit 1 +fi + +# Parse command-line arguments for optional router base +while [[ "$#" -gt 0 ]]; do + case $1 in + --router-base) ROUTER_BASE="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +# Update Helm chart with the detected or provided router base +echo "Using router base: $ROUTER_BASE" +# Assuming you have a values.yaml or similar configuration for the Helm chart +sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" path/to/helm/values.yaml + +# Proceed with Helm installation +helm install my-release path/to/helm/chart --values path/to/helm/values.yaml + +echo "Helm installation completed successfully." From 60003cd6095f29629bef7220502fba4200edb8b4 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Tue, 18 Jun 2024 09:07:27 +0100 Subject: [PATCH 02/28] Copyright statement and information about the relevant Apache Licence. --- scripts/install-helm.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh index bb1cd786..e6928c4a 100755 --- a/scripts/install-helm.sh +++ b/scripts/install-helm.sh @@ -1,4 +1,22 @@ #!/bin/bash +# +# Copyright (c) 2024 Red Hat, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Script to handle CLI helm installation for k8s and OCP +# +# Requires: oc or kubectl + # Function to check if a command exists command_exists() { From 62317f8eaca688482bfaa525d881510e91df7f01 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Tue, 18 Jun 2024 15:13:37 +0100 Subject: [PATCH 03/28] Refractored the function to detect cluster router base: Instead of using a combination of commands get route or get ingress followed by grep to search for a line containing console or default and then awk to extract the desired field from that line, I went with more direct approach with -o=jsonpath option to extract the host value directly from the JSON output of the get route or get ingress command. --- scripts/install-helm.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh index e6928c4a..d346f7c7 100755 --- a/scripts/install-helm.sh +++ b/scripts/install-helm.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2024 Red Hat, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. +# You may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 @@ -17,7 +17,6 @@ # # Requires: oc or kubectl - # Function to check if a command exists command_exists() { command -v "$1" >/dev/null 2>&1 @@ -42,9 +41,9 @@ fi # Function to detect cluster router base detect_cluster_router_base() { if [ "$CLI" == "oc" ]; then - ROUTER_BASE=$($CLI get route -n default | grep -m1 'console' | awk '{print $2}') + ROUTER_BASE=$($CLI get route -n openshift-console -o=jsonpath='{.items[0].spec.host}') else - ROUTER_BASE=$($CLI get ingress -A | grep -m1 'default' | awk '{print $4}') + ROUTER_BASE=$($CLI get ingress -n default -o=jsonpath='{.items[0].spec.rules[0].host}') fi } @@ -68,10 +67,22 @@ done # Update Helm chart with the detected or provided router base echo "Using router base: $ROUTER_BASE" -# Assuming you have a values.yaml or similar configuration for the Helm chart -sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" path/to/helm/values.yaml +# Define the path to values.yaml +VALUES_FILE="../charts/backstage/values.yaml" +if [ ! -f "$VALUES_FILE" ]; then + echo "Error: values.yaml file not found at $VALUES_FILE" + exit 1 +fi +sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" + +# Define the path to the Helm chart directory +HELM_CHART_DIR="../charts/backstage" +if [ ! -d "$HELM_CHART_DIR" ]; then + echo "Error: Helm chart directory not found at $HELM_CHART_DIR" + exit 1 +fi # Proceed with Helm installation -helm install my-release path/to/helm/chart --values path/to/helm/values.yaml +helm install my-release "$HELM_CHART_DIR" --values "$VALUES_FILE" echo "Helm installation completed successfully." From 59965c6ff2a3f4e14a175be7da2be19767725648 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Tue, 18 Jun 2024 21:05:41 +0100 Subject: [PATCH 04/28] Added clear instructions and a description of the script, the options available, and examples of usage all using the usage function, this helps keep docs information centralized reducing cognitive load. --- scripts/install-helm.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh index d346f7c7..efcee3fb 100755 --- a/scripts/install-helm.sh +++ b/scripts/install-helm.sh @@ -17,6 +17,25 @@ # # Requires: oc or kubectl +usage() { +echo " +This script simplifies and automates the installation process of Helm charts on Kubernetes (K8s) and OpenShift Container Platform (OCP) clusters. +It detects whether 'oc' or 'kubectl' is installed and ensures that the user is logged into a cluster. +The script also attempts to detect the cluster router base and updates the Helm chart configuration accordingly. + +Usage: + $0 [OPTIONS] + +Options: + --router-base : Manually provide the cluster router base if auto-detection fails. + --help : Show this help message and exit. + +Examples: + $0 # Auto-detects router base and installs the Helm chart + $0 --router-base example.com # Manually specifies the router base and installs the Helm chart +" +} + # Function to check if a command exists command_exists() { command -v "$1" >/dev/null 2>&1 From 6e1a1a1d9339c379fc7d133e2cad9d549b017c4f Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Wed, 19 Jun 2024 12:16:27 +0100 Subject: [PATCH 05/28] Added --help option to display usage information. --- scripts/install.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 scripts/install.sh diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 00000000..756ddeec --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# +# Copyright (c) 2024 Red Hat, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Script to handle CLI helm installation for k8s and OCP +# +# Requires: oc or kubectl + +usage() { +echo " +This script simplifies and automates the installation process of Helm charts on Kubernetes (K8s) and OpenShift Container Platform (OCP) clusters. +It detects whether 'oc' or 'kubectl' is installed and ensures that the user is logged into a cluster. +The script also attempts to detect the cluster router base and updates the Helm chart configuration accordingly. + +Usage: + $0 [OPTIONS] + +Options: + --router-base : Manually provide the cluster router base if auto-detection fails. + --help : Show this help message and exit. + +Examples: + $0 # Auto-detects router base and installs the Helm chart + $0 --router-base example.com # Manually specifies the router base and installs the Helm chart +" +} + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Check if either oc or kubectl is installed +if command_exists oc; then + CLI="oc" +elif command_exists kubectl; then + CLI="kubectl" +else + echo "Error: Neither 'oc' nor 'kubectl' is installed. Please install one of them to proceed." + exit 1 +fi + +# Check if the user is logged into a cluster +if ! $CLI whoami >/dev/null 2>&1; then + echo "Error: You are not logged into a cluster. Please log in using '$CLI login' or '$CLI config set-context'." + exit 1 +fi + +# Function to detect cluster router base +detect_cluster_router_base() { + if [ "$CLI" == "oc" ]; then + ROUTER_BASE=$($CLI get route -n openshift-console -o=jsonpath='{.items[0].spec.host}') + else + ROUTER_BASE=$($CLI get ingress -n default -o=jsonpath='{.items[0].spec.rules[0].host}') + fi +} + +# Detect cluster router base +detect_cluster_router_base + +# If detection fails, prompt user for input +if [ -z "$ROUTER_BASE" ]; then + echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." + exit 1 +fi + +# Parse command-line arguments for optional router base +while [[ "$#" -gt 0 ]]; do + case $1 in + --router-base) ROUTER_BASE="$2"; shift ;; + --help) usage; exit 0 ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +# Update Helm chart with the detected or provided router base +echo "Using router base: $ROUTER_BASE" +# Define the path to values.yaml +VALUES_FILE="../charts/backstage/values.yaml" +if [ ! -f "$VALUES_FILE" ]; then + echo "Error: values.yaml file not found at $VALUES_FILE" + exit 1 +fi +sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" + +# Define the path to the Helm chart directory +HELM_CHART_DIR="../charts/backstage" +if [ ! -d "$HELM_CHART_DIR" ]; then + echo "Error: Helm chart directory not found at $HELM_CHART_DIR" + exit 1 +fi + +# Proceed with Helm installation +helm install my-release "$HELM_CHART_DIR" --values "$VALUES_FILE" + +echo "Helm installation completed successfully." From 733f5f8db1e35c4f8a38e2c138cf10d76552519e Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Wed, 19 Jun 2024 12:21:46 +0100 Subject: [PATCH 06/28] .sh file name change as noted that the install-helm.sh file makes it sound like it stalls he Helm executable. --- scripts/install-helm.sh | 107 ---------------------------------------- 1 file changed, 107 deletions(-) delete mode 100755 scripts/install-helm.sh diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh deleted file mode 100755 index efcee3fb..00000000 --- a/scripts/install-helm.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2024 Red Hat, Inc. -# Licensed under the Apache License, Version 2.0 (the "License"); -# You may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Script to handle CLI helm installation for k8s and OCP -# -# Requires: oc or kubectl - -usage() { -echo " -This script simplifies and automates the installation process of Helm charts on Kubernetes (K8s) and OpenShift Container Platform (OCP) clusters. -It detects whether 'oc' or 'kubectl' is installed and ensures that the user is logged into a cluster. -The script also attempts to detect the cluster router base and updates the Helm chart configuration accordingly. - -Usage: - $0 [OPTIONS] - -Options: - --router-base : Manually provide the cluster router base if auto-detection fails. - --help : Show this help message and exit. - -Examples: - $0 # Auto-detects router base and installs the Helm chart - $0 --router-base example.com # Manually specifies the router base and installs the Helm chart -" -} - -# Function to check if a command exists -command_exists() { - command -v "$1" >/dev/null 2>&1 -} - -# Check if either oc or kubectl is installed -if command_exists oc; then - CLI="oc" -elif command_exists kubectl; then - CLI="kubectl" -else - echo "Error: Neither 'oc' nor 'kubectl' is installed. Please install one of them to proceed." - exit 1 -fi - -# Check if the user is logged into a cluster -if ! $CLI whoami >/dev/null 2>&1; then - echo "Error: You are not logged into a cluster. Please log in using '$CLI login' or '$CLI config set-context'." - exit 1 -fi - -# Function to detect cluster router base -detect_cluster_router_base() { - if [ "$CLI" == "oc" ]; then - ROUTER_BASE=$($CLI get route -n openshift-console -o=jsonpath='{.items[0].spec.host}') - else - ROUTER_BASE=$($CLI get ingress -n default -o=jsonpath='{.items[0].spec.rules[0].host}') - fi -} - -# Detect cluster router base -detect_cluster_router_base - -# If detection fails, prompt user for input -if [ -z "$ROUTER_BASE" ]; then - echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." - exit 1 -fi - -# Parse command-line arguments for optional router base -while [[ "$#" -gt 0 ]]; do - case $1 in - --router-base) ROUTER_BASE="$2"; shift ;; - *) echo "Unknown parameter passed: $1"; exit 1 ;; - esac - shift -done - -# Update Helm chart with the detected or provided router base -echo "Using router base: $ROUTER_BASE" -# Define the path to values.yaml -VALUES_FILE="../charts/backstage/values.yaml" -if [ ! -f "$VALUES_FILE" ]; then - echo "Error: values.yaml file not found at $VALUES_FILE" - exit 1 -fi -sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" - -# Define the path to the Helm chart directory -HELM_CHART_DIR="../charts/backstage" -if [ ! -d "$HELM_CHART_DIR" ]; then - echo "Error: Helm chart directory not found at $HELM_CHART_DIR" - exit 1 -fi - -# Proceed with Helm installation -helm install my-release "$HELM_CHART_DIR" --values "$VALUES_FILE" - -echo "Helm installation completed successfully." From 45c1e1f4352bd3c34014c5b4947cfde8023be048 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Wed, 19 Jun 2024 14:12:04 +0100 Subject: [PATCH 07/28] Added --cli option to specify which CLI tool to use. Included logic to validate the --cli parameter. Retained the automatic detection of CLI if --cli is not provided. Updated usage instructions to reflect the new --cli option. --- scripts/install.sh | 78 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 756ddeec..d7991d42 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -27,11 +27,13 @@ Usage: $0 [OPTIONS] Options: - --router-base : Manually provide the cluster router base if auto-detection fails. - --help : Show this help message and exit. + --cli : Specify the CLI tool to use (overrides auto-detection). + --router-base : Manually provide the cluster router base if auto-detection fails. + --help : Show this help message and exit. Examples: $0 # Auto-detects router base and installs the Helm chart + $0 --cli kubectl # Uses kubectl even if oc is installed $0 --router-base example.com # Manually specifies the router base and installs the Helm chart " } @@ -41,14 +43,52 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } -# Check if either oc or kubectl is installed -if command_exists oc; then - CLI="oc" -elif command_exists kubectl; then - CLI="kubectl" -else - echo "Error: Neither 'oc' nor 'kubectl' is installed. Please install one of them to proceed." - exit 1 +# Default CLI detection +detect_cli() { + if command_exists oc; then + CLI="oc" + elif command_exists kubectl; then + CLI="kubectl" + else + echo "Error: Neither 'oc' nor 'kubectl' is installed. Please install one of them to proceed." + exit 1 + fi +} + +# Parse command-line arguments for CLI tool and optional router base +CLI="" +ROUTER_BASE="" + +while [[ "$#" -gt 0 ]]; do + case $1 in + --cli) + CLI="$2" + if [[ "$CLI" != "oc" && "$CLI" != "kubectl" ]]; then + echo "Error: Invalid value for --cli. Use 'oc' or 'kubectl'." + exit 1 + fi + shift + ;; + --router-base) + ROUTER_BASE="$2" + shift + ;; + --help) + usage + exit 0 + ;; + *) + echo "Unknown parameter passed: $1" + usage + exit 1 + ;; + esac + shift +done + +# If CLI is not specified, detect automatically +if [[ -z "$CLI" ]]; then + detect_cli fi # Check if the user is logged into a cluster @@ -66,25 +106,17 @@ detect_cluster_router_base() { fi } -# Detect cluster router base -detect_cluster_router_base +# Detect cluster router base if not provided +if [[ -z "$ROUTER_BASE" ]]; then + detect_cluster_router_base +fi # If detection fails, prompt user for input -if [ -z "$ROUTER_BASE" ]; then +if [[ -z "$ROUTER_BASE" ]]; then echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." exit 1 fi -# Parse command-line arguments for optional router base -while [[ "$#" -gt 0 ]]; do - case $1 in - --router-base) ROUTER_BASE="$2"; shift ;; - --help) usage; exit 0 ;; - *) echo "Unknown parameter passed: $1"; exit 1 ;; - esac - shift -done - # Update Helm chart with the detected or provided router base echo "Using router base: $ROUTER_BASE" # Define the path to values.yaml From 40aa740d298eef186a426a9158a59d689c30ec62 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Wed, 19 Jun 2024 14:54:22 +0100 Subject: [PATCH 08/28] Placed the checks for essential information at the top of the file ensuring that the script exists early if the necessary components are not available. This prevents unnecessary execution of other parts of the script. --- scripts/install.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index d7991d42..a556ea8b 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -18,7 +18,7 @@ # Requires: oc or kubectl usage() { -echo " + echo " This script simplifies and automates the installation process of Helm charts on Kubernetes (K8s) and OpenShift Container Platform (OCP) clusters. It detects whether 'oc' or 'kubectl' is installed and ensures that the user is logged into a cluster. The script also attempts to detect the cluster router base and updates the Helm chart configuration accordingly. @@ -43,6 +43,20 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } +# Check if required files and directories exist +HELM_CHART_DIR="../charts/backstage" +VALUES_FILE="$HELM_CHART_DIR/values.yaml" + +if [ ! -d "$HELM_CHART_DIR" ]; then + echo "Error: Helm chart directory not found at $HELM_CHART_DIR" + exit 1 +fi + +if [ ! -f "$VALUES_FILE" ]; then + echo "Error: values.yaml file not found at $VALUES_FILE" + exit 1 +fi + # Default CLI detection detect_cli() { if command_exists oc; then @@ -119,21 +133,8 @@ fi # Update Helm chart with the detected or provided router base echo "Using router base: $ROUTER_BASE" -# Define the path to values.yaml -VALUES_FILE="../charts/backstage/values.yaml" -if [ ! -f "$VALUES_FILE" ]; then - echo "Error: values.yaml file not found at $VALUES_FILE" - exit 1 -fi sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" -# Define the path to the Helm chart directory -HELM_CHART_DIR="../charts/backstage" -if [ ! -d "$HELM_CHART_DIR" ]; then - echo "Error: Helm chart directory not found at $HELM_CHART_DIR" - exit 1 -fi - # Proceed with Helm installation helm install my-release "$HELM_CHART_DIR" --values "$VALUES_FILE" From d4a5a5c1d8d7928df5616c932a4a958839f411e9 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Wed, 19 Jun 2024 16:50:33 +0100 Subject: [PATCH 09/28] Support for --release-name and --generate-name options: Allows users to specify a custom release name or generate one automatically. --- scripts/install.sh | 50 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index a556ea8b..1c836585 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -18,7 +18,7 @@ # Requires: oc or kubectl usage() { - echo " +echo " This script simplifies and automates the installation process of Helm charts on Kubernetes (K8s) and OpenShift Container Platform (OCP) clusters. It detects whether 'oc' or 'kubectl' is installed and ensures that the user is logged into a cluster. The script also attempts to detect the cluster router base and updates the Helm chart configuration accordingly. @@ -29,12 +29,17 @@ Usage: Options: --cli : Specify the CLI tool to use (overrides auto-detection). --router-base : Manually provide the cluster router base if auto-detection fails. + --release-name : Specify a custom release name for the Helm chart. + --generate-name : Generate a name for the Helm release (overrides --release-name). + --namespace : Specify the namespace for the Helm release (autodetects if not provided). --help : Show this help message and exit. Examples: $0 # Auto-detects router base and installs the Helm chart $0 --cli kubectl # Uses kubectl even if oc is installed $0 --router-base example.com # Manually specifies the router base and installs the Helm chart + $0 --release-name myrelease # Installs the Helm chart with the specified release name + $0 --generate-name # Generates a name for the Helm release " } @@ -69,9 +74,12 @@ detect_cli() { fi } -# Parse command-line arguments for CLI tool and optional router base +# Parse command-line arguments CLI="" ROUTER_BASE="" +RELEASE_NAME="" +GENERATE_NAME=false +NAMESPACE="" while [[ "$#" -gt 0 ]]; do case $1 in @@ -87,6 +95,17 @@ while [[ "$#" -gt 0 ]]; do ROUTER_BASE="$2" shift ;; + --release-name) + RELEASE_NAME="$2" + shift + ;; + --generate-name) + GENERATE_NAME=true + ;; + --namespace) + NAMESPACE="$2" + shift + ;; --help) usage exit 0 @@ -131,11 +150,34 @@ if [[ -z "$ROUTER_BASE" ]]; then exit 1 fi +# Detect namespace if not provided +if [[ -z "$NAMESPACE" ]]; then + NAMESPACE=$($CLI config view --minify --output 'jsonpath={..namespace}') + if [[ -z "$NAMESPACE" ]]; then + echo "Error: Namespace could not be detected. Please provide it using the --namespace flag." + exit 1 + fi +fi + # Update Helm chart with the detected or provided router base echo "Using router base: $ROUTER_BASE" sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" -# Proceed with Helm installation -helm install my-release "$HELM_CHART_DIR" --values "$VALUES_FILE" +# Construct Helm install command +HELM_CMD="helm install" +if $GENERATE_NAME; then + HELM_CMD+=" --generate-name" +else + if [[ -z "$RELEASE_NAME" ]]; then + echo "Error: Either --release-name must be specified or --generate-name must be used." + exit 1 + fi + HELM_CMD+=" $RELEASE_NAME" +fi + +HELM_CMD+=" $HELM_CHART_DIR --values $VALUES_FILE --namespace $NAMESPACE" + +# Execute Helm install command +eval $HELM_CMD echo "Helm installation completed successfully." From 8996e310bae3c1ff4a2e1c9a76f12b804346d0b1 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 24 Jun 2024 11:45:03 +0100 Subject: [PATCH 10/28] Using dirname to determine the base directory of the script ensuring that it can be executed from any location on the filesystem. In addition capturing additional arguments and appending extra arguments. --- scripts/install.sh | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 1c836585..b7b9e03b 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -15,7 +15,7 @@ # # Script to handle CLI helm installation for k8s and OCP # -# Requires: oc or kubectl +# Requires: oc or kubectl and an active login session to a cluster. usage() { echo " @@ -32,6 +32,7 @@ Options: --release-name : Specify a custom release name for the Helm chart. --generate-name : Generate a name for the Helm release (overrides --release-name). --namespace : Specify the namespace for the Helm release (autodetects if not provided). + --values : Specify your own values file for the Helm chart. --help : Show this help message and exit. Examples: @@ -40,6 +41,7 @@ Examples: $0 --router-base example.com # Manually specifies the router base and installs the Helm chart $0 --release-name myrelease # Installs the Helm chart with the specified release name $0 --generate-name # Generates a name for the Helm release + $0 --values /path/to/values.yaml # Installs the Helm chart using the specified values file " } @@ -49,19 +51,14 @@ command_exists() { } # Check if required files and directories exist -HELM_CHART_DIR="../charts/backstage" -VALUES_FILE="$HELM_CHART_DIR/values.yaml" +HELM_CHART_DIR="$(dirname "$0")/../charts/backstage" +DEFAULT_VALUES_FILE="$HELM_CHART_DIR/values.yaml" if [ ! -d "$HELM_CHART_DIR" ]; then echo "Error: Helm chart directory not found at $HELM_CHART_DIR" exit 1 fi -if [ ! -f "$VALUES_FILE" ]; then - echo "Error: values.yaml file not found at $VALUES_FILE" - exit 1 -fi - # Default CLI detection detect_cli() { if command_exists oc; then @@ -80,6 +77,8 @@ ROUTER_BASE="" RELEASE_NAME="" GENERATE_NAME=false NAMESPACE="" +VALUES_FILE="$DEFAULT_VALUES_FILE" +EXTRA_HELM_ARGS="" while [[ "$#" -gt 0 ]]; do case $1 in @@ -106,14 +105,16 @@ while [[ "$#" -gt 0 ]]; do NAMESPACE="$2" shift ;; + --values) + VALUES_FILE="$2" + shift + ;; --help) usage exit 0 ;; *) - echo "Unknown parameter passed: $1" - usage - exit 1 + EXTRA_HELM_ARGS+=" $1" ;; esac shift @@ -159,9 +160,11 @@ if [[ -z "$NAMESPACE" ]]; then fi fi -# Update Helm chart with the detected or provided router base -echo "Using router base: $ROUTER_BASE" -sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" +# Update Helm chart with the detected or provided router base if using default values file +if [[ "$VALUES_FILE" == "$DEFAULT_VALUES_FILE" ]]; then + echo "Using router base: $ROUTER_BASE" + sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" +fi # Construct Helm install command HELM_CMD="helm install" @@ -175,7 +178,7 @@ else HELM_CMD+=" $RELEASE_NAME" fi -HELM_CMD+=" $HELM_CHART_DIR --values $VALUES_FILE --namespace $NAMESPACE" +HELM_CMD+=" $HELM_CHART_DIR --values $VALUES_FILE --namespace $NAMESPACE $EXTRA_HELM_ARGS" # Execute Helm install command eval $HELM_CMD From 7673f4bb1c28bf45b20fd6d282e7438a215e564a Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 24 Jun 2024 12:02:56 +0100 Subject: [PATCH 11/28] Removed login check because we already provide feedback if the user is not logged in through Helm and other commands. --- scripts/install.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index b7b9e03b..2a55f241 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -125,12 +125,6 @@ if [[ -z "$CLI" ]]; then detect_cli fi -# Check if the user is logged into a cluster -if ! $CLI whoami >/dev/null 2>&1; then - echo "Error: You are not logged into a cluster. Please log in using '$CLI login' or '$CLI config set-context'." - exit 1 -fi - # Function to detect cluster router base detect_cluster_router_base() { if [ "$CLI" == "oc" ]; then From 77042aef1657e779e9b0d488e192b2c5375b6ac4 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 24 Jun 2024 12:35:04 +0100 Subject: [PATCH 12/28] Updated the detect_cluster_router_base function to use oc get ingress.config.openshift.io/cluster to fetch the correct router base domain on OpenShift. --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 2a55f241..679c8488 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -128,7 +128,7 @@ fi # Function to detect cluster router base detect_cluster_router_base() { if [ "$CLI" == "oc" ]; then - ROUTER_BASE=$($CLI get route -n openshift-console -o=jsonpath='{.items[0].spec.host}') + ROUTER_BASE=$($CLI get ingress.config.openshift.io/cluster -o=jsonpath='{.spec.domain}') else ROUTER_BASE=$($CLI get ingress -n default -o=jsonpath='{.items[0].spec.rules[0].host}') fi From a99005905db8dfbad64a22562134e26aab5627b3 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 25 Jun 2024 09:23:53 +0100 Subject: [PATCH 13/28] Refactored the script to only handle the CLI Helm installation for OCP. --- scripts/install.sh | 88 +++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 679c8488..82a6acc6 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -13,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# Script to handle CLI helm installation for k8s and OCP +# Script to handle CLI helm installation for OCP # -# Requires: oc or kubectl and an active login session to a cluster. +# Requires: oc and an active login session to a cluster. + +set -e usage() { -echo " -This script simplifies and automates the installation process of Helm charts on Kubernetes (K8s) and OpenShift Container Platform (OCP) clusters. -It detects whether 'oc' or 'kubectl' is installed and ensures that the user is logged into a cluster. -The script also attempts to detect the cluster router base and updates the Helm chart configuration accordingly. + echo " +This script simplifies and automates the installation process of Helm charts on the OpenShift Container Platform (OCP) clusters. +It ensures that the user is logged into a cluster and attempts to detect the cluster router base, updating the Helm chart configuration accordingly. Usage: $0 [OPTIONS] Options: - --cli : Specify the CLI tool to use (overrides auto-detection). --router-base : Manually provide the cluster router base if auto-detection fails. --release-name : Specify a custom release name for the Helm chart. --generate-name : Generate a name for the Helm release (overrides --release-name). @@ -37,7 +37,6 @@ Options: Examples: $0 # Auto-detects router base and installs the Helm chart - $0 --cli kubectl # Uses kubectl even if oc is installed $0 --router-base example.com # Manually specifies the router base and installs the Helm chart $0 --release-name myrelease # Installs the Helm chart with the specified release name $0 --generate-name # Generates a name for the Helm release @@ -50,6 +49,12 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } +# Check for required commands +if ! command_exists helm || ! command_exists oc; then + echo "Error: Required commands 'helm' and 'oc' are not available." + exit 1 +fi + # Check if required files and directories exist HELM_CHART_DIR="$(dirname "$0")/../charts/backstage" DEFAULT_VALUES_FILE="$HELM_CHART_DIR/values.yaml" @@ -59,20 +64,7 @@ if [ ! -d "$HELM_CHART_DIR" ]; then exit 1 fi -# Default CLI detection -detect_cli() { - if command_exists oc; then - CLI="oc" - elif command_exists kubectl; then - CLI="kubectl" - else - echo "Error: Neither 'oc' nor 'kubectl' is installed. Please install one of them to proceed." - exit 1 - fi -} - # Parse command-line arguments -CLI="" ROUTER_BASE="" RELEASE_NAME="" GENERATE_NAME=false @@ -82,14 +74,6 @@ EXTRA_HELM_ARGS="" while [[ "$#" -gt 0 ]]; do case $1 in - --cli) - CLI="$2" - if [[ "$CLI" != "oc" && "$CLI" != "kubectl" ]]; then - echo "Error: Invalid value for --cli. Use 'oc' or 'kubectl'." - exit 1 - fi - shift - ;; --router-base) ROUTER_BASE="$2" shift @@ -120,38 +104,25 @@ while [[ "$#" -gt 0 ]]; do shift done -# If CLI is not specified, detect automatically -if [[ -z "$CLI" ]]; then - detect_cli -fi - # Function to detect cluster router base detect_cluster_router_base() { - if [ "$CLI" == "oc" ]; then - ROUTER_BASE=$($CLI get ingress.config.openshift.io/cluster -o=jsonpath='{.spec.domain}') - else - ROUTER_BASE=$($CLI get ingress -n default -o=jsonpath='{.items[0].spec.rules[0].host}') - fi + ROUTER_BASE=$(oc get ingress.config.openshift.io/cluster -o=jsonpath='{.spec.domain}') } # Detect cluster router base if not provided if [[ -z "$ROUTER_BASE" ]]; then detect_cluster_router_base -fi - -# If detection fails, prompt user for input -if [[ -z "$ROUTER_BASE" ]]; then +else echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." exit 1 fi # Detect namespace if not provided if [[ -z "$NAMESPACE" ]]; then - NAMESPACE=$($CLI config view --minify --output 'jsonpath={..namespace}') - if [[ -z "$NAMESPACE" ]]; then - echo "Error: Namespace could not be detected. Please provide it using the --namespace flag." - exit 1 - fi + NAMESPACE=$(oc config view --minify --output 'jsonpath={..namespace}') +else + echo "Error: Namespace could not be detected. Please provide it using the --namespace flag." + exit 1 fi # Update Helm chart with the detected or provided router base if using default values file @@ -161,20 +132,25 @@ if [[ "$VALUES_FILE" == "$DEFAULT_VALUES_FILE" ]]; then fi # Construct Helm install command -HELM_CMD="helm install" -if $GENERATE_NAME; then +HELM_CMD="helm upgrade --install" +if [[ $GENERATE_NAME == true ]]; then HELM_CMD+=" --generate-name" +elif [[ -z "$RELEASE_NAME" ]]; then + echo "Error: Either --release-name must be specified or --generate-name must be used." + exit 1 else - if [[ -z "$RELEASE_NAME" ]]; then - echo "Error: Either --release-name must be specified or --generate-name must be used." - exit 1 - fi HELM_CMD+=" $RELEASE_NAME" fi + HELM_CMD+=" $HELM_CHART_DIR --values $VALUES_FILE --namespace $NAMESPACE $EXTRA_HELM_ARGS" # Execute Helm install command -eval $HELM_CMD +echo "Executing: $HELM_CMD" -echo "Helm installation completed successfully." +if eval "$HELM_CMD"; then + echo "Helm installation completed successfully." +else + echo "Something went wrong with Helm installation!" + exit 1 +fi \ No newline at end of file From bc57eed1560c485302c0211df4b5f1635e8613fd Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Fri, 28 Jun 2024 09:59:19 +0100 Subject: [PATCH 14/28] Added install.md file. --- scripts/install.md | 173 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 scripts/install.md diff --git a/scripts/install.md b/scripts/install.md new file mode 100644 index 00000000..d650667d --- /dev/null +++ b/scripts/install.md @@ -0,0 +1,173 @@ +## **Documentation for the script to handle CLI helm installation for OCP** + +Jira Issue - [RHIDP-2706](https://issues.redhat.com/browse/RHIDP-2706) + + +## **Overview** + +The purpose of the `install-helm.sh` script is to simplify and automate the installation process of Helm charts on OpenShift Container Platform (OCP) clusters. Instead of requiring users to follow a lengthy and potentially error-prone series of manual steps, this script consolidates the process into a single, reusable command that can: + + + +* Detect if oc is installed; fail if not found and report the error to the user with a call to action re: installing it. +* Detect if the user is logged into a cluster and fail if not with the call to action (oc command to log in). +* If cluster router base can be detected, use that value to update the helm chart installation; if not, fail and request user pass in command line flag as cluster router base could not be detected (can test this failure case with dev sandbox; can test passing case with clusterbot). + + +## **Prerequisites** + + + +1. Ensure that `oc` (for OpenShift) is installed. +2. Ensure that you are logged into an OCP cluster and that it is running. + + +## **Installation Steps** + +**Download the Script \ +**Clone the repository and navigate to the `scripts` directory: + +**Make the Script Executable \ +**Before running the script, make sure it has executable permissions: + +**Run the Script \ +**Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. + +**Specify Router Base** + +If the script cannot automatically detect the cluster router base, you can provide it manually using the `-router-base` flag. \ + + +Example: + + +### **Specify Release Name** + +To install the Helm chart with a custom release name + + +### **Generate a Release Name** + +To generate a name for the Helm release + + +### **Specify Namespace** + +To specify the namespace for the Helm release + + +### **Specify Custom Values File** + +To use a custom values file for the Helm chart + + +### **Troubleshooting** + + + +* **Missing oc: \ + \ + If the script outputs an error indicating that neither oc nor kubectl is installed, please install the appropriate CLI tool for your cluster: \ + + * For OpenShift: Install oc + * For Kubernetes: Install kubectl +* Not Logged Into Cluster: \ + \ + If you are not logged into a cluster, follow these steps to log in: \ + + * For OpenShift: +* Router Base Detection Failed: \ + \ + If the script cannot detect the cluster router base, manually provide it using the --router-base flag as shown in the example usage section. \ + +* Error: INSTALLATION FAILED: + + An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies: found in Chart.yaml, but missing in charts/ directory: common, backstage: + + * If you get an error saying: “Error: Chart.yaml file is missing”. Change the directory to the backstage directory for example: cd ../charts/backstage/ Then run helm dependency build again. + * You should then see an error like: + + “Error: no repository definition for https://charts.bitnami.com/bitnami, https://backstage.github.io/charts. Please add the missing repos via 'helm repo add'” + + + If you received this error simply add the repositories like this: + + * Your output should be: + + "bitnami" has been added to your repositories + + + "backstage" has been added to your repositories + + * Next run: helm repo list + * You should see: + + NAME URL + + + redhat-developer https://redhat-developer.github.io/rhdh-chart/ + + + bitnami https://charts.bitnami.com/bitnami + + + backstage https://backstage.github.io/charts + + +Then run: + +The output should be: + +Hang tight while we grab the latest from your chart repositories... + +...Successfully got an update from the "backstage" chart repository + +...Successfully got an update from the "redhat-developer" chart repository + +...Successfully got an update from the "bitnami" chart repository + +Update Complete. ⎈Happy Helming!⎈ + +Saving 2 charts + +Downloading common from repo https://charts.bitnami.com/bitnami + +Downloading backstage from repo https://backstage.github.io/charts + +Deleting outdated charts + +Next, navigate to the install-helm.sh file in the scripts directory and run: + +An example of the output should be: + +Using router base: example.com + +NAME: my-release + +LAST DEPLOYED: Tue Jun 18 11:32:15 2024 + +NAMESPACE: default + +STATUS: deployed + +REVISION: 1 + +Helm installation completed successfully. + +You can run: helm version to confirm this installation the output should be: + +version.BuildInfo{Version:"v3.11", GitCommit:"", GitTreeState:"", GoVersion:"go1.21.6"} + +**Script Details** + +The `install-helm.sh` script performs the following tasks: + + + +1. Check if `oc `is installed. +2. Verifies that the user is logged into a cluster. +3. Attempts to detect the cluster router base. +4. Updates the Helm chart configuration with the detected or provided router base. +5. Install the Helm chart using the configured settings. + +Following the above instructions, you can easily and reliably install Helm charts on your K8s or OCP cluster using the `install-helm.sh` script. From 8ba23d9970f4eed6e4bdb6dade28c7aabe372aca Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Fri, 28 Jun 2024 10:01:30 +0100 Subject: [PATCH 15/28] Update install.md --- scripts/install.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/install.md b/scripts/install.md index d650667d..12e80c3f 100644 --- a/scripts/install.md +++ b/scripts/install.md @@ -24,14 +24,14 @@ The purpose of the `install-helm.sh` script is to simplify and automate the inst ## **Installation Steps** -**Download the Script \ -**Clone the repository and navigate to the `scripts` directory: +Download the Script \ +Clone the repository and navigate to the `scripts` directory: -**Make the Script Executable \ -**Before running the script, make sure it has executable permissions: +Make the Script Executable \ +Before running the script, make sure it has executable permissions: -**Run the Script \ -**Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. +Run the Script \ +Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. **Specify Router Base** From 1b5f427669e3cf71d7246a2398001de8a27da1fc Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Fri, 28 Jun 2024 10:40:34 +0100 Subject: [PATCH 16/28] Update install.md --- scripts/install.md | 144 +++++++++++---------------------------------- 1 file changed, 33 insertions(+), 111 deletions(-) diff --git a/scripts/install.md b/scripts/install.md index 12e80c3f..d71254f7 100644 --- a/scripts/install.md +++ b/scripts/install.md @@ -1,8 +1,5 @@ ## **Documentation for the script to handle CLI helm installation for OCP** -Jira Issue - [RHIDP-2706](https://issues.redhat.com/browse/RHIDP-2706) - - ## **Overview** The purpose of the `install-helm.sh` script is to simplify and automate the installation process of Helm charts on OpenShift Container Platform (OCP) clusters. Instead of requiring users to follow a lengthy and potentially error-prone series of manual steps, this script consolidates the process into a single, reusable command that can: @@ -24,150 +21,75 @@ The purpose of the `install-helm.sh` script is to simplify and automate the inst ## **Installation Steps** -Download the Script \ -Clone the repository and navigate to the `scripts` directory: - -Make the Script Executable \ -Before running the script, make sure it has executable permissions: - -Run the Script \ -Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. - -**Specify Router Base** - -If the script cannot automatically detect the cluster router base, you can provide it manually using the `-router-base` flag. \ +1. **Download the Script** - Clone the repository and navigate to the `scripts` directory: \ +`git clone /rhdh-chart.git +cd rhdh-chart/scripts` -Example: +2. **Make the Script Executable** - Before running the script, make sure it has executable permissions: \ +`chmod +x install.sh` -### **Specify Release Name** +3. **Run the Script** - Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. \ +`./install.sh` -To install the Helm chart with a custom release name + **Specify Router Base** - If the script cannot automatically detect the cluster router base, you can provide it manually using the `-router-base` flag, example:\ + `./install.sh --router-base ` -### **Generate a Release Name** -To generate a name for the Helm release +4. **Specify Release Name** - To install the Helm chart with a custom release name: \ +`./install.sh --release-name myrelease` + **Generate a Release Name** - To generate a name for the Helm release: \ + `./install.sh --generate-name` -### **Specify Namespace** +5. **Specify Namespace** - To specify the namespace for the Helm release: \ +`./install.sh --namespace mynamespace` -To specify the namespace for the Helm release + **Specify Custom Values File** - To use a custom values file for the Helm chart: \ + `./install.sh --values /path/to/values.yaml` -### **Specify Custom Values File** -To use a custom values file for the Helm chart -### **Troubleshooting** +## **Troubleshooting** - -* **Missing oc: \ - \ - If the script outputs an error indicating that neither oc nor kubectl is installed, please install the appropriate CLI tool for your cluster: \ - +* Missing oc - If the script outputs an error indicating that neither oc nor kubectl is installed, please install the appropriate CLI tool for your cluster: * For OpenShift: Install oc * For Kubernetes: Install kubectl -* Not Logged Into Cluster: \ - \ - If you are not logged into a cluster, follow these steps to log in: \ + +* Not Logged Into Cluster: If you are not logged into a cluster, follow these steps to log in: * For OpenShift: -* Router Base Detection Failed: \ - \ - If the script cannot detect the cluster router base, manually provide it using the --router-base flag as shown in the example usage section. \ - -* Error: INSTALLATION FAILED: - - An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies: found in Chart.yaml, but missing in charts/ directory: common, backstage: - - * If you get an error saying: “Error: Chart.yaml file is missing”. Change the directory to the backstage directory for example: cd ../charts/backstage/ Then run helm dependency build again. - * You should then see an error like: - - “Error: no repository definition for https://charts.bitnami.com/bitnami, https://backstage.github.io/charts. Please add the missing repos via 'helm repo add'” - - - If you received this error simply add the repositories like this: - - * Your output should be: - - "bitnami" has been added to your repositories - - - "backstage" has been added to your repositories - - * Next run: helm repo list - * You should see: - - NAME URL + `oc login ` - redhat-developer https://redhat-developer.github.io/rhdh-chart/ +* Router Base Detection Failed: - If the script cannot detect the cluster router base, manually provide it using the --router-base flag as shown in the example usage section. - bitnami https://charts.bitnami.com/bitnami - - - backstage https://backstage.github.io/charts - - -Then run: - -The output should be: - -Hang tight while we grab the latest from your chart repositories... - -...Successfully got an update from the "backstage" chart repository - -...Successfully got an update from the "redhat-developer" chart repository - -...Successfully got an update from the "bitnami" chart repository - -Update Complete. ⎈Happy Helming!⎈ - -Saving 2 charts - -Downloading common from repo https://charts.bitnami.com/bitnami - -Downloading backstage from repo https://backstage.github.io/charts +* Error: INSTALLATION FAILED: -Deleting outdated charts + An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies: found in Chart.yaml, but missing in charts/ directory: common, backstage: + `helm dependency build` -Next, navigate to the install-helm.sh file in the scripts directory and run: -An example of the output should be: +An example of the installation output should be: Using router base: example.com -NAME: my-release +NAME: ... -LAST DEPLOYED: Tue Jun 18 11:32:15 2024 +LAST DEPLOYED: ... -NAMESPACE: default +NAMESPACE: ... -STATUS: deployed +STATUS: ... -REVISION: 1 +REVISION: ... Helm installation completed successfully. -You can run: helm version to confirm this installation the output should be: - -version.BuildInfo{Version:"v3.11", GitCommit:"", GitTreeState:"", GoVersion:"go1.21.6"} - -**Script Details** - -The `install-helm.sh` script performs the following tasks: - - - -1. Check if `oc `is installed. -2. Verifies that the user is logged into a cluster. -3. Attempts to detect the cluster router base. -4. Updates the Helm chart configuration with the detected or provided router base. -5. Install the Helm chart using the configured settings. - -Following the above instructions, you can easily and reliably install Helm charts on your K8s or OCP cluster using the `install-helm.sh` script. +You can run: `helm version` to confirm this installation. From ca84b3696ae25e4bdf3d052bc713ba27c75a3584 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 1 Jul 2024 09:39:24 +0100 Subject: [PATCH 17/28] Add suggestions --- scripts/install.md | 54 ++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/scripts/install.md b/scripts/install.md index d71254f7..7bf15555 100644 --- a/scripts/install.md +++ b/scripts/install.md @@ -2,80 +2,62 @@ ## **Overview** -The purpose of the `install-helm.sh` script is to simplify and automate the installation process of Helm charts on OpenShift Container Platform (OCP) clusters. Instead of requiring users to follow a lengthy and potentially error-prone series of manual steps, this script consolidates the process into a single, reusable command that can: +The purpose of the [`install.sh` script](./install.sh) is to simplify and automate the installation process of this Helm Chart on OpenShift Container Platform (OCP) clusters. Instead of requiring users to follow a lengthy and potentially error-prone series of manual steps, this script consolidates the process into a single, reusable command that can: +* Detect if the OpenShit Client ([`oc`](https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html)) is installed; fail if not found and report the error to the user with a call to action (installing it). - -* Detect if oc is installed; fail if not found and report the error to the user with a call to action re: installing it. -* Detect if the user is logged into a cluster and fail if not with the call to action (oc command to log in). * If cluster router base can be detected, use that value to update the helm chart installation; if not, fail and request user pass in command line flag as cluster router base could not be detected (can test this failure case with dev sandbox; can test passing case with clusterbot). - ## **Prerequisites** - - -1. Ensure that `oc` (for OpenShift) is installed. -2. Ensure that you are logged into an OCP cluster and that it is running. - +1. Ensure that `oc` (for OpenShift) is installed. See https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html#installing-openshift-cli for further instructions. +2. Ensure that you are logged into an OCP cluster and that it is running. See [Logging in to the OpenShift CLI](https://docs.redhat.com/en/documentation/openshift_container_platform/4.16/html/cli_tools/openshift-cli-oc#cli-logging-in_cli-developer-commands). +3. git +4. [Helm](https://helm.sh/docs/intro/install/) ## **Installation Steps** 1. **Download the Script** - Clone the repository and navigate to the `scripts` directory: \ -`git clone /rhdh-chart.git -cd rhdh-chart/scripts` + ```shell +git clone --depth 1 https://github.com/redhat-developer/rhdh-chart.git +cd rhdh-charts/scripts +``` -2. **Make the Script Executable** - Before running the script, make sure it has executable permissions: \ -`chmod +x install.sh` - - -3. **Run the Script** - Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. \ +1. **Run the Script** - Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. \ `./install.sh` - - **Specify Router Base** - If the script cannot automatically detect the cluster router base, you can provide it manually using the `-router-base` flag, example:\ + **Specify Router Base** - If the script cannot automatically detect the cluster router base, you can provide it manually using the `--router-base` flag, example:\ `./install.sh --router-base ` - -4. **Specify Release Name** - To install the Helm chart with a custom release name: \ -`./install.sh --release-name myrelease` + **Specify Release Name** - To install the Helm chart with a custom release name: \ + `./install.sh --release-name myrelease` **Generate a Release Name** - To generate a name for the Helm release: \ `./install.sh --generate-name` -5. **Specify Namespace** - To specify the namespace for the Helm release: \ +1. **Specify Namespace** - To specify the namespace for the Helm release: \ `./install.sh --namespace mynamespace` - **Specify Custom Values File** - To use a custom values file for the Helm chart: \ `./install.sh --values /path/to/values.yaml` - - - ## **Troubleshooting** - * Missing oc - If the script outputs an error indicating that neither oc nor kubectl is installed, please install the appropriate CLI tool for your cluster: * For OpenShift: Install oc - * For Kubernetes: Install kubectl - -* Not Logged Into Cluster: If you are not logged into a cluster, follow these steps to log in: +* Not Logged Into Cluster: If you are not logged into a cluster, follow these steps to log in: * For OpenShift: `oc login ` - -* Router Base Detection Failed: - If the script cannot detect the cluster router base, manually provide it using the --router-base flag as shown in the example usage section. - +* Router Base Detection Failed: - If the script cannot detect the cluster router base, manually provide it using the --router-base flag as shown in the example usage section. * Error: INSTALLATION FAILED: An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies: found in Chart.yaml, but missing in charts/ directory: common, backstage: `helm dependency build` - An example of the installation output should be: Using router base: example.com @@ -92,4 +74,4 @@ REVISION: ... Helm installation completed successfully. -You can run: `helm version` to confirm this installation. +You can run: `helm list --namespace $myProject` to confirm this installation. From 8b015127a53cf1478e0bfe6dec9b3da5092b0491 Mon Sep 17 00:00:00 2001 From: Fortune Ndlovu Date: Mon, 1 Jul 2024 09:59:49 +0100 Subject: [PATCH 18/28] Update install.md --- scripts/install.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/install.md b/scripts/install.md index 7bf15555..2bb75fdf 100644 --- a/scripts/install.md +++ b/scripts/install.md @@ -4,7 +4,7 @@ The purpose of the [`install.sh` script](./install.sh) is to simplify and automate the installation process of this Helm Chart on OpenShift Container Platform (OCP) clusters. Instead of requiring users to follow a lengthy and potentially error-prone series of manual steps, this script consolidates the process into a single, reusable command that can: -* Detect if the OpenShit Client ([`oc`](https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html)) is installed; fail if not found and report the error to the user with a call to action (installing it). +* Detect if the OpenShift Client ([`oc`](https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html)) is installed; fail if not found and report the error to the user with a call to action (installing it). * If cluster router base can be detected, use that value to update the helm chart installation; if not, fail and request user pass in command line flag as cluster router base could not be detected (can test this failure case with dev sandbox; can test passing case with clusterbot). @@ -17,34 +17,34 @@ The purpose of the [`install.sh` script](./install.sh) is to simplify and automa ## **Installation Steps** -1. **Download the Script** - Clone the repository and navigate to the `scripts` directory: \ +1. **Download the Script** - Clone the repository and navigate to the `scripts` directory: - ```shell -git clone --depth 1 https://github.com/redhat-developer/rhdh-chart.git -cd rhdh-charts/scripts -``` + ```shell + git clone --depth 1 https://github.com/redhat-developer/rhdh-chart.git + cd rhdh-charts/scripts + ``` -1. **Run the Script** - Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. \ +2. **Run the Script** - Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. \ `./install.sh` - **Specify Router Base** - If the script cannot automatically detect the cluster router base, you can provide it manually using the `--router-base` flag, example:\ +3. **Specify Router Base** - If the script cannot automatically detect the cluster router base, you can provide it manually using the `--router-base` flag, example:\ `./install.sh --router-base ` - **Specify Release Name** - To install the Helm chart with a custom release name: \ +4. **Specify Release Name** - To install the Helm chart with a custom release name: \ `./install.sh --release-name myrelease` - **Generate a Release Name** - To generate a name for the Helm release: \ +5. **Generate a Release Name** - To generate a name for the Helm release: \ `./install.sh --generate-name` -1. **Specify Namespace** - To specify the namespace for the Helm release: \ +6. **Specify Namespace** - To specify the namespace for the Helm release: \ `./install.sh --namespace mynamespace` - **Specify Custom Values File** - To use a custom values file for the Helm chart: \ +7. **Specify Custom Values File** - To use a custom values file for the Helm chart: \ `./install.sh --values /path/to/values.yaml` ## **Troubleshooting** -* Missing oc - If the script outputs an error indicating that neither oc nor kubectl is installed, please install the appropriate CLI tool for your cluster: +* Missing oc - If the script outputs an error indicating oc is not installed, please install the CLI tool for your cluster: * For OpenShift: Install oc * Not Logged Into Cluster: If you are not logged into a cluster, follow these steps to log in: From cafbd47aefb73cf3cd07466569510fdf251ad60a Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 8 Jul 2024 09:41:13 +0100 Subject: [PATCH 19/28] Improve error handling and better practices in setting configuration values --- scripts/install.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 82a6acc6..11dabcc1 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -112,27 +112,28 @@ detect_cluster_router_base() { # Detect cluster router base if not provided if [[ -z "$ROUTER_BASE" ]]; then detect_cluster_router_base -else - echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." - exit 1 + if [[ -z "$ROUTER_BASE" ]]; then + echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." + exit 1 + fi fi # Detect namespace if not provided if [[ -z "$NAMESPACE" ]]; then NAMESPACE=$(oc config view --minify --output 'jsonpath={..namespace}') -else - echo "Error: Namespace could not be detected. Please provide it using the --namespace flag." - exit 1 + if [[ -z $NAMESPACE ]]; then + echo "Error: Namespace could not be detected. Please provide it using the --namespace flag." + exit 1 + fi fi # Update Helm chart with the detected or provided router base if using default values file if [[ "$VALUES_FILE" == "$DEFAULT_VALUES_FILE" ]]; then - echo "Using router base: $ROUTER_BASE" - sed -i "s|routerBase:.*|routerBase: $ROUTER_BASE|" "$VALUES_FILE" + EXTRA_HELM_ARGS+="--set global.clusterRouterBase=$ROUTER_BASE" fi # Construct Helm install command -HELM_CMD="helm upgrade --install" +HELM_CMD="helm install" if [[ $GENERATE_NAME == true ]]; then HELM_CMD+=" --generate-name" elif [[ -z "$RELEASE_NAME" ]]; then @@ -142,7 +143,6 @@ else HELM_CMD+=" $RELEASE_NAME" fi - HELM_CMD+=" $HELM_CHART_DIR --values $VALUES_FILE --namespace $NAMESPACE $EXTRA_HELM_ARGS" # Execute Helm install command From 813fa8b0106b4c525c059fdcde4196edb83ea0d6 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 16 Jul 2024 10:16:16 +0100 Subject: [PATCH 20/28] If detect_cluster_router_base fails, we could just exit with the right message. --- scripts/install.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 11dabcc1..67593fc3 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -111,11 +111,7 @@ detect_cluster_router_base() { # Detect cluster router base if not provided if [[ -z "$ROUTER_BASE" ]]; then - detect_cluster_router_base - if [[ -z "$ROUTER_BASE" ]]; then - echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." - exit 1 - fi + detect_cluster_router_base || (echo "Error: Cluster router base could not be detected. Please provide it using the --router-base flag." && exit 1) fi # Detect namespace if not provided From a67d1115ad147acd5d9a64be2cc5cd0aa02282ba Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 16 Jul 2024 10:25:28 +0100 Subject: [PATCH 21/28] since the ROUTER_BASE is always required and will either be provided by the user or auto-detected, there's no need to add the router base to the Helm arguments conditionally. --- scripts/install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 67593fc3..51a04775 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -123,10 +123,8 @@ if [[ -z "$NAMESPACE" ]]; then fi fi -# Update Helm chart with the detected or provided router base if using default values file -if [[ "$VALUES_FILE" == "$DEFAULT_VALUES_FILE" ]]; then - EXTRA_HELM_ARGS+="--set global.clusterRouterBase=$ROUTER_BASE" -fi +# Always include the router base in Helm arguments +EXTRA_HELM_ARGS+="--set global.clusterRouterBase=$ROUTER_BASE" # Construct Helm install command HELM_CMD="helm install" From 2317626b3ececf1e160af7d90a31bfe8af7313ae Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 16 Jul 2024 10:52:54 +0100 Subject: [PATCH 22/28] removing case --- scripts/install.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 51a04775..e4ba86d3 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -89,10 +89,6 @@ while [[ "$#" -gt 0 ]]; do NAMESPACE="$2" shift ;; - --values) - VALUES_FILE="$2" - shift - ;; --help) usage exit 0 From 905e1ae1b9fa38c31ab6ea5fda1e80fe6935a99c Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 16 Jul 2024 10:56:06 +0100 Subject: [PATCH 23/28] adding space --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index e4ba86d3..484730e2 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -120,7 +120,7 @@ if [[ -z "$NAMESPACE" ]]; then fi # Always include the router base in Helm arguments -EXTRA_HELM_ARGS+="--set global.clusterRouterBase=$ROUTER_BASE" +EXTRA_HELM_ARGS+=" --set global.clusterRouterBase=$ROUTER_BASE" # Construct Helm install command HELM_CMD="helm install" From 401589f4aa51048d9250de4d871853393f10f7ee Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 16 Jul 2024 11:29:50 +0100 Subject: [PATCH 24/28] Not needed to specify the path to the Chart default values.yaml file. --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 484730e2..5db749da 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -133,7 +133,7 @@ else HELM_CMD+=" $RELEASE_NAME" fi -HELM_CMD+=" $HELM_CHART_DIR --values $VALUES_FILE --namespace $NAMESPACE $EXTRA_HELM_ARGS" +HELM_CMD+=" $HELM_CHART_DIR --namespace $NAMESPACE $EXTRA_HELM_ARGS" # Execute Helm install command echo "Executing: $HELM_CMD" From 41bf45bbf9cbb8c56114951930eed831fa3dd2b2 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 16 Jul 2024 20:00:42 +0100 Subject: [PATCH 25/28] Trapping for each condition separately, and then providing a call to action for the user so they know where to get oc or helm to install it. --- scripts/install.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 5db749da..ff771e13 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -15,7 +15,7 @@ # # Script to handle CLI helm installation for OCP # -# Requires: oc and an active login session to a cluster. +# Requires: oc, helm and an active login session to a cluster. set -e @@ -50,8 +50,12 @@ command_exists() { } # Check for required commands -if ! command_exists helm || ! command_exists oc; then - echo "Error: Required commands 'helm' and 'oc' are not available." +if ! command_exists helm; then + echo "Error: 'helm' is required. Install it from https://docs.openshift.com/container-platform/4.16/applications/working_with_helm_charts/installing-helm.html to continue." + exit 1 +fi +if ! command_exists oc; then + echo "Error: 'oc' is required. Install it from https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html to continue." exit 1 fi From dd8c73e2547e8f7e286c095968d55e43c3bdcf9a Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Thu, 18 Jul 2024 12:17:42 +0100 Subject: [PATCH 26/28] List all Helm releases in the specified name space --- scripts/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install.sh b/scripts/install.sh index ff771e13..4266d9c6 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -146,5 +146,6 @@ if eval "$HELM_CMD"; then echo "Helm installation completed successfully." else echo "Something went wrong with Helm installation!" + helm list --namespace $NAMESPACE exit 1 fi \ No newline at end of file From cfa136f1f590a76df8435ec3b91488a5113bc72e Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Fri, 19 Jul 2024 15:07:10 +0100 Subject: [PATCH 27/28] Adding the -i flag to install the chart if it doesnt exists, or upgrade it if it does. And removing the md file because the instructions are present in the usage function of the script. --- scripts/install.md | 77 ---------------------------------------------- scripts/install.sh | 4 +-- 2 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 scripts/install.md diff --git a/scripts/install.md b/scripts/install.md deleted file mode 100644 index 2bb75fdf..00000000 --- a/scripts/install.md +++ /dev/null @@ -1,77 +0,0 @@ -## **Documentation for the script to handle CLI helm installation for OCP** - -## **Overview** - -The purpose of the [`install.sh` script](./install.sh) is to simplify and automate the installation process of this Helm Chart on OpenShift Container Platform (OCP) clusters. Instead of requiring users to follow a lengthy and potentially error-prone series of manual steps, this script consolidates the process into a single, reusable command that can: - -* Detect if the OpenShift Client ([`oc`](https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html)) is installed; fail if not found and report the error to the user with a call to action (installing it). - -* If cluster router base can be detected, use that value to update the helm chart installation; if not, fail and request user pass in command line flag as cluster router base could not be detected (can test this failure case with dev sandbox; can test passing case with clusterbot). - -## **Prerequisites** - -1. Ensure that `oc` (for OpenShift) is installed. See https://docs.openshift.com/container-platform/4.16/cli_reference/openshift_cli/getting-started-cli.html#installing-openshift-cli for further instructions. -2. Ensure that you are logged into an OCP cluster and that it is running. See [Logging in to the OpenShift CLI](https://docs.redhat.com/en/documentation/openshift_container_platform/4.16/html/cli_tools/openshift-cli-oc#cli-logging-in_cli-developer-commands). -3. git -4. [Helm](https://helm.sh/docs/intro/install/) - -## **Installation Steps** - -1. **Download the Script** - Clone the repository and navigate to the `scripts` directory: - - ```shell - git clone --depth 1 https://github.com/redhat-developer/rhdh-chart.git - cd rhdh-charts/scripts - ``` - -2. **Run the Script** - Execute the script to install the Helm chart. The script will automatically detect that you are using `oc` and ensure you are logged into your cluster. \ -`./install.sh` - -3. **Specify Router Base** - If the script cannot automatically detect the cluster router base, you can provide it manually using the `--router-base` flag, example:\ - `./install.sh --router-base ` - -4. **Specify Release Name** - To install the Helm chart with a custom release name: \ - `./install.sh --release-name myrelease` - -5. **Generate a Release Name** - To generate a name for the Helm release: \ - `./install.sh --generate-name` - -6. **Specify Namespace** - To specify the namespace for the Helm release: \ -`./install.sh --namespace mynamespace` - -7. **Specify Custom Values File** - To use a custom values file for the Helm chart: \ - `./install.sh --values /path/to/values.yaml` - -## **Troubleshooting** - -* Missing oc - If the script outputs an error indicating oc is not installed, please install the CLI tool for your cluster: - * For OpenShift: Install oc - -* Not Logged Into Cluster: If you are not logged into a cluster, follow these steps to log in: - * For OpenShift: - `oc login ` - -* Router Base Detection Failed: - If the script cannot detect the cluster router base, manually provide it using the --router-base flag as shown in the example usage section. - -* Error: INSTALLATION FAILED: - - An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies: found in Chart.yaml, but missing in charts/ directory: common, backstage: - `helm dependency build` - -An example of the installation output should be: - -Using router base: example.com - -NAME: ... - -LAST DEPLOYED: ... - -NAMESPACE: ... - -STATUS: ... - -REVISION: ... - -Helm installation completed successfully. - -You can run: `helm list --namespace $myProject` to confirm this installation. diff --git a/scripts/install.sh b/scripts/install.sh index 4266d9c6..dd4c1bf6 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -127,7 +127,7 @@ fi EXTRA_HELM_ARGS+=" --set global.clusterRouterBase=$ROUTER_BASE" # Construct Helm install command -HELM_CMD="helm install" +HELM_CMD="helm upgrade -i" if [[ $GENERATE_NAME == true ]]; then HELM_CMD+=" --generate-name" elif [[ -z "$RELEASE_NAME" ]]; then @@ -146,6 +146,6 @@ if eval "$HELM_CMD"; then echo "Helm installation completed successfully." else echo "Something went wrong with Helm installation!" - helm list --namespace $NAMESPACE + helm list --namespace "$NAMESPACE" exit 1 fi \ No newline at end of file From 595db2550df4514815834fa01f64181f72da27fd Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 22 Jul 2024 10:51:55 +0100 Subject: [PATCH 28/28] Testing script --- scripts/install.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index dd4c1bf6..87c733e4 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -93,6 +93,10 @@ while [[ "$#" -gt 0 ]]; do NAMESPACE="$2" shift ;; + --values) + VALUES_FILE="$2" + shift + ;; --help) usage exit 0 @@ -118,28 +122,28 @@ fi if [[ -z "$NAMESPACE" ]]; then NAMESPACE=$(oc config view --minify --output 'jsonpath={..namespace}') if [[ -z $NAMESPACE ]]; then - echo "Error: Namespace could not be detected. Please provide it using the --namespace flag." - exit 1 + NAMESPACE="default" fi fi # Always include the router base in Helm arguments EXTRA_HELM_ARGS+=" --set global.clusterRouterBase=$ROUTER_BASE" -# Construct Helm install command -HELM_CMD="helm upgrade -i" +# Construct Helm install or upgrade command if [[ $GENERATE_NAME == true ]]; then - HELM_CMD+=" --generate-name" -elif [[ -z "$RELEASE_NAME" ]]; then - echo "Error: Either --release-name must be specified or --generate-name must be used." - exit 1 + HELM_CMD="helm install --generate-name" else - HELM_CMD+=" $RELEASE_NAME" + if [[ -z "$RELEASE_NAME" ]]; then + echo "Error: Either --release-name must be specified or --generate-name must be used." + exit 1 + else + HELM_CMD="helm upgrade -i $RELEASE_NAME" + fi fi -HELM_CMD+=" $HELM_CHART_DIR --namespace $NAMESPACE $EXTRA_HELM_ARGS" +HELM_CMD+=" $HELM_CHART_DIR --namespace $NAMESPACE --values $VALUES_FILE $EXTRA_HELM_ARGS" -# Execute Helm install command +# Execute Helm install or upgrade command echo "Executing: $HELM_CMD" if eval "$HELM_CMD"; then