Skip to content

Commit

Permalink
Merge pull request #15 from annismckenzie/already-applied-labels-not-…
Browse files Browse the repository at this point in the history
…skipping-node-updates

Already applied labels not skipping node updates
  • Loading branch information
annismckenzie authored Jan 9, 2021
2 parents 956090e + 227896c commit e98d615
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: ci
name: build-push-image

on: push
on:
workflow_dispatch:

jobs:
build-push-image:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ dev-delete: tools
@ $(SKAFFOLD) delete -p dev

deploy: manifests tools
$(SKAFFOLD) run -p production
$(SKAFFOLD) run -p release

# This is used to update the manifests into deploy/operator.yaml
render-production-manifests:
@ $(SKAFFOLD) build -q -p production
@ $(KUSTOMIZE) build config/production > deploy/operator.yaml
render-static-manifests:
@ $(SKAFFOLD) build -q -p release
@ $(KUSTOMIZE) build config/release > deploy/operator.yaml

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ That Kubernetes operator doesn't exist. At least, it didn't until now. 🤠
## Installation

```sh
kubectl apply -f https://github.com/annismckenzie/k3os-config-operator/v0.1.1/deploy/operator.yaml
kubectl apply -f https://github.com/annismckenzie/k3os-config-operator/v0.1.2/deploy/operator.yaml
```


## Releasing

1. Tag locally with `vx.y.z`. Make sure the working directory is clean.
2. Run `make render-production-manifests`. This will build and push the new multi-arch image.
2. Run `make render-static-manifests`. This will build and push the new multi-arch image.
3. Update the installation path above with the new tag.
4. Commit the updated `deploy/operator.yaml` and the update to the README.
5. Delete the local tag, tag again, then push using `git push origin --tags`.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
bases:
- ../default

images:
- name: ghcr.io/annismckenzie/k3os-config-operator
newTag: v0.1.1
newTag: v0.1.2
2 changes: 1 addition & 1 deletion deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: ghcr.io/annismckenzie/k3os-config-operator:v0.1.1
image: ghcr.io/annismckenzie/k3os-config-operator:v0.1.2
name: manager
resources:
limits:
Expand Down
14 changes: 8 additions & 6 deletions pkg/nodes/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ func (l *labeler) Reconcile(node *corev1.Node, configNodeLabels map[string]strin
}
}

if len(configNodeLabels) > 0 {
update = true
for labelKey, labelValue := range configNodeLabels {
addedLabelsMap[labelKey] = struct{}{}
nodeLabels[labelKey] = labelValue
l.updatedLabels[labelKey] = labelValue
for labelKey, labelValue := range configNodeLabels {
if _, ok := addedLabelsMap[labelKey]; ok && labelValue == nodeLabels[labelKey] { // label already exists and hasn't been changed, skip
continue
}

update = true
addedLabelsMap[labelKey] = struct{}{}
nodeLabels[labelKey] = labelValue
l.updatedLabels[labelKey] = labelValue
}

if update {
Expand Down
18 changes: 18 additions & 0 deletions pkg/nodes/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ func Test_labeler_Reconcile(t *testing.T) {
},
expectedAddedLabelsAnnotation: "someNewLabel",
},
{
name: "Node has existing labels, we added some labels, without any further changes it should skip updates",
args: args{
node: labeledNode(map[string]string{"addedLabel": "value"}),
configNodeLabels: map[string]string{
"addedLabel": "value",
},
},
expectedLabels: map[string]string{
"k3s.io/hostname": "n2-node",
"kubernetes.io/arch": "arm64",
"node.kubernetes.io/instance-type": "k3s",
"someExistingLabel": "existingValue",
"addedLabel": "value",
},
wantErr: errors.ErrSkipUpdate,
expectedAddedLabelsAnnotation: "addedLabel",
},
{
name: "Node has existing labels and we add and update some labels",
args: args{
Expand Down
18 changes: 9 additions & 9 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ metadata:
build:
local:
push: false
artifacts:
- image: ghcr.io/annismckenzie/k3os-config-operator
custom:
buildCommand: make docker-build
deploy:
kustomize:
paths:
- config/default
profiles:
- name: production
- name: release
build:
artifacts:
- image: ghcr.io/annismckenzie/k3os-config-operator
custom:
buildCommand: make docker-build
tagPolicy:
gitCommit: {}
local:
push: true
deploy:
kustomize:
paths:
- config/default
- name: dev
build:
tagPolicy:
Expand Down

0 comments on commit e98d615

Please sign in to comment.