Skip to content

Commit d346aee

Browse files
authored
Merge pull request containerd#9746 from neoaggelos/fix/config-glob
Fix config import relative path glob
2 parents 00fe7a4 + 2566372 commit d346aee

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

cmd/containerd/server/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ func resolveImports(parent string, imports []string) ([]string, error) {
373373
var out []string
374374

375375
for _, path := range imports {
376+
path = filepath.Clean(path)
377+
if !filepath.IsAbs(path) {
378+
path = filepath.Join(filepath.Dir(parent), path)
379+
}
380+
376381
if strings.Contains(path, "*") {
377382
matches, err := filepath.Glob(path)
378383
if err != nil {
@@ -381,11 +386,6 @@ func resolveImports(parent string, imports []string) ([]string, error) {
381386

382387
out = append(out, matches...)
383388
} else {
384-
path = filepath.Clean(path)
385-
if !filepath.IsAbs(path) {
386-
path = filepath.Join(filepath.Dir(parent), path)
387-
}
388-
389389
out = append(out, path)
390390
}
391391
}

cmd/containerd/server/config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ func TestResolveImports(t *testing.T) {
105105
filepath.Join(tempDir, "test.toml"),
106106
filepath.Join(tempDir, "current.toml"),
107107
})
108+
109+
t.Run("GlobRelativePath", func(t *testing.T) {
110+
imports, err := resolveImports(filepath.Join(tempDir, "root.toml"), []string{
111+
"config_*.toml", // Glob files from working dir
112+
})
113+
assert.NoError(t, err)
114+
assert.Equal(t, imports, []string{
115+
filepath.Join(tempDir, "config_1.toml"),
116+
filepath.Join(tempDir, "config_2.toml"),
117+
})
118+
})
108119
}
109120

110121
func TestLoadSingleConfig(t *testing.T) {

0 commit comments

Comments
 (0)