From 99dd7b802a6679d1276f1186ae22659b51485342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Torrentsgener=C3=B3s?= Date: Fri, 24 May 2024 15:52:03 +0200 Subject: [PATCH] chore: using predictable label value --- Makefile | 6 +++--- config/rbac/role.yaml | 1 - controllers/provisioner_controller.go | 8 ++++---- controllers/provisioner_controller_test.go | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 6b9af98..97926da 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ endif # Image URL to use all building/pushing image targets IMG ?= controller:latest # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.24.2 +ENVTEST_K8S_VERSION = 1.29.3 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -175,8 +175,8 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 -CONTROLLER_TOOLS_VERSION ?= v0.9.2 +KUSTOMIZE_VERSION ?= v5.4.2 +CONTROLLER_TOOLS_VERSION ?= v0.14.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 482a7c2..2355979 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - creationTimestamp: null name: manager-role rules: - apiGroups: diff --git a/controllers/provisioner_controller.go b/controllers/provisioner_controller.go index bb6e85d..8c01bc8 100644 --- a/controllers/provisioner_controller.go +++ b/controllers/provisioner_controller.go @@ -44,7 +44,7 @@ type ProvisionerReconciler struct { const ( addKWasmNodeLabelAnnotation = "kwasm.sh/kwasm-node" - nodeNameLabel = "kwasm.sh/kwasm-provisioned" + provisionedLabel = "kwasm.sh/kwasm-provisioned" ) //+kubebuilder:rbac:groups=wasm.kwasm.sh,resources=provisioners,verbs=get;list;watch;create;update;patch;delete @@ -83,7 +83,7 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request) */ labelShouldBePresent := node.Annotations[addKWasmNodeLabelAnnotation] == "true" - labelIsPresent := node.Labels[nodeNameLabel] == node.Name + labelIsPresent := node.Labels[provisionedLabel] == "true" if labelShouldBePresent == labelIsPresent && !r.AutoProvision { // The desired state and actual state of the Node are the same. @@ -96,7 +96,7 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request) if node.Labels == nil { node.Labels = make(map[string]string) } - node.Labels[nodeNameLabel] = node.Name + node.Labels[provisionedLabel] = "true" log.Info().Msgf("Trying to Deploy on %s", node.Name) dep, err := r.deployJob(node, req) @@ -110,7 +110,7 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request) } } else if !r.AutoProvision { // If the label should not be set but is, remove it. - delete(node.Labels, nodeNameLabel) + delete(node.Labels, provisionedLabel) log.Info().Msg("Label removed. Removing Job.") err := r.Delete(ctx, &batchv1.Job{ diff --git a/controllers/provisioner_controller_test.go b/controllers/provisioner_controller_test.go index 4302879..2119f1d 100644 --- a/controllers/provisioner_controller_test.go +++ b/controllers/provisioner_controller_test.go @@ -64,7 +64,7 @@ var _ = Describe("ProvisionerController", func() { // Verify that the Node has the expected label. err = k8sClient.Get(ctx, types.NamespacedName{Name: nodeName}, node) Expect(err).NotTo(HaveOccurred()) - Expect(node.Labels["kwasm.sh/kwasm-provisioned"]).To(Equal(nodeName)) + Expect(node.Labels["kwasm.sh/kwasm-provisioned"]).To(Equal("true")) // Call Reconcile again with the same Request object to ensure that the operator // does not create a duplicate Job.