Skip to content

Commit

Permalink
[release-1.32] Update contract downgrade script to be standalone (#2555)
Browse files Browse the repository at this point in the history
* 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 <cmurray@redhat.com>

* Trigger update of volume with mounted contract configmap

* kafka-source-receiver -> kafka-sink-receiver

---------

Co-authored-by: Calum Murray <cmurray@redhat.com>
Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
  • Loading branch information
3 people committed Mar 12, 2024
1 parent 1d312db commit 5a25a16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions 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 <namespace> <additional-configmaps>
# 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
2 changes: 1 addition & 1 deletion test/upgrade/installation/serverless.go
Expand Up @@ -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)

Expand Down

0 comments on commit 5a25a16

Please sign in to comment.