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
5 changes: 5 additions & 0 deletions pkg/handlers/generic/mutation/mirrors/containerd_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func generateContainerdDefaultHostsFile(
inputs = append(inputs, input)
}

// No need to generate the file if there are no mirrors.
if len(inputs) == 0 {
return nil, nil
}

var b bytes.Buffer
err := containerdDefaultHostsConfigurationTemplate.Execute(&b, inputs)
if err != nil {
Expand Down
11 changes: 2 additions & 9 deletions pkg/handlers/generic/mutation/mirrors/containerd_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,8 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
CACert: "myregistrycert",
},
},
want: &cabpkv1.File{
Path: "/etc/containerd/certs.d/_default/hosts.toml",
Owner: "",
Permissions: "0600",
Encoding: "",
Append: false,
Content: `
`,
},
want: nil,

wantErr: nil,
},
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/handlers/generic/mutation/mirrors/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ var _ = Describe("Generate Global mirror patches", func() {
Operation: "add",
Path: "/spec/template/spec/kubeadmConfigSpec/files",
ValueMatcher: gomega.HaveExactElements(
gomega.HaveKeyWithValue(
"path", "/etc/containerd/certs.d/_default/hosts.toml",
),
gomega.HaveKeyWithValue(
"path", "/etc/containerd/certs.d/registry.example.com/ca.crt",
),
Expand Down Expand Up @@ -323,9 +320,6 @@ var _ = Describe("Generate Global mirror patches", func() {
Operation: "add",
Path: "/spec/template/spec/files",
ValueMatcher: gomega.HaveExactElements(
gomega.HaveKeyWithValue(
"path", "/etc/containerd/certs.d/_default/hosts.toml",
),
gomega.HaveKeyWithValue(
"path", "/etc/containerd/certs.d/registry.example.com:5050/ca.crt",
),
Expand Down
Loading