Skip to content

Commit

Permalink
set skipPhases in Init and JoinConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed May 21, 2024
1 parent ead292a commit e0d157b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
34 changes: 24 additions & 10 deletions pkg/cluster/internal/create/actions/kubeadminit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,38 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
return err
}

// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.13+
skipPhases := "preflight"
if a.skipKubeProxy {
skipPhases += ",addon/kube-proxy"
kubeVersionStr, err := nodeutils.KubeVersion(node)
if err != nil {
return errors.Wrap(err, "failed to get kubernetes version from node")
}
kubeVersion, err := version.ParseGeneric(kubeVersionStr)
if err != nil {
return errors.Wrapf(err, "failed to parse kubernetes version %q", kubeVersionStr)
}

// run kubeadm
cmd := node.Command(
args := []string{
// init because this is the control plane node
"kubeadm", "init",
"--skip-phases="+skipPhases,
"init",
// specify our generated config file
"--config=/kind/kubeadm.conf",
"--skip-token-print",
// increase verbosity for debugging
"--v=6",
)
}

// Newer versions set this in the config file.
if kubeVersion.LessThan(version.MustParseSemantic("v1.23.0")) {
// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.13+
skipPhases := "preflight"
if a.skipKubeProxy {
skipPhases += ",addon/kube-proxy"
}
args = append(args, "--skip-phases="+skipPhases)
}

// run kubeadm
cmd := node.Command("kubeadm", args...)
lines, err := exec.CombinedOutputLines(cmd)
ctx.Logger.V(3).Info(strings.Join(lines, "\n"))
if err != nil {
Expand Down
30 changes: 22 additions & 8 deletions pkg/cluster/internal/create/actions/kubeadmjoin/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
"sigs.k8s.io/kind/pkg/internal/version"
"sigs.k8s.io/kind/pkg/log"

"sigs.k8s.io/kind/pkg/cluster/nodeutils"
Expand Down Expand Up @@ -117,18 +118,31 @@ func joinWorkers(

// runKubeadmJoin executes kubeadm join command
func runKubeadmJoin(logger log.Logger, node nodes.Node) error {
// run kubeadm join
// TODO(bentheelder): this should be using the config file
cmd := node.Command(
"kubeadm", "join",
kubeVersionStr, err := nodeutils.KubeVersion(node)
if err != nil {
return errors.Wrap(err, "failed to get kubernetes version from node")
}
kubeVersion, err := version.ParseGeneric(kubeVersionStr)
if err != nil {
return errors.Wrapf(err, "failed to parse kubernetes version %q", kubeVersionStr)
}

args := []string{
"join",
// the join command uses the config file generated in a well known location
"--config", "/kind/kubeadm.conf",
// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.13+
"--skip-phases=preflight",
// increase verbosity for debugging
"--v=6",
)
}
// Newer versions set this in the config file.
if kubeVersion.LessThan(version.MustParseSemantic("v1.23.0")) {
// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.13+
args = append(args, "--skip-phases=preflight")
}

// run kubeadm join
cmd := node.Command("kubeadm", args...)
lines, err := exec.CombinedOutputLines(cmd)
logger.V(3).Info(strings.Join(lines, "\n"))
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions pkg/cluster/internal/kubeadm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ type DerivedConfigData struct {
IPv6 bool
// kubelet cgroup driver, based on kubernetes version
CgroupDriver string
// JoinSkipPhases are the skipPhases values for the JoinConfiguration.
JoinSkipPhases []string
// InitSkipPhases are the skipPhases values for the InitConfiguration.
InitSkipPhases []string
}

type FeatureGate struct {
Expand Down Expand Up @@ -166,6 +170,14 @@ func (c *ConfigData) Derive() {
runtimeConfig = append(runtimeConfig, fmt.Sprintf("%s=%s", k, v))
}
c.RuntimeConfigString = strings.Join(runtimeConfig, ",")

// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.22+
c.JoinSkipPhases = []string{"preflight"}
c.InitSkipPhases = []string{"preflight"}
if c.KubeProxyMode == string(config.NoneProxyMode) {
c.InitSkipPhases = append(c.InitSkipPhases, "addon/kube-proxy")
}
}

// See docs for these APIs at:
Expand Down Expand Up @@ -380,6 +392,12 @@ nodeRegistration:
node-ip: "{{ .NodeAddress }}"
provider-id: "kind://{{.NodeProvider}}/{{.ClusterName}}/{{.NodeName}}"
node-labels: "{{ .NodeLabels }}"
{{ if .InitSkipPhases -}}
skipPhases:
{{ range $phase := .InitSkipPhases -}}
- "{{ $phase }}"
{{- end }}
{{- end }}
---
# no-op entry that exists solely so it can be patched
apiVersion: kubeadm.k8s.io/v1beta3
Expand All @@ -403,6 +421,12 @@ discovery:
apiServerEndpoint: "{{ .ControlPlaneEndpoint }}"
token: "{{ .Token }}"
unsafeSkipCAVerification: true
{{ if .JoinSkipPhases -}}
skipPhases:
{{ range $phase := .JoinSkipPhases -}}
- "{{ $phase }}"
{{- end }}
{{- end }}
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
Expand Down

0 comments on commit e0d157b

Please sign in to comment.