Skip to content

Commit 42967c4

Browse files
vdicevoigt
authored andcommitted
fix(detect.go): check default location only after distro-specific
Signed-off-by: Vaughn Dice <[email protected]>
1 parent 53f1864 commit 42967c4

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

cmd/node-installer/detect.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"github.com/spinframework/runtime-class-manager/internal/preset"
2626
)
2727

28+
const defaultContainerdConfigLocation = "/etc/containerd/config.toml"
29+
2830
var containerdConfigLocations = map[string]preset.Settings{
2931
// Microk8s
3032
"/var/snap/microk8s/current/args/containerd-template.toml": preset.MicroK8s,
@@ -34,8 +36,6 @@ var containerdConfigLocations = map[string]preset.Settings{
3436
"/var/lib/rancher/k3s/agent/etc/containerd/config.toml": preset.K3s,
3537
// K0s
3638
"/etc/k0s/containerd.toml": preset.K0s,
37-
// default
38-
"/etc/containerd/config.toml": preset.Default,
3939
}
4040

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

5151
var errs []error
5252

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

64+
// Check the default location last, assuming no distro-specific location has been detected.
65+
_, err := hostFs.Stat(defaultContainerdConfigLocation)
66+
if err == nil {
67+
return preset.Default, nil
68+
}
69+
errs = append(errs, err)
70+
6271
return preset.Settings{}, fmt.Errorf("failed to detect containerd config path: %w", errors.Join(errs...))
6372
}

cmd/node-installer/detect_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ func Test_DetectDistro(t *testing.T) {
7676
false,
7777
preset.Default.WithConfigPath("/etc/containerd/not_found.toml"),
7878
},
79+
{
80+
"default_and_distro_specific_exist",
81+
args{
82+
main.Config{
83+
struct {
84+
Name string
85+
ConfigPath string
86+
}{"containerd", ""},
87+
struct {
88+
Path string
89+
AssetPath string
90+
}{"/opt/kwasm", "/assets"},
91+
struct{ RootPath string }{""},
92+
},
93+
tests.FixtureFs("../../testdata/node-installer/containerd/default-and-k0s-configs"),
94+
},
95+
false,
96+
preset.K0s,
97+
},
7998
{
8099
"unsupported",
81100
args{

testdata/node-installer/containerd/default-and-k0s-configs/etc/containerd/config.toml

Whitespace-only changes.

testdata/node-installer/containerd/default-and-k0s-configs/etc/k0s/containerd.toml

Whitespace-only changes.

0 commit comments

Comments
 (0)