Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
chore: only label nodes with kubernetes.io/role if they need it (#4827)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis committed Feb 11, 2022
1 parent db2a3b4 commit fe9e4d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
17 changes: 9 additions & 8 deletions parts/k8s/cloud-init/artifacts/label-nodes.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env bash

# Applies missing master and agent labels to Kubernetes nodes.
# This script looks for nodes that don't have the required kubernetes.io/role label,
# and then labels them appropriately
#
# Kubelet 1.16+ rejects the `kubernetes.io/role` and `node-role.kubernetes.io`
# labels in its `--node-labels` argument, but they need to be present for
# backward compatibility.
# Because nodes can't self-label their role in this way,
# we need control plane nodes to do this continually
# to ensure that new nodes get the role labels quickly

set -euo pipefail

KUBECONFIG="$(find /home/*/.kube/config)"
KUBECTL="kubectl --kubeconfig=${KUBECONFIG}"

MASTER_SELECTOR="kubernetes.azure.com/role!=agent,kubernetes.io/role!=agent"
MASTER_LABELS="kubernetes.azure.com/role=master kubernetes.io/role=master node-role.kubernetes.io/master="
AGENT_SELECTOR="kubernetes.azure.com/role!=master,kubernetes.io/role!=master"
AGENT_LABELS="kubernetes.azure.com/role=agent kubernetes.io/role=agent node-role.kubernetes.io/agent="
MASTER_SELECTOR="kubernetes.azure.com/role=master,kubernetes.io/role!=master,node-role.kubernetes.io/master!="
MASTER_LABELS="kubernetes.io/role=master node-role.kubernetes.io/master="
AGENT_SELECTOR="kubernetes.azure.com/role=agent,kubernetes.io/role!=agent,node-role.kubernetes.io/agent!="
AGENT_LABELS="kubernetes.io/role=agent node-role.kubernetes.io/agent="

${KUBECTL} label nodes --overwrite -l $MASTER_SELECTOR $MASTER_LABELS
${KUBECTL} label nodes --overwrite -l $AGENT_SELECTOR $AGENT_LABELS
Expand Down
17 changes: 9 additions & 8 deletions pkg/engine/templates_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/e2e/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,7 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
}
labels := n.Metadata.Labels
Expect(labels).To(HaveKeyWithValue("kubernetes.io/role", role))
Expect(labels).To(HaveKeyWithValue(fmt.Sprintf("node-role.kubernetes.io/%s", role), ""))
Expect(labels).To(HaveKey(fmt.Sprintf("node-role.kubernetes.io/%s", role)))
if role == "master" && common.IsKubernetesVersionGe(
eng.ExpandedDefinition.Properties.OrchestratorProfile.OrchestratorVersion, "1.17.1") {
Expand Down

0 comments on commit fe9e4d4

Please sign in to comment.