From 78a83dfa1e32f4312233fc895abbd4de7ed96a7f Mon Sep 17 00:00:00 2001 From: Alex Masi Date: Tue, 28 May 2024 18:23:29 +0000 Subject: [PATCH 1/3] Add handling for cri-docker --- deploy/deploy.go | 10 ++++++++++ deploy/deploy_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/deploy/deploy.go b/deploy/deploy.go index fc14cca5..c34a8fa8 100644 --- a/deploy/deploy.go +++ b/deploy/deploy.go @@ -46,6 +46,7 @@ var ( pullRetryDelay = time.Second poolRetryDelay = 5 * time.Second healthTimeout = time.Minute + criDocker = "cri-docker" // Stubs for testing. execLookPath = exec.LookPath @@ -445,6 +446,15 @@ 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) diff --git a/deploy/deploy_test.go b/deploy/deploy_test.go index ab5d5e77..fcb58e16 100644 --- a/deploy/deploy_test.go +++ b/deploy/deploy_test.go @@ -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{ From cdda7adb90b1ffdc830343d9d4f38d9e9e816db0 Mon Sep 17 00:00:00 2001 From: Alex Masi Date: Tue, 28 May 2024 18:29:08 +0000 Subject: [PATCH 2/3] add better logging for failures with kubeadm init --- deploy/deploy.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/deploy/deploy.go b/deploy/deploy.go index c34a8fa8..a85d1e50 100644 --- a/deploy/deploy.go +++ b/deploy/deploy.go @@ -462,9 +462,19 @@ func (k *KubeadmSpec) Deploy(ctx context.Context) error { 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 kind these are lines + // prefixed with "ERROR" or "Command Output". + for _, line := range strings.Split(string(out), "\n") { + if strings.HasPrefix(line, "ERROR") || strings.HasPrefix(line, "Command Output") { + 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 From db85d87e8b187f3df6861e58d804fa73c107612e Mon Sep 17 00:00:00 2001 From: Alex Masi Date: Tue, 28 May 2024 18:33:00 +0000 Subject: [PATCH 3/3] fix comment --- deploy/deploy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy/deploy.go b/deploy/deploy.go index a85d1e50..342a3760 100644 --- a/deploy/deploy.go +++ b/deploy/deploy.go @@ -465,10 +465,10 @@ func (k *KubeadmSpec) Deploy(ctx context.Context) error { 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 kind these are lines - // prefixed with "ERROR" or "Command Output". + // 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.HasPrefix(line, "ERROR") || strings.HasPrefix(line, "Command Output") { + if strings.Contains(strings.ToLower(line), "error") { msg = append(msg, line) } }