diff --git a/controllers/compassmanager_controller.go b/controllers/compassmanager_controller.go index c988194..c9440da 100644 --- a/controllers/compassmanager_controller.go +++ b/controllers/compassmanager_controller.go @@ -137,6 +137,9 @@ func (cm *CompassManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ compassRuntimeID, err := cm.getRuntimeIDFromCompassMapping(req.Name, req.Namespace) + kymaLabels := kymaCR.Labels + kymaAnnotations := kymaCR.Annotations + if migrationCompassRuntimeID, ok := kymaAnnotations[AnnotationIDForMigration]; compassRuntimeID == "" && ok { cm.Log.Infof("Configuring compass for already registered Kyma resource %s.", req.Name) cmerr := cm.upsertCompassMappingResource(migrationCompassRuntimeID, req.Namespace, kymaLabels) @@ -150,8 +153,6 @@ func (cm *CompassManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ return ctrl.Result{}, errors.Wrapf(err, "failed to obtain Compass Runtime ID from Kyma resource %s", req.Name) } - kymaLabels := kymaCR.Labels - if compassRuntimeID == "" { newCompassRuntimeID, regErr := cm.Registrator.RegisterInCompass(createCompassRuntimeLabels(kymaLabels)) if regErr != nil { @@ -280,7 +281,7 @@ func (cm *CompassManagerReconciler) getRuntimeIDFromCompassMapping(kymaName, nam func (cm *CompassManagerReconciler) getGlobalAccountFromCompassMapping(kymaName, namespace string) (string, error) { mappingList := &v1beta1.CompassManagerMappingList{} labelSelector := labels.SelectorFromSet(map[string]string{ - KymaNameLabel: kymaName, + LabelKymaName: kymaName, }) err := cm.Client.List(context.Background(), mappingList, &client.ListOptions{ @@ -296,7 +297,7 @@ func (cm *CompassManagerReconciler) getGlobalAccountFromCompassMapping(kymaName, return "", nil } - return mappingList.Items[0].GetLabels()[GlobalAccountIDLabel], nil + return mappingList.Items[0].GetLabels()[LabelGlobalAccountID], nil } func (cm *CompassManagerReconciler) handleKymaDeletion(kymaName, namespace string) error { diff --git a/controllers/compassmanager_controller_test.go b/controllers/compassmanager_controller_test.go index d037e6e..313e83a 100644 --- a/controllers/compassmanager_controller_test.go +++ b/controllers/compassmanager_controller_test.go @@ -108,7 +108,7 @@ var _ = Describe("Compass Manager controller", func() { Expect(k8sClient.Create(context.Background(), &kymaCR)).To(Succeed()) Eventually(func() bool { - label, err := getCompassMappingLabel(kymaCR.Name, ComppassIDLabel, kymaCustomResourceNamespace) + label, err := getCompassMappingCompassID(kymaCR.Name) return err == nil && label != "" }, clientTimeout, clientInterval).Should(BeTrue()) @@ -117,7 +117,7 @@ var _ = Describe("Compass Manager controller", func() { Expect(k8sClient.Delete(context.Background(), &kymaCR)).To(Succeed()) Eventually(func() bool { - label, err := getCompassMappingLabel(kymaCR.Name, ComppassIDLabel, kymaCustomResourceNamespace) + label, err := getCompassMappingCompassID(kymaCR.Name) return errors.IsNotFound(err) && label == "" }, clientTimeout, clientInterval).Should(BeTrue())