diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index c95db280e..a76341966 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -2066,21 +2066,22 @@ func (r *BtpOperatorReconciler) reconcileResourcesWithoutChangingCrState(ctx con func (r *BtpOperatorReconciler) handleSapBtpManagerChange(ctx context.Context, logger *logr.Logger) error { logger.Info("handling SAP BTP Manager change") - configMap := &corev1.ConfigMap{} + var err error + configMap := &corev1.ConfigMap{} sapBtpSecret := r.buildSecretWithDataAndLabels(SecretName, nil, nil) clusterIdSecret := r.buildSecretWithDataAndLabels(clusterIdSecretName, nil, nil) - clusterIdUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(clusterIdSecret) - clusterIdUnstructuredObj := &unstructured.Unstructured{Object: clusterIdUnstructured} - if err != nil { - return fmt.Errorf("failed to secret: %s in %s to unstructred : %s \n", sapBtpSecret.GetName(), sapBtpSecret.GetNamespace(), err.Error()) - } err = r.Get(ctx, client.ObjectKey{Namespace: ChartNamespace, Name: SecretName}, sapBtpSecret) if err != nil { return fmt.Errorf("failed to get secret %s in %s : %s \n", sapBtpSecret.GetName(), sapBtpSecret.GetNamespace(), err.Error()) } + clusterIdUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(clusterIdSecret) + if err != nil { + return fmt.Errorf("failed to secret: %s in %s to unstructred : %s \n", sapBtpSecret.GetName(), sapBtpSecret.GetNamespace(), err.Error()) + } + clusterIdUnstructuredObj := &unstructured.Unstructured{Object: clusterIdUnstructured} synced, err := r.getDependedResourcesForSecretChange(ctx, clusterIdUnstructuredObj, sapBtpSecret, configMap, logger) if err != nil { return fmt.Errorf("while checking data integrity") @@ -2152,7 +2153,7 @@ func inSync(clusterId *unstructured.Unstructured, sapBtpManager *corev1.Secret, return false } - clusterIdObj := dataValueFromObject(clusterId, clusterIdSecretKey) + clusterIdObj := valueFromUnstructured(clusterId, clusterIdSecretKey) match := strings.EqualFold(clusterIdObj, string(sapBtpManager.Data[sapBtpManagerSecretClusterIdKey])) match = match && strings.EqualFold(clusterIdObj, configMap.Data[clusterIdKeyConfigMap]) logger.Info("are config map and secrets in sync?", "match", match) @@ -2177,7 +2178,7 @@ func (r *BtpOperatorReconciler) restartDeployment(ctx context.Context) error { return nil } -func dataValueFromObject(us *unstructured.Unstructured, key string) string { +func valueFromUnstructured(us *unstructured.Unstructured, key string) string { data, ok := us.Object["data"].(map[string]interface{}) if !ok { return ""