Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch sap-btp-operator-controller-manager #924

Merged
merged 17 commits into from
Dec 18, 2024
42 changes: 42 additions & 0 deletions controllers/btpoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -1343,6 +1348,43 @@ 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 {
newObj := e.ObjectNew.(*appsv1.Deployment)
oldObj := e.ObjectOld.(*appsv1.Deployment)
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)
}
}
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
},
}
}

func (r *BtpOperatorReconciler) watchValidatingWebhooksPredicates() predicate.Funcs {
return predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
Expand Down
74 changes: 73 additions & 1 deletion scripts/testing/run_e2e_module_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,79 @@ 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"}]}}}}'

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"
SECONDS=0
TIMEOUT=30
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
done

echo -e "\n--- Waiting for ${SAP_BTP_OPERATOR_DEPLOYMENT_NAME} deployment to be reconciled and ready"
SECONDS=0
TIMEOUT=30
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
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--- 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"
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 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 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--- 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 == "Ready" ]]; then
break
else
echo -e "\n--- Waiting for btpOperator to be ready"; sleep 5;
fi
done

echo -e "\n---Uninstalling..."

Expand Down
Loading