Skip to content

Commit

Permalink
Add handling for cri-docker (#540)
Browse files Browse the repository at this point in the history
* Add handling for cri-docker

* add better logging for failures with kubeadm init

* fix comment
  • Loading branch information
alexmasi authored May 28, 2024
1 parent 0e17b04 commit cdcf059
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
24 changes: 22 additions & 2 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
pullRetryDelay = time.Second
poolRetryDelay = 5 * time.Second
healthTimeout = time.Minute
criDocker = "cri-docker"

// Stubs for testing.
execLookPath = exec.LookPath
Expand Down Expand Up @@ -445,16 +446,35 @@ func (k *KubeadmSpec) Deploy(ctx context.Context) error {
args := []string{"kubeadm", "init"}
if k.CRISocket != "" {
args = append(args, "--cri-socket", k.CRISocket)
// If using cri-docker, then ensure the components are running.
if strings.Contains(k.CRISocket, criDocker) {
if err := run.LogCommand("sudo", "systemctl", "enable", "--now", criDocker+".socket"); err != nil {
return err
}
if err := run.LogCommand("sudo", "systemctl", "enable", "--now", criDocker+".service"); err != nil {
return err
}
}
}
if k.PodNetworkCIDR != "" {
args = append(args, "--pod-network-cidr", k.PodNetworkCIDR)
}
if k.TokenTTL != "" {
args = append(args, "--token-ttl", k.TokenTTL)
}
if err := run.LogCommand("sudo", args...); err != nil {
return err
log.Infof("Creating kubeadm cluster with: %v", args)
if out, err := run.OutLogCommand("sudo", args...); err != nil {
msg := []string{}
// Filter output to only show lines relevant to the error message. For kubeadm these are lines
// containing "error" in any case.
for _, line := range strings.Split(string(out), "\n") {
if strings.Contains(strings.ToLower(line), "error") {
msg = append(msg, line)
}
}
return fmt.Errorf("%w: %v", err, strings.Join(msg, ", "))
}
log.Infof("Deployed kubeadm cluster")
kubeDir := filepath.Join(homeDir(), ".kube")
if err := os.MkdirAll(kubeDir, 0750); err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ func TestKubeadmSpec(t *testing.T) {
{Cmd: "sudo", Args: []string{"cat", "/etc/kubernetes/admin.conf"}},
{Cmd: "docker", Args: []string{"network", "create", "kne-kubeadm-.*"}},
},
}, {
desc: "use cri-docker",
k: &KubeadmSpec{
CRISocket: "unix:///var/run/cri-dockerd.sock",
},
resp: []fexec.Response{
{Cmd: "sudo", Args: []string{"systemctl", "enable", "--now", "cri-docker.socket"}},
{Cmd: "sudo", Args: []string{"systemctl", "enable", "--now", "cri-docker.service"}},
{Cmd: "sudo", Args: []string{"kubeadm", "init", "--cri-socket", "unix:///var/run/cri-dockerd.sock"}},
{Cmd: "sudo", Args: []string{"cat", "/etc/kubernetes/admin.conf"}},
{Cmd: "docker", Args: []string{"network", "create", "kne-kubeadm-.*"}},
},
}, {
desc: "allow control plane scheduling",
k: &KubeadmSpec{
Expand Down

0 comments on commit cdcf059

Please sign in to comment.