Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm install script #27

Closed
wants to merge 29 commits into from
Closed
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
790122e
Added helm installation script.
Jun 18, 2024
60003cd
Copyright statement and information about the relevant Apache Licence.
Jun 18, 2024
62317f8
Refractored the function to detect cluster router base: Instead of us…
Jun 18, 2024
59965c6
Added clear instructions and a description of the script, the options…
Jun 18, 2024
6e1a1a1
Added --help option to display usage information.
Jun 19, 2024
733f5f8
.sh file name change as noted that the install-helm.sh file makes it …
Jun 19, 2024
45c1e1f
Added --cli <oc|kubectl> option to specify which CLI tool to use.
Jun 19, 2024
40aa740
Placed the checks for essential information at the top of the file en…
Jun 19, 2024
d4a5a5c
Support for --release-name and --generate-name options: Allows users …
Jun 19, 2024
aa66059
Merge branch 'redhat-developer:main' into helm-install-script
Fortune-Ndlovu Jun 24, 2024
8996e31
Using dirname to determine the base directory of the script ensuring …
Fortune-Ndlovu Jun 24, 2024
7673f4b
Removed login check because we already provide feedback if the user i…
Fortune-Ndlovu Jun 24, 2024
77042ae
Updated the detect_cluster_router_base function to use oc get ingress…
Fortune-Ndlovu Jun 24, 2024
a990059
Refactored the script to only handle the CLI Helm installation for OCP.
Fortune-Ndlovu Jun 25, 2024
bc57eed
Added install.md file.
Fortune-Ndlovu Jun 28, 2024
8ba23d9
Update install.md
Fortune-Ndlovu Jun 28, 2024
1b5f427
Update install.md
Fortune-Ndlovu Jun 28, 2024
ca84b36
Add suggestions
Fortune-Ndlovu Jul 1, 2024
8b01512
Update install.md
Fortune-Ndlovu Jul 1, 2024
cafbd47
Improve error handling and better practices in setting configuration …
Fortune-Ndlovu Jul 8, 2024
813fa8b
If detect_cluster_router_base fails, we could just exit with the righ…
Fortune-Ndlovu Jul 16, 2024
a67d111
since the ROUTER_BASE is always required and will either be provided …
Fortune-Ndlovu Jul 16, 2024
2317626
removing case
Fortune-Ndlovu Jul 16, 2024
905e1ae
adding space
Fortune-Ndlovu Jul 16, 2024
401589f
Not needed to specify the path to the Chart default values.yaml file.
Fortune-Ndlovu Jul 16, 2024
41bf45b
Trapping for each condition separately, and then providing a call to …
Fortune-Ndlovu Jul 16, 2024
dd8c73e
List all Helm releases in the specified name space
Fortune-Ndlovu Jul 18, 2024
cfa136f
Adding the -i flag to install the chart if it doesnt exists, or upgra…
Fortune-Ndlovu Jul 19, 2024
595db25
Testing script
Fortune-Ndlovu Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions scripts/install-helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/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 <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
Fortune-Ndlovu marked this conversation as resolved.
Show resolved Hide resolved

# 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
nickboldt marked this conversation as resolved.
Show resolved Hide resolved

# 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
Fortune-Ndlovu marked this conversation as resolved.
Show resolved Hide resolved
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
Fortune-Ndlovu marked this conversation as resolved.
Show resolved Hide resolved

# Proceed with Helm installation
helm install my-release "$HELM_CHART_DIR" --values "$VALUES_FILE"
Fortune-Ndlovu marked this conversation as resolved.
Show resolved Hide resolved

echo "Helm installation completed successfully."