From 5a25a168b4947f883dce3ac53fd1b43205431142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20St=C3=A4bler?= Date: Tue, 12 Mar 2024 07:24:08 +0100 Subject: [PATCH] [release-1.32] Update contract downgrade script to be standalone (#2555) * Update script to allow namespace specification and to include names of main contract configmaps already. * Remove suppressing errors * Unset ingress.enableAutoCreateEventTypes in downgrade.sh too * Update test/upgrade/installation/downgrade.sh Co-authored-by: Calum Murray * Trigger update of volume with mounted contract configmap * kafka-source-receiver -> kafka-sink-receiver --------- Co-authored-by: Calum Murray Co-authored-by: Pierangelo Di Pilato --- test/upgrade/installation/downgrade.sh | 30 ++++++++++++++++++++++--- test/upgrade/installation/serverless.go | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/test/upgrade/installation/downgrade.sh b/test/upgrade/installation/downgrade.sh index dec2644106..2c92d16541 100755 --- a/test/upgrade/installation/downgrade.sh +++ b/test/upgrade/installation/downgrade.sh @@ -1,9 +1,33 @@ #!/usr/bin/env bash -for cm_name in "$@"; do - cmdata=$(kubectl get cm "$cm_name" -n knative-eventing -ojson) +# Removes the `trustBundles` key from contract configmaps. +# +# Usage +# downgrade.sh +# Example: +# downgrade.sh knative-eventing kafka-source-dispatcher-0 kafka-source-dispatcher-1 +# +# namespace: Optional - The namespace in which to update the configmaps. Defaults to "knative-eventing" +# additional-configmaps: Optional - List of additional contract configmaps to patch +# (in addition to kafka-broker-brokers-triggers, kafka-channel-channels-subscriptions and kafka-sink-sinks) + +target_namespace="${1:-"knative-eventing"}" +declare -a contract_configmaps=("kafka-broker-brokers-triggers" "kafka-channel-channels-subscriptions" "kafka-sink-sinks") + +for additional_cm in "${@:2}"; do + contract_configmaps+=("$additional_cm") +done + +for cm_name in "${contract_configmaps[@]}"; do + cmdata=$(kubectl get cm "$cm_name" -n "$target_namespace" -ojson || true) if [ -n "$cmdata" ]; then - new_data=$(echo "$cmdata" | jq -r .binaryData.data | base64 --decode | jq 'del(.trustBundles)' -c | base64 -w 0) + new_data=$(echo "$cmdata" | jq -r .binaryData.data | base64 --decode | jq 'del(.trustBundles, .resources[].ingress.enableAutoCreateEventTypes)' -c | base64 -w 0) echo "$cmdata" | jq --arg new_data "$new_data" '.binaryData.data = $new_data' | kubectl apply -f - fi done + +# Trigger a reconcile of the related pods (see https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#mounted-configmaps-are-updated-automatically) +declare -a pods_app_labels=("kafka-broker-dispatcher" "kafka-broker-receiver" "kafka-channel-dispatcher" "kafka-channel-receiver" "kafka-source-dispatcher" "kafka-sink-receiver") +for app_label in "${pods_app_labels[@]}"; do + kubectl -n "$target_namespace" annotate pod -l=app="$app_label" why="to trigger a reconcile" --overwrite || true +done diff --git a/test/upgrade/installation/serverless.go b/test/upgrade/installation/serverless.go index 02c043f6e3..582f03559b 100644 --- a/test/upgrade/installation/serverless.go +++ b/test/upgrade/installation/serverless.go @@ -262,7 +262,7 @@ func setStorageToAlpha(ctx *test.Context, name string) error { } func downgradeKafkaContractsWithScript() error { - c := exec.Command("bash", "-s", "-", "kafka-broker-brokers-triggers", "kafka-channel-channels-subscriptions", "kafka-sink-sinks", "kafka-source-dispatcher-0", "kafka-source-dispatcher-1") + c := exec.Command("bash", "-s", "-", test.EventingNamespace, "kafka-source-dispatcher-0", "kafka-source-dispatcher-1") c.Stdin = strings.NewReader(downgradeContractScript)