From bb6c2be1c086a965ac38f8ff99eb254831e50994 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 11 Dec 2024 14:18:03 +0100 Subject: [PATCH 01/17] Watch sap-btp-operator-controller-manager --- controllers/btpoperator_controller.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index bb9e96244..0c539fad1 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -1264,6 +1264,11 @@ func (r *BtpOperatorReconciler) SetupWithManager(mgr ctrl.Manager) error { handler.EnqueueRequestsFromMapFunc(r.reconcileRequestForOldestBtpOperator), builder.WithPredicates(r.watchValidatingWebhooksPredicates()), ). + Watches( + &appsv1.Deployment{}, + handler.EnqueueRequestsFromMapFunc(r.reconcileRequestForOldestBtpOperator), + builder.WithPredicates(r.watchDeploymentPredicates()), + ). Complete(r) } @@ -1343,6 +1348,23 @@ func (r *BtpOperatorReconciler) watchSecretPredicates() predicate.TypedPredicate } } +func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { + return predicate.Funcs{ + CreateFunc: func(e event.CreateEvent) bool { + obj := e.Object.(*appsv1.Deployment) + return obj.Name == DeploymentName && obj.Namespace == ChartNamespace + }, + DeleteFunc: func(e event.DeleteEvent) bool { + obj := e.Object.(*appsv1.Deployment) + return obj.Name == DeploymentName && obj.Namespace == ChartNamespace + }, + UpdateFunc: func(e event.UpdateEvent) bool { + obj := e.ObjectNew.(*appsv1.Deployment) + return obj.Name == DeploymentName && obj.Namespace == ChartNamespace + }, + } +} + func (r *BtpOperatorReconciler) watchValidatingWebhooksPredicates() predicate.Funcs { return predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { From 3959dcee7fe8b3d3dfb02e5ab1222e69f18a034b Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 11 Dec 2024 14:49:22 +0100 Subject: [PATCH 02/17] Check deep --- controllers/btpoperator_controller.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index 0c539fad1..900758195 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -1359,8 +1359,9 @@ func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { return obj.Name == DeploymentName && obj.Namespace == ChartNamespace }, UpdateFunc: func(e event.UpdateEvent) bool { - obj := e.ObjectNew.(*appsv1.Deployment) - return obj.Name == DeploymentName && obj.Namespace == ChartNamespace + oldObj := e.ObjectOld.(*appsv1.Deployment) + newObj := e.ObjectNew.(*appsv1.Deployment) + return newObj.Name == DeploymentName && newObj.Namespace == ChartNamespace && !reflect.DeepEqual(oldObj.Spec, newObj.Spec) }, } } From b692e83147b4381a010ee69bf10c127d58960ded Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 11 Dec 2024 15:40:14 +0100 Subject: [PATCH 03/17] Check replicas --- controllers/btpoperator_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index 900758195..69edc7451 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -1361,7 +1361,7 @@ func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { UpdateFunc: func(e event.UpdateEvent) bool { oldObj := e.ObjectOld.(*appsv1.Deployment) newObj := e.ObjectNew.(*appsv1.Deployment) - return newObj.Name == DeploymentName && newObj.Namespace == ChartNamespace && !reflect.DeepEqual(oldObj.Spec, newObj.Spec) + return newObj.Name == DeploymentName && newObj.Namespace == ChartNamespace && oldObj.Status.ReadyReplicas != newObj.Status.ReadyReplicas }, } } From fcc134522120933c0307af04318fe33ef9a78f55 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Thu, 12 Dec 2024 14:27:48 +0100 Subject: [PATCH 04/17] Try another watch --- controllers/btpoperator_controller.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index 69edc7451..80511ad15 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -1359,9 +1359,19 @@ func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { return obj.Name == DeploymentName && obj.Namespace == ChartNamespace }, UpdateFunc: func(e event.UpdateEvent) bool { - oldObj := e.ObjectOld.(*appsv1.Deployment) newObj := e.ObjectNew.(*appsv1.Deployment) - return newObj.Name == DeploymentName && newObj.Namespace == ChartNamespace && oldObj.Status.ReadyReplicas != newObj.Status.ReadyReplicas + if newObj.Name != DeploymentName || newObj.Namespace != ChartNamespace { + return false + } + var newAvailableConditionStatus, newProgressingConditionStatus string + for _, condition := range newObj.Status.Conditions { + if string(condition.Type) == deploymentProgressingConditionType { + newProgressingConditionStatus = string(condition.Status) + } else if string(condition.Type) == deploymentAvailableConditionType { + newAvailableConditionStatus = string(condition.Status) + } + } + return newAvailableConditionStatus != "True" || newProgressingConditionStatus != "True" }, } } From 7f6075d4d8b7acf0afe138caed18137af4e30d35 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Fri, 13 Dec 2024 10:36:04 +0100 Subject: [PATCH 05/17] Change reconcile --- controllers/btpoperator_controller.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index 80511ad15..d9271b7be 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -1360,6 +1360,7 @@ func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { }, UpdateFunc: func(e event.UpdateEvent) bool { newObj := e.ObjectNew.(*appsv1.Deployment) + oldObj := e.ObjectOld.(*appsv1.Deployment) if newObj.Name != DeploymentName || newObj.Namespace != ChartNamespace { return false } @@ -1371,7 +1372,15 @@ func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { newAvailableConditionStatus = string(condition.Status) } } - return newAvailableConditionStatus != "True" || newProgressingConditionStatus != "True" + var oldAvailableConditionStatus, oldProgressingConditionStatus string + for _, condition := range oldObj.Status.Conditions { + if string(condition.Type) == deploymentProgressingConditionType { + oldProgressingConditionStatus = string(condition.Status) + } else if string(condition.Type) == deploymentAvailableConditionType { + oldAvailableConditionStatus = string(condition.Status) + } + } + return newAvailableConditionStatus != oldAvailableConditionStatus || newProgressingConditionStatus != oldProgressingConditionStatus }, } } From f9e8db01a0110441ef70cc56ae5bc8fece4f50f3 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Mon, 16 Dec 2024 10:45:14 +0100 Subject: [PATCH 06/17] Add test --- scripts/testing/run_e2e_module_tests.sh | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index b828751f1..585195b12 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -63,6 +63,42 @@ fi ./scripts/testing/multiple_btpoperators_exist.sh 10 +echo -e "\n--- Patching ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment with non-existing image" +kubectl patch deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system --patch '{"spec": {"template": {"spec": {"containers": [{"name": "manager", "image": "non-existing-image:0.0.00000"}]}}}}' + +echo -e "\n--- Deleting ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} pod" +kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system + +echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be in error" +availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') +progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') +SECONDS=0 +TIMEOUT=30 +while [[ "${availableConditionStatus}" != "False" ]] || [[ "${progressingConditionStatus}" != "True" ]]; do + echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be in error" + if [[ ${SECONDS} -ge ${TIMEOUT} ]]; then + echo "timed out after ${TIMEOUT}s" && exit 1 + fi + sleep 5 + availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') + progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') +done + +echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be reconciled and ready" +availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') +progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') +SECONDS=0 +TIMEOUT=30 +while [[ "${availableConditionStatus}" != "True" ]] || [[ "${progressingConditionStatus}" != "True" ]]; do + echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be reconciled and ready" + if [[ ${SECONDS} -ge ${TIMEOUT} ]]; then + echo "timed out after ${TIMEOUT}s" && exit 1 + fi + sleep 5 + availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') + progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') +done + echo -e "\n---Uninstalling..." # remove btp-operator (ServiceInstance and ServiceBinding should be deleted as well) From 9d42ce6d45d4c2d9f3301687eae4914127d028f4 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Mon, 16 Dec 2024 10:53:08 +0100 Subject: [PATCH 07/17] Refactor --- scripts/testing/run_e2e_module_tests.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index 585195b12..d34f8bbdf 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -70,33 +70,27 @@ echo -e "\n--- Deleting ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} pod" kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be in error" -availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') -progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') SECONDS=0 TIMEOUT=30 -while [[ "${availableConditionStatus}" != "False" ]] || [[ "${progressingConditionStatus}" != "True" ]]; do +until [[ "$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status')" == "False" ]] && \ + [[ "$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status')" == "True" ]]; do echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be in error" if [[ ${SECONDS} -ge ${TIMEOUT} ]]; then echo "timed out after ${TIMEOUT}s" && exit 1 fi sleep 5 - availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') - progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') done echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be reconciled and ready" -availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') -progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') SECONDS=0 TIMEOUT=30 -while [[ "${availableConditionStatus}" != "True" ]] || [[ "${progressingConditionStatus}" != "True" ]]; do +until [[ "$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status')" == "True" ]] && \ + [[ "$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status')" == "True" ]]; do echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be reconciled and ready" if [[ ${SECONDS} -ge ${TIMEOUT} ]]; then echo "timed out after ${TIMEOUT}s" && exit 1 fi sleep 5 - availableConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Available") | .status') - progressingConditionStatus=$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system -o json | jq -r '.status.conditions[] | select(.type=="Progressing") | .status') done echo -e "\n---Uninstalling..." From 3b9161e5404a54fee6bc58f7cc376f0083d466ad Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Mon, 16 Dec 2024 14:08:20 +0100 Subject: [PATCH 08/17] Add second test --- scripts/testing/run_e2e_module_tests.sh | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index d34f8bbdf..ba4e278b6 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -93,6 +93,44 @@ until [[ "$(kubectl get deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-s sleep 5 done +echo -e "\n--- Patching sap-btp-manager configmap with ReadyTimeout of 10 seconds" +kubectl patch configmap sap-btp-manager -n kyma-system --type merge -p '{"data":{"ReadyTimeout":"10s"}}' + +echo -e "\n--- Changing cluster_id in sap-btp-manager secret" +cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") +kubectl patch secret sap-btp-manager -n kyma-system -p '{"data":{"cluster_id":"dGVzdAo="}}' +kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system + +echo -e "\n--- Waiting for btpOperator to be in error" +while true; do + operator_status=$(kubectl get btpoperators/e2e-test-btpoperator -o json) + state_status=$(echo $operator_status | jq -r '.status.state') + + if [[ $state_status == "Error" ]]; then + break + else + echo -e "\n--- Waiting for btpOperator to be in error"; sleep 5; + fi +done + +echo -e "\n--- Patching sap-btp-manager configmap to remove ReadyTimeout" +kubectl patch configmap sap-btp-manager -n kyma-system --type json -p '[{"op": "remove", "path": "/data/ReadyTimeout"}]' + +echo -e "\n--- Changing cluster_id in sap-btp-manager secret back to original value" +kubectl patch secret sap-btp-manager -n kyma-system -p "{\"data\":{\"cluster_id\":\"${cluster_id}\"}}" + +echo -e "\n--- Waiting for btpOperator to be ready" +while true; do + operator_status=$(kubectl get btpoperators/e2e-test-btpoperator -o json) + state_status=$(echo $operator_status | jq -r '.status.state') + + if [[ $state_status == "Error" ]]; then + break + else + echo -e "\n--- Waiting for btpOperator to be ready"; sleep 5; + fi +done + echo -e "\n---Uninstalling..." # remove btp-operator (ServiceInstance and ServiceBinding should be deleted as well) From 34a6002c7255713e7868d895f6723dc6505f7e49 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Mon, 16 Dec 2024 14:21:45 +0100 Subject: [PATCH 09/17] Increase timeout --- .github/workflows/run-e2e-tests-reusable.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-e2e-tests-reusable.yaml b/.github/workflows/run-e2e-tests-reusable.yaml index 2aa1ef676..b79a0852a 100644 --- a/.github/workflows/run-e2e-tests-reusable.yaml +++ b/.github/workflows/run-e2e-tests-reusable.yaml @@ -56,7 +56,7 @@ jobs: run-e2e-matrix: runs-on: ubuntu-latest needs: prepare-tests - timeout-minutes: 5 + timeout-minutes: 7 strategy: matrix: ${{ fromJSON(needs.prepare-tests.outputs.versions) }} steps: From 8e489e25903199d5d0494de9ef5bfb70620ec22d Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 07:38:38 +0100 Subject: [PATCH 10/17] Wait for pods --- scripts/testing/run_e2e_module_tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index ba4e278b6..445d830b5 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -99,6 +99,10 @@ kubectl patch configmap sap-btp-manager -n kyma-system --type merge -p '{"data": echo -e "\n--- Changing cluster_id in sap-btp-manager secret" cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") kubectl patch secret sap-btp-manager -n kyma-system -p '{"data":{"cluster_id":"dGVzdAo="}}' +until [[ $(kubectl get pods -l app.kubernetes.io/name=sap-btp-operator -n kyma-system --no-headers | wc -l) -eq 2 ]]; do + sleep 5; +done + kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system echo -e "\n--- Waiting for btpOperator to be in error" From f3ff5468c7e104a17c7899b7b3fa2e3669d2de26 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 07:59:49 +0100 Subject: [PATCH 11/17] Add log --- scripts/testing/run_e2e_module_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index 445d830b5..f380f4d43 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -100,7 +100,7 @@ echo -e "\n--- Changing cluster_id in sap-btp-manager secret" cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") kubectl patch secret sap-btp-manager -n kyma-system -p '{"data":{"cluster_id":"dGVzdAo="}}' until [[ $(kubectl get pods -l app.kubernetes.io/name=sap-btp-operator -n kyma-system --no-headers | wc -l) -eq 2 ]]; do - sleep 5; + echo -e "\n--- Waiting for sap-btp-operator pods to be recreated"; sleep 5; done kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system From 35287fa4710b4c57faa461202c24becb73b95aca Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 08:22:05 +0100 Subject: [PATCH 12/17] Wait for change --- scripts/testing/run_e2e_module_tests.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index f380f4d43..4fc256093 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -99,10 +99,7 @@ kubectl patch configmap sap-btp-manager -n kyma-system --type merge -p '{"data": echo -e "\n--- Changing cluster_id in sap-btp-manager secret" cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") kubectl patch secret sap-btp-manager -n kyma-system -p '{"data":{"cluster_id":"dGVzdAo="}}' -until [[ $(kubectl get pods -l app.kubernetes.io/name=sap-btp-operator -n kyma-system --no-headers | wc -l) -eq 2 ]]; do - echo -e "\n--- Waiting for sap-btp-operator pods to be recreated"; sleep 5; -done - +sleep 5 kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system echo -e "\n--- Waiting for btpOperator to be in error" From f076ef8871bf7a19d3330aa07e096b0681279d20 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 08:30:00 +0100 Subject: [PATCH 13/17] Restore timeout --- .github/workflows/run-e2e-tests-reusable.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-e2e-tests-reusable.yaml b/.github/workflows/run-e2e-tests-reusable.yaml index b79a0852a..2aa1ef676 100644 --- a/.github/workflows/run-e2e-tests-reusable.yaml +++ b/.github/workflows/run-e2e-tests-reusable.yaml @@ -56,7 +56,7 @@ jobs: run-e2e-matrix: runs-on: ubuntu-latest needs: prepare-tests - timeout-minutes: 7 + timeout-minutes: 5 strategy: matrix: ${{ fromJSON(needs.prepare-tests.outputs.versions) }} steps: From aef059540791991a4b3293493ef00495d3afbf26 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 08:45:54 +0100 Subject: [PATCH 14/17] Less multiple btpoperators executions --- scripts/testing/run_e2e_module_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index 4fc256093..1d6f0b864 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -61,7 +61,7 @@ else echo -e "\n--- Service binding is not ready due to dummy/invalid credentials (Ready: NotProvisioned, Succeeded: CreateInProgress)" fi -./scripts/testing/multiple_btpoperators_exist.sh 10 +./scripts/testing/multiple_btpoperators_exist.sh 5 echo -e "\n--- Patching ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment with non-existing image" kubectl patch deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system --patch '{"spec": {"template": {"spec": {"containers": [{"name": "manager", "image": "non-existing-image:0.0.00000"}]}}}}' From 381943bdeae8d9eeeec07e4f496081662271e1c6 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 15:24:00 +0100 Subject: [PATCH 15/17] Use CM not secret --- scripts/testing/run_e2e_module_tests.sh | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index 1d6f0b864..c12d6656b 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -20,10 +20,10 @@ CREDENTIALS=$1 YAML_DIR="scripts/testing/yaml" SAP_BTP_OPERATOR_DEPLOYMENT_NAME=sap-btp-operator-controller-manager -[[ -z ${GITHUB_RUN_ID} ]] && echo "required variable GITHUB_RUN_ID not set" && exit 1 +#[[ -z ${GITHUB_RUN_ID} ]] && echo "required variable GITHUB_RUN_ID not set" && exit 1 -SI_NAME=auditlog-management-si-${GITHUB_JOB}-${GITHUB_RUN_ID} -SB_NAME=auditlog-management-sb-${GITHUB_JOB}-${GITHUB_RUN_ID} +SI_NAME=auditlog-management-si-2 +SB_NAME=auditlog-management-sb-3 export SI_NAME export SB_NAME @@ -61,7 +61,7 @@ else echo -e "\n--- Service binding is not ready due to dummy/invalid credentials (Ready: NotProvisioned, Succeeded: CreateInProgress)" fi -./scripts/testing/multiple_btpoperators_exist.sh 5 +#./scripts/testing/multiple_btpoperators_exist.sh 5 echo -e "\n--- Patching ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment with non-existing image" kubectl patch deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system --patch '{"spec": {"template": {"spec": {"containers": [{"name": "manager", "image": "non-existing-image:0.0.00000"}]}}}}' @@ -96,30 +96,36 @@ done echo -e "\n--- Patching sap-btp-manager configmap with ReadyTimeout of 10 seconds" kubectl patch configmap sap-btp-manager -n kyma-system --type merge -p '{"data":{"ReadyTimeout":"10s"}}' -echo -e "\n--- Changing cluster_id in sap-btp-manager secret" -cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") -kubectl patch secret sap-btp-manager -n kyma-system -p '{"data":{"cluster_id":"dGVzdAo="}}' +echo -e "\n--- Saving lastTransitionTime of btpOperator" +last_transition_time=$(kubectl get btpoperators/e2e-test-btpoperator -o json | jq -r '.status.conditions[] | select(.type=="Ready") | .lastTransitionTime') + +echo -e "\n--- Changing CLUSTER_ID in configmap sap-btp-operator-config" +#cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") +#toch CM not secret + +kubectl patch configmap sap-btp-operator-config -n kyma-system -p '{"data":{"CLUSTER_ID":"dGVzdAo="}}' sleep 5 kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system -echo -e "\n--- Waiting for btpOperator to be in error" +echo -e "\n--- Waiting for btpOperator to be in error or LastTransitionTime to change" while true; do operator_status=$(kubectl get btpoperators/e2e-test-btpoperator -o json) state_status=$(echo $operator_status | jq -r '.status.state') - + current_last_transition_time=$(echo $operator_status | jq -r '.status.conditions[] | select(.type=="Ready") | .lastTransitionTime') if [[ $state_status == "Error" ]]; then + echo -e "\n--- btpOperator is in error state" + break + elif [[ $current_last_transition_time != $last_transition_time ]]; then + echo -e "\n--- LastTransitionTime has changed so error state was set on btpOperator" break else - echo -e "\n--- Waiting for btpOperator to be in error"; sleep 5; + echo -e "\n--- Waiting for btpOperator to be in error or LastTransitionTime to change"; sleep 1; fi done echo -e "\n--- Patching sap-btp-manager configmap to remove ReadyTimeout" kubectl patch configmap sap-btp-manager -n kyma-system --type json -p '[{"op": "remove", "path": "/data/ReadyTimeout"}]' -echo -e "\n--- Changing cluster_id in sap-btp-manager secret back to original value" -kubectl patch secret sap-btp-manager -n kyma-system -p "{\"data\":{\"cluster_id\":\"${cluster_id}\"}}" - echo -e "\n--- Waiting for btpOperator to be ready" while true; do operator_status=$(kubectl get btpoperators/e2e-test-btpoperator -o json) From fd296d82c148feef6023f168da0b66de5bef6ce1 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 17 Dec 2024 15:47:54 +0100 Subject: [PATCH 16/17] Fix --- scripts/testing/run_e2e_module_tests.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/testing/run_e2e_module_tests.sh b/scripts/testing/run_e2e_module_tests.sh index c12d6656b..e8d410735 100755 --- a/scripts/testing/run_e2e_module_tests.sh +++ b/scripts/testing/run_e2e_module_tests.sh @@ -20,10 +20,10 @@ CREDENTIALS=$1 YAML_DIR="scripts/testing/yaml" SAP_BTP_OPERATOR_DEPLOYMENT_NAME=sap-btp-operator-controller-manager -#[[ -z ${GITHUB_RUN_ID} ]] && echo "required variable GITHUB_RUN_ID not set" && exit 1 +[[ -z ${GITHUB_RUN_ID} ]] && echo "required variable GITHUB_RUN_ID not set" && exit 1 -SI_NAME=auditlog-management-si-2 -SB_NAME=auditlog-management-sb-3 +SI_NAME=auditlog-management-si-${GITHUB_JOB}-${GITHUB_RUN_ID} +SB_NAME=auditlog-management-sb-${GITHUB_JOB}-${GITHUB_RUN_ID} export SI_NAME export SB_NAME @@ -61,7 +61,7 @@ else echo -e "\n--- Service binding is not ready due to dummy/invalid credentials (Ready: NotProvisioned, Succeeded: CreateInProgress)" fi -#./scripts/testing/multiple_btpoperators_exist.sh 5 +./scripts/testing/multiple_btpoperators_exist.sh 5 echo -e "\n--- Patching ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment with non-existing image" kubectl patch deployment ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} -n kyma-system --patch '{"spec": {"template": {"spec": {"containers": [{"name": "manager", "image": "non-existing-image:0.0.00000"}]}}}}' @@ -100,9 +100,6 @@ echo -e "\n--- Saving lastTransitionTime of btpOperator" last_transition_time=$(kubectl get btpoperators/e2e-test-btpoperator -o json | jq -r '.status.conditions[] | select(.type=="Ready") | .lastTransitionTime') echo -e "\n--- Changing CLUSTER_ID in configmap sap-btp-operator-config" -#cluster_id=$(kubectl get secret sap-btp-manager -n kyma-system -o jsonpath="{.data.cluster_id}") -#toch CM not secret - kubectl patch configmap sap-btp-operator-config -n kyma-system -p '{"data":{"CLUSTER_ID":"dGVzdAo="}}' sleep 5 kubectl delete pod -l app.kubernetes.io/name=sap-btp-operator -n kyma-system @@ -131,7 +128,7 @@ while true; do operator_status=$(kubectl get btpoperators/e2e-test-btpoperator -o json) state_status=$(echo $operator_status | jq -r '.status.state') - if [[ $state_status == "Error" ]]; then + if [[ $state_status == "Ready" ]]; then break else echo -e "\n--- Waiting for btpOperator to be ready"; sleep 5; From 51ebed7a3c99a2f551aec107a3c0b5ba4e9c98b5 Mon Sep 17 00:00:00 2001 From: Marek Michali <56163696+MarekMichali@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:29:39 +0100 Subject: [PATCH 17/17] Update controllers/btpoperator_controller.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jarosław Pieszka --- controllers/btpoperator_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index d9271b7be..c0e727aa4 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -1361,7 +1361,7 @@ func (r *BtpOperatorReconciler) watchDeploymentPredicates() predicate.Funcs { UpdateFunc: func(e event.UpdateEvent) bool { newObj := e.ObjectNew.(*appsv1.Deployment) oldObj := e.ObjectOld.(*appsv1.Deployment) - if newObj.Name != DeploymentName || newObj.Namespace != ChartNamespace { + if !(newObj.Name == DeploymentName && newObj.Namespace == ChartNamespace) { return false } var newAvailableConditionStatus, newProgressingConditionStatus string