Skip to content

Commit

Permalink
operator: move control plane label to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
3u13r committed Oct 20, 2024
1 parent 49ef340 commit ce2e48c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand All @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions operators/constellation-node-operator/internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ce2e48c

Please sign in to comment.