Skip to content

Commit 2769585

Browse files
dkoshkinsupershal
authored andcommitted
fix: don't generate empty _default containerd mirror file
1 parent b748025 commit 2769585

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

pkg/handlers/generic/mutation/mirrors/containerd_files.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ func generateContainerdDefaultHostsFile(
112112
inputs = append(inputs, input)
113113
}
114114

115+
// No need to generate the file if there are no mirrors.
116+
if len(inputs) == 0 {
117+
return nil, nil
118+
}
119+
115120
var b bytes.Buffer
116121
err := containerdDefaultHostsConfigurationTemplate.Execute(&b, inputs)
117122
if err != nil {

pkg/handlers/generic/mutation/mirrors/containerd_files_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,8 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
134134
CACert: "myregistrycert",
135135
},
136136
},
137-
want: &cabpkv1.File{
138-
Path: "/etc/containerd/certs.d/_default/hosts.toml",
139-
Owner: "",
140-
Permissions: "0600",
141-
Encoding: "",
142-
Append: false,
143-
Content: `
144-
`,
145-
},
137+
want: nil,
138+
146139
wantErr: nil,
147140
},
148141
}

pkg/handlers/generic/mutation/mirrors/inject_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ var _ = Describe("Generate Global mirror patches", func() {
162162
Operation: "add",
163163
Path: "/spec/template/spec/kubeadmConfigSpec/files",
164164
ValueMatcher: gomega.HaveExactElements(
165-
gomega.HaveKeyWithValue(
166-
"path", "/etc/containerd/certs.d/_default/hosts.toml",
167-
),
168165
gomega.HaveKeyWithValue(
169166
"path", "/etc/containerd/certs.d/registry.example.com/ca.crt",
170167
),
@@ -323,9 +320,6 @@ var _ = Describe("Generate Global mirror patches", func() {
323320
Operation: "add",
324321
Path: "/spec/template/spec/files",
325322
ValueMatcher: gomega.HaveExactElements(
326-
gomega.HaveKeyWithValue(
327-
"path", "/etc/containerd/certs.d/_default/hosts.toml",
328-
),
329323
gomega.HaveKeyWithValue(
330324
"path", "/etc/containerd/certs.d/registry.example.com:5050/ca.crt",
331325
),

0 commit comments

Comments
 (0)