Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/node-installer/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/spinframework/runtime-class-manager/internal/preset"
)

const defaultContainerdConfigLocation = "/etc/containerd/config.toml"

var containerdConfigLocations = map[string]preset.Settings{
// Microk8s
"/var/snap/microk8s/current/args/containerd-template.toml": preset.MicroK8s,
Expand All @@ -34,8 +36,6 @@ var containerdConfigLocations = map[string]preset.Settings{
"/var/lib/rancher/k3s/agent/etc/containerd/config.toml": preset.K3s,
// K0s
"/etc/k0s/containerd.toml": preset.K0s,
// default
"/etc/containerd/config.toml": preset.Default,
}

func DetectDistro(config Config, hostFs afero.Fs) (preset.Settings, error) {
Expand All @@ -50,6 +50,8 @@ func DetectDistro(config Config, hostFs afero.Fs) (preset.Settings, error) {

var errs []error

// Check for distro-specific containerd config locations first.
// We do this because the default config may *also* exist in some scenarios.
for loc, distro := range containerdConfigLocations {
_, err := hostFs.Stat(loc)
if err == nil {
Expand All @@ -59,5 +61,12 @@ func DetectDistro(config Config, hostFs afero.Fs) (preset.Settings, error) {
errs = append(errs, err)
}

// Check the default location last, assuming no distro-specific location has been detected.
_, err := hostFs.Stat(defaultContainerdConfigLocation)
if err == nil {
return preset.Default, nil
}
errs = append(errs, err)

return preset.Settings{}, fmt.Errorf("failed to detect containerd config path: %w", errors.Join(errs...))
}
19 changes: 19 additions & 0 deletions cmd/node-installer/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ func Test_DetectDistro(t *testing.T) {
false,
preset.Default.WithConfigPath("/etc/containerd/not_found.toml"),
},
{
"default_and_distro_specific_exist",
args{
main.Config{
struct {
Name string
ConfigPath string
}{"containerd", ""},
struct {
Path string
AssetPath string
}{"/opt/rcm", "/assets"},
struct{ RootPath string }{""},
},
tests.FixtureFs("../../testdata/node-installer/containerd/default-and-k0s-configs"),
},
false,
preset.K0s,
},
{
"unsupported",
args{
Expand Down
Loading