From e05de45062b2c1ddde6637d73a3f471d91da9215 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Fri, 5 Jan 2024 16:54:16 +0200 Subject: [PATCH 1/6] Move next minor version processing to a function --- scripts/lib.sh | 22 ++++++++++++++++++++++ scripts/pre-release-process.sh | 4 ++-- scripts/update-makefile-version.sh | 24 +++++++----------------- 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100755 scripts/lib.sh diff --git a/scripts/lib.sh b/scripts/lib.sh new file mode 100755 index 00000000..bada6545 --- /dev/null +++ b/scripts/lib.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +NEXT_VERSION="" + +next_minor_version() { + local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' + + local MINOR=$(echo $CURRENT_VERSION | sed -e "s#$RE#\2#") + + local NEXT_VERSION_PARTS=() + for i in {1..3} + do + local PART=$(echo $CURRENT_VERSION | sed -e "s#$RE#\\$i#") + if [ $i == 2 ] + then + let PART+=1 + fi + NEXT_VERSION_PARTS+=($PART) + done + + NEXT_VERSION=${NEXT_VERSION_PARTS[0]}.${NEXT_VERSION_PARTS[1]}.${NEXT_VERSION_PARTS[2]} +} diff --git a/scripts/pre-release-process.sh b/scripts/pre-release-process.sh index 8e267cd9..ccce42b4 100755 --- a/scripts/pre-release-process.sh +++ b/scripts/pre-release-process.sh @@ -16,10 +16,10 @@ make kustomize KUSTOMIZE=$(pwd)/bin/kustomize # Modify CHANGELOG automatically to match the tag -sed -i -e "s/## unreleased/## $TAG/" CHANGELOG.md +sed -i '' -e "s/## unreleased/## $TAG/" CHANGELOG.md # Modify README to include proper installation refs -sed -i -e "s/$PREVTAG/$TAG/g" README.md +sed -i '' -e "s/$PREVTAG/$TAG/g" README.md # Modify config/manager/kustomization.yaml to have proper newTag for cass-operator cd config/manager && $KUSTOMIZE edit set image controller=$IMG && cd - diff --git a/scripts/update-makefile-version.sh b/scripts/update-makefile-version.sh index 336989e4..aa9c18ed 100755 --- a/scripts/update-makefile-version.sh +++ b/scripts/update-makefile-version.sh @@ -1,21 +1,11 @@ #!/bin/bash +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi -RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' +. scripts/lib.sh CURRENT_VERSION=$(gawk 'match($0, /^VERSION \?= /) { print substr($0, RLENGTH+1)}' Makefile) -MINOR=$(echo $CURRENT_VERSION | sed -e "s#$RE#\2#") - -NEXT_VERSION_PARTS=() -for i in {1..3} -do - PART=$(echo $CURRENT_VERSION | sed -e "s#$RE#\\$i#") - if [ $i == 2 ] - then - let PART+=1 - fi - NEXT_VERSION_PARTS+=($PART) -done - -NEXT_VERSION=${NEXT_VERSION_PARTS[0]}.${NEXT_VERSION_PARTS[1]}.${NEXT_VERSION_PARTS[2]} - -sed -i -e "s/VERSION ?= $CURRENT_VERSION/VERSION ?= $NEXT_VERSION/" Makefile +next_minor_version +sed -i '' -e "s/VERSION ?= $CURRENT_VERSION/VERSION ?= $NEXT_VERSION/" Makefile From 23185ec3b0efc678e90b4ae9c9227b65e1d20722 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Fri, 5 Jan 2024 16:55:27 +0200 Subject: [PATCH 2/6] Add requirement to run scripts from the root folder --- scripts/post-release-process.sh | 5 +++++ scripts/postprocess-bundle.sh | 4 ++++ scripts/pre-release-process.sh | 4 ++++ scripts/release-certified-bundles.sh | 4 ++++ scripts/release-community-bundles.sh | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/scripts/post-release-process.sh b/scripts/post-release-process.sh index 8797be16..640e4110 100755 --- a/scripts/post-release-process.sh +++ b/scripts/post-release-process.sh @@ -1,4 +1,9 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi + IMG=k8ssandra/cass-operator:latest KUSTOMIZE=$(pwd)/bin/kustomize diff --git a/scripts/postprocess-bundle.sh b/scripts/postprocess-bundle.sh index 7437f58f..5cfb9068 100755 --- a/scripts/postprocess-bundle.sh +++ b/scripts/postprocess-bundle.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi # These labels are required to be in the bundle.Dockerfile, but can't be added by the operator-sdk automatically cat <> bundle.Dockerfile diff --git a/scripts/pre-release-process.sh b/scripts/pre-release-process.sh index ccce42b4..fd0a0714 100755 --- a/scripts/pre-release-process.sh +++ b/scripts/pre-release-process.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi if [ "$#" -ne 1 ]; then echo "Usage: scripts/pre-release-process.sh newTag" diff --git a/scripts/release-certified-bundles.sh b/scripts/release-certified-bundles.sh index 61a43026..8704fe44 100755 --- a/scripts/release-certified-bundles.sh +++ b/scripts/release-certified-bundles.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi if [ "$#" -ne 4 ]; then echo "Usage: scripts/release-certified-bundles.sh version sha256: sha256: sha256:" diff --git a/scripts/release-community-bundles.sh b/scripts/release-community-bundles.sh index f649f739..5f4300f7 100755 --- a/scripts/release-community-bundles.sh +++ b/scripts/release-community-bundles.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi if [ "$#" -ne 1 ]; then echo "Usage: scripts/release-community-bundles.sh version" From ef62754785b3e6ef809bad0139d87a8d75fe05b8 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Fri, 5 Jan 2024 17:35:52 +0200 Subject: [PATCH 3/6] Update Helm script to automatically prepare the next release --- hack/boilerplate.go.txt | 2 +- scripts/lib.sh | 2 +- scripts/release-helm-chart.sh | 51 ++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 45dbbbbc..65b86227 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright 2021. +Copyright 2023. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/scripts/lib.sh b/scripts/lib.sh index bada6545..50049396 100755 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -18,5 +18,5 @@ next_minor_version() { NEXT_VERSION_PARTS+=($PART) done - NEXT_VERSION=${NEXT_VERSION_PARTS[0]}.${NEXT_VERSION_PARTS[1]}.${NEXT_VERSION_PARTS[2]} + NEXT_VERSION=${NEXT_VERSION_PARTS[0]}.${NEXT_VERSION_PARTS[1]}.0 } diff --git a/scripts/release-helm-chart.sh b/scripts/release-helm-chart.sh index 5d537f3a..391c6d60 100755 --- a/scripts/release-helm-chart.sh +++ b/scripts/release-helm-chart.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi + # This script assumes k8ssandra is checked out at ../k8ssandra and is checked out at main if [ "$#" -ne 1 ]; then echo "Usage: scripts/release-helm-chart.sh version" @@ -8,13 +13,16 @@ if [ "$#" -ne 1 ]; then exit fi +# This should work with BSD/MacOS mktemp and GNU one +CRD_TMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'crd') + VERSION=$1 CHART_HOME=../k8ssandra/charts/cass-operator -CRD_TARGET_PATH=$CHART_HOME/crds +CRD_TARGET_PATH=$CRD_TMP_DIR TEMPLATE_HOME=$CHART_HOME/templates # Checkout tag -git checkout v$VERSION +# git checkout v$VERSION # Create CRDs kustomize build config/crd --output $CRD_TARGET_PATH @@ -25,4 +33,41 @@ for f in $CRD_TARGET_PATH/*; do mv $f $CRD_TARGET_PATH/$TARGET_FILENAME done -# TODO Update all the necessary fields also (Chart.yaml, values.yaml, configmap.yaml) +# Add conditionals to the and beginning before applying them to the templates path +echo "Updating CRDs in" $TEMPLATE_HOME +CRD_FILE_NAME=$TEMPLATE_HOME/crds.yaml +echo '{{- if .Values.updateCRDs }}' > $CRD_FILE_NAME + +declare -a files +files=($CRD_TARGET_PATH/*) +for i in ${!files[@]}; do + echo "Processing " ${files[$i]} + cat ${files[$i]} >> $CRD_FILE_NAME + if [[ $i -lt ${#files[@]}-1 ]]; then + echo "---" >> $CRD_FILE_NAME + fi +done +echo '{{- end }}' >> $CRD_FILE_NAME + +rm -fr $CRD_TMP_DIR + +# Update version of the Chart.yaml automatically (to next minor one) +CURRENT_VERSION=$(yq '.version' $CHART_HOME/Chart.yaml) +. scripts/lib.sh +next_minor_version +echo "Updating Chart.yaml version to next minor version" $NEXT_VERSION +yq -i '.version = "'"$NEXT_VERSION"'"' $CHART_HOME/Chart.yaml + +# Update appVersion to the same as version +echo "Setting appVersion to" $VERSION +yq -i '.appVersion = "'"$VERSION"'"' $CHART_HOME/Chart.yaml + +# Update imageConfig settings to the current one +echo "Updating .Values.imageConfig to match config/manager/image_config.yaml" +SYSTEM_LOGGER_IMAGE=$(yq '.images.system-logger' config/manager/image_config.yaml) +K8SSANDRA_CLIENT_IMAGE=$(yq '.images.k8ssandra-client' config/manager/image_config.yaml) +CONFIG_BUILDER_IMAGE=$(yq '.images.config-builder' config/manager/image_config.yaml) + +yq -i '.imageConfig.systemLogger = "cr.k8ssandra.io" + "/" + "'"$SYSTEM_LOGGER_IMAGE"'"' $CHART_HOME/values.yaml +yq -i '.imageConfig.k8ssandraClient = "cr.k8ssandra.io" + "/" + "'"$K8SSANDRA_CLIENT_IMAGE"'"' $CHART_HOME/values.yaml +yq -i '.imageConfig.configBuilder = "cr.dtsx.io" + "/" + "'"$CONFIG_BUILDER_IMAGE"'"' $CHART_HOME/values.yaml \ No newline at end of file From 49bdf9f86f37e54104835908affe3e603cdc4425 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Fri, 5 Jan 2024 17:37:59 +0200 Subject: [PATCH 4/6] Enable automated git checkout --- scripts/release-helm-chart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release-helm-chart.sh b/scripts/release-helm-chart.sh index 391c6d60..29028063 100755 --- a/scripts/release-helm-chart.sh +++ b/scripts/release-helm-chart.sh @@ -22,7 +22,7 @@ CRD_TARGET_PATH=$CRD_TMP_DIR TEMPLATE_HOME=$CHART_HOME/templates # Checkout tag -# git checkout v$VERSION +git checkout v$VERSION # Create CRDs kustomize build config/crd --output $CRD_TARGET_PATH From 9ecaa3b0a9677d6caa37aafda47ac5877a17f6dd Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Fri, 5 Jan 2024 17:39:39 +0200 Subject: [PATCH 5/6] Update comment --- scripts/release-helm-chart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release-helm-chart.sh b/scripts/release-helm-chart.sh index 29028063..46c8e895 100755 --- a/scripts/release-helm-chart.sh +++ b/scripts/release-helm-chart.sh @@ -33,7 +33,7 @@ for f in $CRD_TARGET_PATH/*; do mv $f $CRD_TARGET_PATH/$TARGET_FILENAME done -# Add conditionals to the and beginning before applying them to the templates path +# Add Helm conditionals to the end and beginnin of CRDs before applying them to the templates path echo "Updating CRDs in" $TEMPLATE_HOME CRD_FILE_NAME=$TEMPLATE_HOME/crds.yaml echo '{{- if .Values.updateCRDs }}' > $CRD_FILE_NAME From 58fc1617df1ba36b6323b7b95baaa4e5dbfe9ced Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Sat, 6 Jan 2024 00:59:30 +0200 Subject: [PATCH 6/6] Update scripts/release-helm-chart.sh Co-authored-by: Olivier Michallat --- scripts/release-helm-chart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release-helm-chart.sh b/scripts/release-helm-chart.sh index 46c8e895..326274f6 100755 --- a/scripts/release-helm-chart.sh +++ b/scripts/release-helm-chart.sh @@ -33,7 +33,7 @@ for f in $CRD_TARGET_PATH/*; do mv $f $CRD_TARGET_PATH/$TARGET_FILENAME done -# Add Helm conditionals to the end and beginnin of CRDs before applying them to the templates path +# Add Helm conditionals to the end and beginning of CRDs before applying them to the templates path echo "Updating CRDs in" $TEMPLATE_HOME CRD_FILE_NAME=$TEMPLATE_HOME/crds.yaml echo '{{- if .Values.updateCRDs }}' > $CRD_FILE_NAME