From 01e870c83a49e9f448b322a0f76f5504abd9a2e4 Mon Sep 17 00:00:00 2001 From: Leonard Cohnen Date: Wed, 4 Jan 2023 23:21:05 +0100 Subject: [PATCH] operator: use mainconstants --- .../controllers/joiningnode_controller.go | 6 +- .../joiningnode_controller_env_test.go | 5 +- .../controllers/nodeversion_controller.go | 3 +- .../nodeversion_controller_test.go | 57 ++++++++++--------- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/operators/constellation-node-operator/controllers/joiningnode_controller.go b/operators/constellation-node-operator/controllers/joiningnode_controller.go index 382284afd..8e0b1df4d 100644 --- a/operators/constellation-node-operator/controllers/joiningnode_controller.go +++ b/operators/constellation-node-operator/controllers/joiningnode_controller.go @@ -10,6 +10,7 @@ import ( "context" "time" + mainconstants "github.com/edgelesssys/constellation/v2/internal/constants" updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -26,9 +27,6 @@ import ( ) const ( - // NodeKubernetesComponentsReferenceAnnotationKey is the name of the annotation holding the reference to the ConfigMap listing all K8s components. - NodeKubernetesComponentsReferenceAnnotationKey = "constellation.edgeless.systems/kubernetes-components" - joiningNodeNameKey = ".spec.name" ) @@ -76,7 +74,7 @@ func (r *JoiningNodesReconciler) Reconcile(ctx context.Context, req ctrl.Request if node.Annotations == nil { node.Annotations = map[string]string{} } - node.Annotations[NodeKubernetesComponentsReferenceAnnotationKey] = joiningNode.Spec.ComponentsReference + node.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey] = joiningNode.Spec.ComponentsReference return r.Update(ctx, &node) }) if err != nil { diff --git a/operators/constellation-node-operator/controllers/joiningnode_controller_env_test.go b/operators/constellation-node-operator/controllers/joiningnode_controller_env_test.go index b5c0b2e79..19a199efb 100644 --- a/operators/constellation-node-operator/controllers/joiningnode_controller_env_test.go +++ b/operators/constellation-node-operator/controllers/joiningnode_controller_env_test.go @@ -18,6 +18,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + mainconstants "github.com/edgelesssys/constellation/v2/internal/constants" updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1" ) @@ -80,7 +81,7 @@ var _ = Describe("JoiningNode controller", func() { By("annotating the node") Eventually(func() string { _ = k8sClient.Get(ctx, types.NamespacedName{Name: nodeName1}, createdNode) - return createdNode.Annotations[NodeKubernetesComponentsReferenceAnnotationKey] + return createdNode.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey] }, timeout, interval).Should(Equal(ComponentsReference1)) By("deleting the joining node resource") @@ -134,7 +135,7 @@ var _ = Describe("JoiningNode controller", func() { By("annotating the node") Eventually(func() string { _ = k8sClient.Get(ctx, types.NamespacedName{Name: createdNode.Name}, createdNode) - return createdNode.Annotations[NodeKubernetesComponentsReferenceAnnotationKey] + return createdNode.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey] }, timeout, interval).Should(Equal(ComponentsReference2)) By("deleting the joining node resource") diff --git a/operators/constellation-node-operator/controllers/nodeversion_controller.go b/operators/constellation-node-operator/controllers/nodeversion_controller.go index f97841c5f..c2d860a42 100644 --- a/operators/constellation-node-operator/controllers/nodeversion_controller.go +++ b/operators/constellation-node-operator/controllers/nodeversion_controller.go @@ -12,6 +12,7 @@ import ( "strings" "time" + mainconstants "github.com/edgelesssys/constellation/v2/internal/constants" nodeutil "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/internal/node" "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/internal/patch" corev1 "k8s.io/api/core/v1" @@ -776,7 +777,7 @@ func groupNodes(nodes []corev1.Node, pendingNodes []updatev1alpha1.PendingNode, continue } if !strings.EqualFold(node.Annotations[nodeImageAnnotation], latestImageReference) || - !strings.EqualFold(node.Annotations[NodeKubernetesComponentsReferenceAnnotationKey], latestK8sComponentsReference) { + !strings.EqualFold(node.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey], latestK8sComponentsReference) { if heir := node.Annotations[heirAnnotation]; heir != "" { groups.Donors = append(groups.Donors, node) } else { diff --git a/operators/constellation-node-operator/controllers/nodeversion_controller_test.go b/operators/constellation-node-operator/controllers/nodeversion_controller_test.go index e07df5ea8..e99e107b0 100644 --- a/operators/constellation-node-operator/controllers/nodeversion_controller_test.go +++ b/operators/constellation-node-operator/controllers/nodeversion_controller_test.go @@ -18,6 +18,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + mainconstants "github.com/edgelesssys/constellation/v2/internal/constants" updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1" ) @@ -608,9 +609,9 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "outdated", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference, - nodeImageAnnotation: "old-image", + scalingGroupAnnotation: scalingGroup, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference, + nodeImageAnnotation: "old-image", }, }, }, @@ -618,9 +619,9 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "outdated", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - NodeKubernetesComponentsReferenceAnnotationKey: "old-ref", - nodeImageAnnotation: latestImageReference, + scalingGroupAnnotation: scalingGroup, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: "old-ref", + nodeImageAnnotation: latestImageReference, }, }, }, @@ -630,9 +631,9 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "uptodate", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - nodeImageAnnotation: latestImageReference, - NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference, + scalingGroupAnnotation: scalingGroup, + nodeImageAnnotation: latestImageReference, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference, }, }, }, @@ -642,10 +643,10 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "donor", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - nodeImageAnnotation: "old-image", - NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference, - heirAnnotation: "heir", + scalingGroupAnnotation: scalingGroup, + nodeImageAnnotation: "old-image", + mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference, + heirAnnotation: "heir", }, }, }, @@ -653,10 +654,10 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "donor", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - nodeImageAnnotation: latestImageReference, - NodeKubernetesComponentsReferenceAnnotationKey: "old-ref", - heirAnnotation: "heir", + scalingGroupAnnotation: scalingGroup, + nodeImageAnnotation: latestImageReference, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: "old-ref", + heirAnnotation: "heir", }, }, }, @@ -666,10 +667,10 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "heir", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - nodeImageAnnotation: latestImageReference, - NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference, - donorAnnotation: "donor", + scalingGroupAnnotation: scalingGroup, + nodeImageAnnotation: latestImageReference, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference, + donorAnnotation: "donor", }, }, }, @@ -679,10 +680,10 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "obsolete", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - nodeImageAnnotation: latestImageReference, - NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference, - obsoleteAnnotation: "true", + scalingGroupAnnotation: scalingGroup, + nodeImageAnnotation: latestImageReference, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference, + obsoleteAnnotation: "true", }, }, }, @@ -693,9 +694,9 @@ func TestGroupNodes(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "mint", Annotations: map[string]string{ - scalingGroupAnnotation: scalingGroup, - nodeImageAnnotation: latestImageReference, - NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference, + scalingGroupAnnotation: scalingGroup, + nodeImageAnnotation: latestImageReference, + mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference, }, }, },