Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ukff committed Dec 16, 2024
1 parent d717a7c commit 1ad623d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions controllers/btpoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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 ""
Expand Down

0 comments on commit 1ad623d

Please sign in to comment.