Skip to content

Commit

Permalink
fix: specify containerd-base-dir when bootstrapping k8s
Browse files Browse the repository at this point in the history
(cherry picked from commit 63173e9)
  • Loading branch information
jnsgruk committed Jan 28, 2025
1 parent fe48b28 commit 4e65c7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions internal/providers/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,19 @@ func (k *K8s) install() error {
// init ensures that K8s is installed, minimally configured, and ready.
func (k *K8s) init() error {
if k.needsBootstrap() {
cmd := system.NewCommand("k8s", []string{"bootstrap"})
_, err := k.system.RunWithRetries(cmd, (5 * time.Minute))
// Write a K8s bootstrap config file to change the default containerd-base-path,
// avoiding conflicts on machines where containerd is already present. This mostly
// occurs on Github Actions runners.
filepath := path.Join(k.system.User().HomeDir, ".cache", "concierge", "k8s-bootstrap.yaml")
err := k.system.WriteHomeDirFile(filepath, []byte(
"containerd-base-dir: /run/containerd-k8s-snap\n",
))
if err != nil {
return fmt.Errorf("failed to write K8s bootstrap confile file: %w", err)
}

cmd := system.NewCommand("k8s", []string{"bootstrap", "--file", filepath})
_, err = k.system.RunWithRetries(cmd, (5 * time.Minute))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/providers/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestK8sPrepareCommands(t *testing.T) {
expectedCommands := []string{
fmt.Sprintf("snap install k8s --channel %s", defaultK8sChannel),
"snap install kubectl --channel stable",
"k8s bootstrap",
"k8s bootstrap --file /tmp/.cache/concierge/k8s-bootstrap.yaml",
"k8s status --wait-ready",
"k8s set load-balancer.l2-mode=true",
"k8s status",
Expand All @@ -88,6 +88,7 @@ func TestK8sPrepareCommands(t *testing.T) {

expectedFiles := map[string]string{
".kube/config": "",
"/tmp/.cache/concierge/k8s-bootstrap.yaml": "containerd-base-dir: /run/containerd-k8s-snap\n",
}

system := system.NewMockSystem()
Expand Down

0 comments on commit 4e65c7c

Please sign in to comment.