From a2e045ed423eec0deefc7766f0f2bc3fce409862 Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Sun, 2 Jun 2024 14:34:13 +0200 Subject: [PATCH] fix: use correct shim path when containerd opt is preconfigured --- cmd/installer/main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/installer/main.go b/cmd/installer/main.go index 8247107..a9270f9 100644 --- a/cmd/installer/main.go +++ b/cmd/installer/main.go @@ -10,6 +10,7 @@ import ( "os/exec" "path" "path/filepath" + "strings" "time" "github.com/containerd/containerd" @@ -254,12 +255,17 @@ func configureContainerd(runtime containerRuntime, containerdConfig string) (res return false, err } - if _, err := cfg.WriteString(fmt.Sprintf(runtimeConfig, *hostOptPath)); err != nil { + configured, containerdOptPath, err := optConfigured(containerdConfig) + if err != nil { return false, err } - configured, err := optConfigured(containerdConfig) - if err != nil { + optPath := *hostOptPath + if configured { + optPath = containerdOptPath + } + + if _, err := cfg.WriteString(fmt.Sprintf(runtimeConfig, strings.TrimSuffix(optPath, "/"))); err != nil { return false, err } @@ -303,18 +309,18 @@ func copyConfig(from, to string) error { return nil } -func optConfigured(containerdConfig string) (bool, error) { +func optConfigured(containerdConfig string) (bool, string, error) { conf := &config.Config{} if err := config.LoadConfig(containerdConfig, conf); err != nil { - return false, err + return false, "", err } if opt, ok := conf.Plugins[containerdOptKey]; ok { if opt.Has("path") { - return true, nil + return true, opt.Get("path").(string), nil } } - return false, nil + return false, "", nil } func installRuntimeClass(ctx context.Context, client kubernetes.Interface) error {