Skip to content

Commit 55a75df

Browse files
committed
fix: Remove empty containerd _default/hosts.toml
If there is no mirror configuration then this file is unnecessary so do not create it.
1 parent 7bc9094 commit 55a75df

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

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

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

115+
if len(inputs) == 0 {
116+
return nil, nil
117+
}
118+
115119
var b bytes.Buffer
116120
err := containerdDefaultHostsConfigurationTemplate.Execute(&b, inputs)
117121
if err != nil {

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,7 @@ 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,
146138
wantErr: nil,
147139
},
148140
}

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)