Skip to content

Commit

Permalink
Allow to set values via CLI in installation
Browse files Browse the repository at this point in the history
Also allows to install without a values.yaml file at all.
More importantly, it reuses values from previous installations so
updates are very simple now.

Closes #740.
  • Loading branch information
michaelsauter committed Nov 6, 2023
1 parent f7b51c3 commit 75b5013
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
24 changes: 0 additions & 24 deletions deploy/README.md

This file was deleted.

40 changes: 29 additions & 11 deletions deploy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ diff="true"
namespace=""
release_name="ods-pipeline"
serviceaccount="pipeline"
values_file="values.yaml"
values_file=""
if [ -f "values.yaml" ]; then
values_file="values.yaml"
fi
helm_set_values=""
chart_dir="./chart"
chart_version="0.14.0"
# Secrets
Expand Down Expand Up @@ -61,6 +65,7 @@ function usage {
printf "\t-n|--namespace\t\t\tK8s namespace to target.\n"
printf "\t--local-chart\t\t\tUse local chart instead of remote, versioned chart.\n"
printf "\t-f|--values\t\t\tValues file to supply to Helm (defaults to '%s'). Multiple files can be specified comma-separated.\n" "$values_file"
printf "\t--set\t\t\t\tSet values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)\n"
printf "\t-s|--serviceaccount\t\tServiceaccount to use (defaults to '%s').\n" "$serviceaccount"
printf "\t--no-diff\t\t\tDo not run Helm diff before running Helm upgrade.\n"
printf "\t--dry-run\t\t\tDo not apply any changes, instead just print what the script would do.\n"
Expand All @@ -73,6 +78,7 @@ function usage {
printf "\nExample:\n\n"
printf "\t%s \ \
\n\t\t--namespace foo \ \
\n\t\t--set bitbucketUrl=https://bitbucket.example.com,nexusUrl=https://nexus.example.com,consoleUrl=https://console.example.com,pipelineManager.storageProvisioner=ebs.csi.aws.com,pipelineManager.storageClassName=gp3-csi \ \
\n\t\t--bitbucket-auth 'personal-access-token' \ \
\n\t\t--nexus-auth 'user:password' \n\n" "$0"
}
Expand Down Expand Up @@ -100,6 +106,9 @@ while [ "$#" -gt 0 ]; do
-s|--serviceaccount) serviceaccount="$2"; shift;;
-s=*|--serviceaccount=*) serviceaccount="${1#*=}";;

--set) helm_set_values="$2"; shift;;
--set=*) helm_set_values="${1#*=}";;

--auth-separator) auth_separator="$2"; shift;;
--auth-separator=*) auth_separator="${1#*=}";;

Expand All @@ -121,11 +130,14 @@ while [ "$#" -gt 0 ]; do
*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done

values_fileS=$(echo "$values_file" | tr "," "\n")
values_args=()
for valueFile in ${values_fileS}; do
values_args+=(--values="${valueFile}")
values_files=$(echo "$values_file" | tr "," "\n")
values_args=""
for vf in ${values_files}; do
values_args+="--values=${vf} "
done
if [ "${helm_set_values}" != "" ]; then
helm_set_values="--set ${helm_set_values}"
fi

if [ "${verbose}" = true ]; then
set -x
Expand Down Expand Up @@ -272,28 +284,34 @@ fi

echo "Installing Helm release ${release_name} from ${chart_location} ..."
if [ "${diff}" = true ]; then
# shellcheck disable=SC2086
if "${helm_bin}" -n "${namespace}" \
diff upgrade --install --detailed-exitcode --three-way-merge --normalize-manifests \
"${values_args[@]}" \
diff upgrade --install --detailed-exitcode --three-way-merge --normalize-manifests --reuse-values \
${values_args} \
${helm_set_values} \
"${release_name}" "${chart_location}"; then
echo "Helm release already up-to-date."
else
if [ "${dry_run}" = true ]; then
echo "(skipping in dry-run)"
else
# shellcheck disable=SC2086
"${helm_bin}" -n "${namespace}" \
upgrade --install \
"${values_args[@]}" \
upgrade --install --reuse-values \
${values_args} \
${helm_set_values} \
"${release_name}" "${chart_location}"
fi
fi
else
if [ "${dry_run}" = true ]; then
echo "(skipping in dry-run)"
else
# shellcheck disable=SC2086
"${helm_bin}" -n "${namespace}" \
upgrade --install \
"${values_args[@]}" \
upgrade --install --reuse-values \
${values_args} \
${helm_set_values} \
"${release_name}" "${chart_location}"
fi
fi
Expand Down
23 changes: 4 additions & 19 deletions docs/installation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ Download the template and fill in the values according to the comments in that f
curl -fsSL https://raw.githubusercontent.com/opendevstack/ods-pipeline/v0.14.0.1/deploy/values.yaml.tmpl -o values.yaml
----

TIP: It is recommended to keep this file around after the installation so that it can be reused when updating ODS Pipeline to future versions.

=== Step 2: Running the install script

Login to the OpenShift cluster in your terminal, then run:
Login to the OpenShift cluster in your terminal, then run the following from the same directory that the `values.yaml` file is located in:

[source]
----
Expand Down Expand Up @@ -66,28 +64,15 @@ CAUTION: An important feature of ODS Pipeline is to retain pipeline run artifact

== Update Instructions

The update procedure consists of two quick steps:

1. Updating the chart values if required
2. Running the install script (which will deploy the Helm chart)

=== Step 1: Updating the chart values

Ensure that the `values.yaml` file you used during installation is located in the working directory. Then check if any new values have been introduced in link:https://raw.githubusercontent.com/opendevstack/ods-pipeline/v0.14.0.1/deploy/values.yaml.tmpl[`values.yaml.tmpl`] and update `values.yaml` accordingly.

TIP: If you cannot find the `values.yaml` file from the installation, create it again using the values found in the current Helm installation.

=== Step 2: Running the install script

Login to the OpenShift cluster in your terminal, then run:
To update ODS Pipeline, simply run the install script again (using the new version tag that you want to install). Login to the OpenShift cluster in your terminal, then run:

[source]
----
curl -fsSL https://raw.githubusercontent.com/opendevstack/ods-pipeline/v0.14.0.1/deploy/install.sh | bash -s -- -n=<your_cd_namespace>
----

TIP: If you want to review the changes first before applying them, supply `--dry-run`.
IMPORTANT: Previous Helm chart values will be reused. If the release notes mention any new or changed Helm chart values, you have to pass those to the install script using `--set key1=val1,key2=val2`.

TIP: By default, the credentials stored in the K8s secrets will not be updated. If you want to make a change, pass any new values as flags to the install script (supply `--help` to see all options) or update the secrets manually.
TIP: If you want to review the changes first before applying them, supply `--dry-run`.

TIP: If you do not have access to the OpenShift API from your local machine, you can use the https://docs.openshift.com/container-platform/latest/web_console/odc-about-web-terminal.html[OpenShift Web Terminal]. Open a web terminal in the target namespace and make sure the `values.yaml` file is present in the working directory there. Then run the installation script as described above. Note that you must either install the `helm-diff` plugin using `helm plugin install https://github.com/databus23/helm-diff --version "v3.3.2"` beforehand or supply `--no-diff` when running the install script.

0 comments on commit 75b5013

Please sign in to comment.