From 583c1c5d27d452752048177a40d13386f71bf75a Mon Sep 17 00:00:00 2001 From: Leonard Cohnen Date: Sun, 20 Oct 2024 22:16:47 +0200 Subject: [PATCH] operator: move control plane label to constants --- .../constellation-node-operator/controllers/BUILD.bazel | 1 + .../internal/constants/constants.go | 2 ++ .../internal/controlplane/BUILD.bazel | 1 + .../internal/controlplane/controlplane_test.go | 3 ++- .../constellation-node-operator/internal/etcd/BUILD.bazel | 1 + .../constellation-node-operator/internal/etcd/etcd_test.go | 3 ++- .../constellation-node-operator/internal/node/BUILD.bazel | 2 ++ operators/constellation-node-operator/internal/node/node.go | 5 ++--- .../constellation-node-operator/internal/node/node_test.go | 3 ++- 9 files changed, 15 insertions(+), 6 deletions(-) diff --git a/operators/constellation-node-operator/controllers/BUILD.bazel b/operators/constellation-node-operator/controllers/BUILD.bazel index f6653580918..2a24c2584b5 100644 --- a/operators/constellation-node-operator/controllers/BUILD.bazel +++ b/operators/constellation-node-operator/controllers/BUILD.bazel @@ -81,6 +81,7 @@ go_test( "//3rdparty/node-maintenance-operator/api/v1beta1", "//internal/constants", "//operators/constellation-node-operator/api/v1alpha1", + "//operators/constellation-node-operator/internal/constants", "@com_github_onsi_ginkgo_v2//:ginkgo", "@com_github_onsi_gomega//:gomega", "@com_github_stretchr_testify//assert", diff --git a/operators/constellation-node-operator/internal/constants/constants.go b/operators/constellation-node-operator/internal/constants/constants.go index b057df59cb8..db493530037 100644 --- a/operators/constellation-node-operator/internal/constants/constants.go +++ b/operators/constellation-node-operator/internal/constants/constants.go @@ -19,4 +19,6 @@ const ( PlaceholderControlPlaneScalingGroupName = "control-planes-id" // PlaceholderWorkerScalingGroupName name of the worker scaling group used if upgrades are not yet supported. PlaceholderWorkerScalingGroupName = "workers-id" + // ControlPlaneRoleLabel label used to identify control plane nodes. + ControlPlaneRoleLabel = "node-role.kubernetes.io/control-plane" ) diff --git a/operators/constellation-node-operator/internal/controlplane/BUILD.bazel b/operators/constellation-node-operator/internal/controlplane/BUILD.bazel index 65651541d01..c2495adbb45 100644 --- a/operators/constellation-node-operator/internal/controlplane/BUILD.bazel +++ b/operators/constellation-node-operator/internal/controlplane/BUILD.bazel @@ -18,6 +18,7 @@ go_test( srcs = ["controlplane_test.go"], embed = [":controlplane"], deps = [ + "//operators/constellation-node-operator/internal/constants", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@io_k8s_api//core/v1:core", diff --git a/operators/constellation-node-operator/internal/controlplane/controlplane_test.go b/operators/constellation-node-operator/internal/controlplane/controlplane_test.go index a089f02b347..6aba0137bd9 100644 --- a/operators/constellation-node-operator/internal/controlplane/controlplane_test.go +++ b/operators/constellation-node-operator/internal/controlplane/controlplane_test.go @@ -11,6 +11,7 @@ import ( "errors" "testing" + "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/internal/constants" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -29,7 +30,7 @@ func TestListControlPlaneIPs(t *testing.T) { nodes: []corev1.Node{ { ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{"node-role.kubernetes.io/control-plane": ""}, + Labels: map[string]string{constants.ControlPlaneRoleLabel: ""}, }, Status: corev1.NodeStatus{Addresses: []corev1.NodeAddress{{ Type: corev1.NodeInternalIP, diff --git a/operators/constellation-node-operator/internal/etcd/BUILD.bazel b/operators/constellation-node-operator/internal/etcd/BUILD.bazel index f41f5bbf5e9..f4e6ced77d0 100644 --- a/operators/constellation-node-operator/internal/etcd/BUILD.bazel +++ b/operators/constellation-node-operator/internal/etcd/BUILD.bazel @@ -19,6 +19,7 @@ go_test( srcs = ["etcd_test.go"], embed = [":etcd"], deps = [ + "//operators/constellation-node-operator/internal/constants", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@io_etcd_go_etcd_api_v3//etcdserverpb", diff --git a/operators/constellation-node-operator/internal/etcd/etcd_test.go b/operators/constellation-node-operator/internal/etcd/etcd_test.go index 5775140cbc8..30e04d817ea 100644 --- a/operators/constellation-node-operator/internal/etcd/etcd_test.go +++ b/operators/constellation-node-operator/internal/etcd/etcd_test.go @@ -11,6 +11,7 @@ import ( "errors" "testing" + "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/internal/constants" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" pb "go.etcd.io/etcd/api/v3/etcdserverpb" @@ -124,7 +125,7 @@ func TestGetInitialEndpoints(t *testing.T) { nodes: []corev1.Node{ { ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{"node-role.kubernetes.io/control-plane": ""}, + Labels: map[string]string{constants.ControlPlaneRoleLabel: ""}, }, Status: corev1.NodeStatus{Addresses: []corev1.NodeAddress{{ Type: corev1.NodeInternalIP, diff --git a/operators/constellation-node-operator/internal/node/BUILD.bazel b/operators/constellation-node-operator/internal/node/BUILD.bazel index 3726946ac1c..080257817c5 100644 --- a/operators/constellation-node-operator/internal/node/BUILD.bazel +++ b/operators/constellation-node-operator/internal/node/BUILD.bazel @@ -8,6 +8,7 @@ go_library( visibility = ["//operators/constellation-node-operator:__subpackages__"], deps = [ "//operators/constellation-node-operator/api/v1alpha1", + "//operators/constellation-node-operator/internal/constants", "@io_k8s_api//core/v1:core", ], ) @@ -18,6 +19,7 @@ go_test( embed = [":node"], deps = [ "//operators/constellation-node-operator/api/v1alpha1", + "//operators/constellation-node-operator/internal/constants", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@io_k8s_api//core/v1:core", diff --git a/operators/constellation-node-operator/internal/node/node.go b/operators/constellation-node-operator/internal/node/node.go index 854b49906f0..ecfcb61587e 100644 --- a/operators/constellation-node-operator/internal/node/node.go +++ b/operators/constellation-node-operator/internal/node/node.go @@ -11,11 +11,10 @@ import ( "regexp" updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/api/v1alpha1" + "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/internal/constants" corev1 "k8s.io/api/core/v1" ) -const controlPlaneRoleLabel = "node-role.kubernetes.io/control-plane" - var reservedHostRegex = regexp.MustCompile(`^(.+\.|)(kubernetes|k8s)\.io(/.*)?$`) // Ready checks if a kubernetes node has the `NodeReady` condition set to true. @@ -40,7 +39,7 @@ func VPCIP(node *corev1.Node) (string, error) { // IsControlPlaneNode returns true if the node is a control plane node. func IsControlPlaneNode(node *corev1.Node) bool { - _, ok := node.Labels[controlPlaneRoleLabel] + _, ok := node.Labels[constants.ControlPlaneRoleLabel] return ok } diff --git a/operators/constellation-node-operator/internal/node/node_test.go b/operators/constellation-node-operator/internal/node/node_test.go index 8a11a19aa8e..34b706b5e37 100644 --- a/operators/constellation-node-operator/internal/node/node_test.go +++ b/operators/constellation-node-operator/internal/node/node_test.go @@ -10,6 +10,7 @@ import ( "testing" updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/api/v1alpha1" + "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/internal/constants" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -69,7 +70,7 @@ func TestIsControlPlaneNode(t *testing.T) { "node with control-plane role label": { node: corev1.Node{ ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{controlPlaneRoleLabel: ""}, + Labels: map[string]string{constants.ControlPlaneRoleLabel: ""}, }, }, wantControlPlane: true,