From db90305b87c5b3ca20a85d45b2b729f058501a0a Mon Sep 17 00:00:00 2001 From: Markus Rudy Date: Mon, 3 Feb 2025 18:39:42 +0100 Subject: [PATCH] nodeinstaller: ignore absence of containerd config template Commit ff6bfe1 introduced an os.ReadFile operation for the containerd config template used by k3s, assuming that the template file would always be present. However, a fresh installation of k3s does not come with a template file: https://docs.k3s.io/advanced#configuring-containerd. On a fresh k3s installation, the nodeinstaller will not find the template file, (falsely) assume that there is no config and use an embedded default, which happens to be incompatible with k3s. Going forward, the nodeinstaller will treat an absent template like an empty template. --- nodeinstaller/node-installer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nodeinstaller/node-installer.go b/nodeinstaller/node-installer.go index a39be68e8..5d38edf5b 100644 --- a/nodeinstaller/node-installer.go +++ b/nodeinstaller/node-installer.go @@ -7,8 +7,10 @@ import ( "bytes" "context" "encoding/json" + "errors" "flag" "fmt" + "io/fs" "os" "os/exec" "path/filepath" @@ -275,7 +277,10 @@ func parseExistingContainerdConfig(path string) ([]byte, config.ContainerdConfig // they are overwriting the template file and not the rendered file, we need to return the // template file here. configData, err = os.ReadFile(path) - if err != nil { + if errors.Is(err, fs.ErrNotExist) { + // The template file will be created by us, pretend that it's empty right now. + return []byte{}, cfg, nil + } else if err != nil { return nil, config.ContainerdConfig{}, fmt.Errorf("reading containerd config template %s: %w", path, err) } return configData, cfg, nil