diff --git a/api/common/consts.go b/api/common/consts.go index ba488ac9..dd1a2166 100644 --- a/api/common/consts.go +++ b/api/common/consts.go @@ -2,6 +2,7 @@ package common const ( ManagedByBTPOperatorLabel = "services.cloud.sap.com/managed-by-sap-btp-operator" + ClusterSecretLabel = "services.cloud.sap.com/cluster-secret" NamespaceLabel = "_namespace" K8sNameLabel = "_k8sname" diff --git a/main.go b/main.go index b734c347..50bd0c47 100644 --- a/main.go +++ b/main.go @@ -209,6 +209,7 @@ func createClusterSecret(client client.Client) { clusterSecret := &v1.Secret{} clusterSecret.Name = "sap-btp-operator-clusterid" clusterSecret.Namespace = config.Get().ReleaseNamespace + clusterSecret.Labels = map[string]string{common.ManagedByBTPOperatorLabel: "true", common.ClusterSecretLabel: "true"} clusterSecret.StringData = map[string]string{"INITIAL_CLUSTER_ID": config.Get().ClusterID} clusterSecret.Labels = map[string]string{common.ManagedByBTPOperatorLabel: "true"} if err := client.Create(context.Background(), clusterSecret); err != nil { diff --git a/sapbtp-operator-charts/templates/pre-delete-job.yml b/sapbtp-operator-charts/templates/pre-delete-job.yml index 06ba89fd..16b7b3ac 100644 --- a/sapbtp-operator-charts/templates/pre-delete-job.yml +++ b/sapbtp-operator-charts/templates/pre-delete-job.yml @@ -32,27 +32,23 @@ spec: args: - "-c" - | - servicebindingsCRD="servicebindings.services.cloud.sap.com" - kubectl get $servicebindingsCRD -A - kubectl get $servicebindingsCRD -A --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | tail -n +2 | while read -r line; do + kubectl get servicebindings.services.cloud.sap.com -A --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | tail -n +2 | while read -r line; do name=$(echo $line | awk '{print $1}') namespace=$(echo $line | awk '{print $2}') echo "Deleting binding with Name: $name, and Namespace: $namespace" - timeout 30 kubectl delete $servicebindingsCRD $name -n $namespace + timeout 30 kubectl delete servicebindings.services.cloud.sap.com $name -n $namespace if [ $? -ne 0 ]; then echo "Failed to delete service binding $name" exit 1 fi done - echo "No more bindings found" + echo "Deleting bindings finished successfully" - serviceinstanceCRD="serviceinstances.services.cloud.sap.com" - kubectl get $serviceinstanceCRD -A - kubectl get $serviceinstanceCRD -A --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | tail -n +2 | while read -r line; do + kubectl get serviceinstances.services.cloud.sap.com -A --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | tail -n +2 | while read -r line; do name=$(echo $line | awk '{print $1}') namespace=$(echo $line | awk '{print $2}') echo "Deleting instance with Name: $name, and Namespace: $namespace" - timeout 30 kubectl delete $serviceinstanceCRD $name -n $namespace + timeout 30 kubectl delete serviceinstances.services.cloud.sap.com $name -n $namespace if [ $? -ne 0 ]; then echo "Failed to delete service instance $name" exit 1 @@ -62,8 +58,20 @@ spec: if [ $? -ne 0 ]; then exit 1 fi + echo "Deleting instances finished successfully" + + kubectl get secrets -l "services.cloud.sap.com/cluster-secret" -A --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | tail -n +2 | while read -r line; do + name=$(echo $line | awk '{print $1}') + namespace=$(echo $line | awk '{print $2}') + echo "Deleting secret with Name: $name, and Namespace: $namespace" + timeout 30 kubectl delete secret $name -n $namespace + if [ $? -ne 0 ]; then + echo "Failed to delete secret $name" + exit 1 + fi + done + echo "Cluster secret deletion finished successfully" - echo "No more instances found" exit 0 restartPolicy: Never