Skip to content

Commit

Permalink
CAPD: only ignore necessary kubeadm preflight errors
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed Jan 4, 2023
1 parent aebde5b commit 3d31c8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ func hackKubeadmIgnoreErrors(c provisioning.Cmd) provisioning.Cmd {
// case kubeadm commands are defined as a string
if c.Cmd == "/bin/sh" && len(c.Args) >= 2 {
if c.Args[0] == "-c" {
c.Args[1] = strings.Replace(c.Args[1], "kubeadm init", "kubeadm init --ignore-preflight-errors=all", 1)
c.Args[1] = strings.Replace(c.Args[1], "kubeadm join", "kubeadm join --ignore-preflight-errors=all", 1)
c.Args[1] = strings.Replace(c.Args[1], "kubeadm init", "kubeadm init --ignore-preflight-errors=SystemVerification,Swap", 1)
c.Args[1] = strings.Replace(c.Args[1], "kubeadm join", "kubeadm join --ignore-preflight-errors=SystemVerification,Swap", 1)
}
}

// case kubeadm commands are defined as a list
if c.Cmd == "kubeadm" && len(c.Args) >= 1 {
if c.Args[0] == "init" || c.Args[0] == "join" {
c.Args = append(c.Args, "") // make space
copy(c.Args[2:], c.Args[1:]) // shift elements
c.Args[1] = "--ignore-preflight-errors=all" // insert the additional arg
c.Args = append(c.Args, "") // make space
copy(c.Args[2:], c.Args[1:]) // shift elements
c.Args[1] = "--ignore-preflight-errors=SystemVerification,Swap" // insert the additional arg
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestRunCmdRun(t *testing.T) {
},
},
expectedCmds: []provisioning.Cmd{
{Cmd: "/bin/sh", Args: []string{"-c", "kubeadm init --ignore-preflight-errors=all --config /run/kubeadm/kubeadm.yaml"}},
{Cmd: "/bin/sh", Args: []string{"-c", "kubeadm init --ignore-preflight-errors=SystemVerification,Swap --config /run/kubeadm/kubeadm.yaml"}},
},
},
}
Expand Down Expand Up @@ -100,11 +100,11 @@ runcmd:

r.Cmds[0] = hackKubeadmIgnoreErrors(r.Cmds[0])

expected0 := provisioning.Cmd{Cmd: "/bin/sh", Args: []string{"-c", "kubeadm init --ignore-preflight-errors=all --config=/run/kubeadm/kubeadm.yaml"}}
expected0 := provisioning.Cmd{Cmd: "/bin/sh", Args: []string{"-c", "kubeadm init --ignore-preflight-errors=SystemVerification,Swap --config=/run/kubeadm/kubeadm.yaml"}}
g.Expect(r.Cmds[0]).To(Equal(expected0))

r.Cmds[1] = hackKubeadmIgnoreErrors(r.Cmds[1])

expected1 := provisioning.Cmd{Cmd: "kubeadm", Args: []string{"join", "--ignore-preflight-errors=all", "--config=/run/kubeadm/kubeadm-controlplane-join-config.yaml"}}
expected1 := provisioning.Cmd{Cmd: "kubeadm", Args: []string{"join", "--ignore-preflight-errors=SystemVerification,Swap", "--config=/run/kubeadm/kubeadm-controlplane-join-config.yaml"}}
g.Expect(r.Cmds[1]).To(Equal(expected1))
}

0 comments on commit 3d31c8c

Please sign in to comment.