Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: using predictable label value #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
8 changes: 4 additions & 4 deletions controllers/provisioner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion controllers/provisioner_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down