Skip to content

Commit

Permalink
Merge pull request #2595 from neolit123/1.24-adapt-to-master-label-ta…
Browse files Browse the repository at this point in the history
…int-changes

handle "master" label/taint changes for kubeadm 1.24
  • Loading branch information
k8s-ci-robot authored Jan 20, 2022
2 parents 6944813 + 26de74a commit bf63502
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
6 changes: 6 additions & 0 deletions pkg/build/nodeimage/const_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ spec:
spec:
nodeSelector:
kubernetes.io/os: linux
# TODO: Remove the "master" taint after kubeadm nodes no longer have it.
# This can be done once kind no longer supports kubeadm 1.24.
# https://github.com/kubernetes-sigs/kind/issues/1699
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Equal
effect: NoSchedule
- key: node-role.kubernetes.io/master
operator: Equal
effect: NoSchedule
Expand Down
26 changes: 22 additions & 4 deletions pkg/cluster/internal/create/actions/kubeadminit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
"sigs.k8s.io/kind/pkg/internal/apis/config"
"sigs.k8s.io/kind/pkg/internal/version"
)

// kubeadmInitAction implements action for executing the kubeadm init
Expand Down Expand Up @@ -106,14 +107,31 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
}
}

// if we are only provisioning one node, remove the master taint
// if we are only provisioning one node, remove the control plane taint
// https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#master-isolation
if len(allNodes) == 1 {
// TODO: Once kubeadm 1.23 is no longer supported remove the <1.24 handling.
// TODO: Remove only the "control-plane" taint for kubeadm >= 1.25.
// https://github.com/kubernetes-sigs/kind/issues/1699
rawVersion, err := nodeutils.KubeVersion(node)
if err != nil {
return errors.Wrap(err, "failed to get Kubernetes version from node")
}
kubeVersion, err := version.ParseSemantic(rawVersion)
if err != nil {
return errors.Wrap(err, "could not parse Kubernetes version")
}
taints := []string{"node-role.kubernetes.io/control-plane-", "node-role.kubernetes.io/master-"}
if kubeVersion.LessThan(version.MustParseSemantic("v1.24.0")) {
taints = []string{"node-role.kubernetes.io/master-"}
}
taintArgs := []string{"--kubeconfig=/etc/kubernetes/admin.conf", "taint", "nodes", "--all"}
taintArgs = append(taintArgs, taints...)

if err := node.Command(
"kubectl", "--kubeconfig=/etc/kubernetes/admin.conf",
"taint", "nodes", "--all", "node-role.kubernetes.io/master-",
"kubectl", taintArgs...,
).Run(); err != nil {
return errors.Wrap(err, "failed to remove master taint")
return errors.Wrap(err, "failed to remove control plane taint")
}
}

Expand Down
24 changes: 21 additions & 3 deletions pkg/cluster/internal/create/actions/waitforready/waitforready.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
"sigs.k8s.io/kind/pkg/internal/version"
)

// Action implements an action for waiting for the cluster to be ready
Expand Down Expand Up @@ -66,7 +68,23 @@ func (a *Action) Execute(ctx *actions.ActionContext) error {

// Wait for the nodes to reach Ready status.
startTime := time.Now()
isReady := waitForReady(node, startTime.Add(a.waitTime))

// TODO: Remove the below handling once kubeadm 1.23 is no longer supported.
// https://github.com/kubernetes-sigs/kind/issues/1699
rawVersion, err := nodeutils.KubeVersion(node)
if err != nil {
return errors.Wrap(err, "failed to get Kubernetes version from node")
}
kubeVersion, err := version.ParseSemantic(rawVersion)
if err != nil {
return errors.Wrap(err, "could not parse Kubernetes version")
}
selectorLabel := "node-role.kubernetes.io/control-plane"
if kubeVersion.LessThan(version.MustParseSemantic("v1.24.0")) {
selectorLabel = "node-role.kubernetes.io/master"
}

isReady := waitForReady(node, startTime.Add(a.waitTime), selectorLabel)
if !isReady {
ctx.Status.End(false)
ctx.Logger.V(0).Info(" • WARNING: Timed out waiting for Ready ⚠️")
Expand All @@ -81,14 +99,14 @@ func (a *Action) Execute(ctx *actions.ActionContext) error {

// WaitForReady uses kubectl inside the "node" container to check if the
// control plane nodes are "Ready".
func waitForReady(node nodes.Node, until time.Time) bool {
func waitForReady(node nodes.Node, until time.Time, selectorLabel string) bool {
return tryUntil(until, func() bool {
cmd := node.Command(
"kubectl",
"--kubeconfig=/etc/kubernetes/admin.conf",
"get",
"nodes",
"--selector=node-role.kubernetes.io/master",
"--selector="+selectorLabel,
// When the node reaches status ready, the status field will be set
// to true.
"-o=jsonpath='{.items..status.conditions[-1:].status}'",
Expand Down
15 changes: 10 additions & 5 deletions site/static/examples/ingress/contour/patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
"ingress-ready": "true"
},
"tolerations": [
{
"key": "node-role.kubernetes.io/master",
"operator": "Equal",
"effect": "NoSchedule"
}
{
"key": "node-role.kubernetes.io/control-plane",
"operator": "Equal",
"effect": "NoSchedule"
},
{
"key": "node-role.kubernetes.io/master",
"operator": "Equal",
"effect": "NoSchedule"
}
]
}
}
Expand Down

0 comments on commit bf63502

Please sign in to comment.