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

chore: only label nodes with kubernetes.io/role if they need it #4827

Merged
merged 3 commits into from
Feb 11, 2022
Merged
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
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