@@ -24,10 +24,6 @@ import (
24
24
const (
25
25
validMirrorCASecretName = "myregistry-mirror-cacert"
26
26
validMirrorNoCASecretName = "myregistry-mirror-no-cacert"
27
- //nolint:gosec // Does not contain hard coded credentials.
28
- cpRegistryAsMirrorCreds = "kubeadmControlPlaneRegistryAsMirrorCreds"
29
- //nolint:gosec // Does not contain hard coded credentials.
30
- workerRegistryAsMirrorCreds = "kubeadmConfigTemplateRegistryAsMirrorCreds"
31
27
)
32
28
33
29
func TestMirrorsPatch (t * testing.T ) {
@@ -93,7 +89,7 @@ var _ = Describe("Generate Global mirror patches", func() {
93
89
v1alpha1 .GlobalMirrorVariableName ,
94
90
),
95
91
},
96
- RequestItem : request .NewKubeadmControlPlaneTemplateRequest ("" , cpRegistryAsMirrorCreds ),
92
+ RequestItem : request .NewKubeadmControlPlaneTemplateRequestItem ("" ),
97
93
ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
98
94
{
99
95
Operation : "add" ,
@@ -128,7 +124,7 @@ var _ = Describe("Generate Global mirror patches", func() {
128
124
v1alpha1 .GlobalMirrorVariableName ,
129
125
),
130
126
},
131
- RequestItem : request .NewKubeadmControlPlaneTemplateRequest ("" , cpRegistryAsMirrorCreds ),
127
+ RequestItem : request .NewKubeadmControlPlaneTemplateRequestItem ("" ),
132
128
ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
133
129
{
134
130
Operation : "add" ,
@@ -145,7 +141,42 @@ var _ = Describe("Generate Global mirror patches", func() {
145
141
},
146
142
},
147
143
{
148
- Name : "files added in KubeadmConfigTemplate for registry mirror wihthout CA certificate secret" ,
144
+ Name : "files added in KubeadmControlPlaneTemplate for image registry with CA Certificate secret" ,
145
+ Vars : []runtimehooksv1.Variable {
146
+ capitest .VariableWithValue (
147
+ v1alpha1 .ClusterConfigVariableName ,
148
+ []v1alpha1.ImageRegistry {{
149
+ URL : "https://registry.example.com" ,
150
+ Credentials : & v1alpha1.RegistryCredentials {
151
+ SecretRef : & v1alpha1.LocalObjectReference {
152
+ Name : validMirrorCASecretName ,
153
+ },
154
+ },
155
+ }},
156
+ v1alpha1 .ImageRegistriesVariableName ,
157
+ ),
158
+ },
159
+ RequestItem : request .NewKubeadmControlPlaneTemplateRequestItem ("" ),
160
+ ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
161
+ {
162
+ Operation : "add" ,
163
+ Path : "/spec/template/spec/kubeadmConfigSpec/files" ,
164
+ ValueMatcher : gomega .HaveExactElements (
165
+ gomega .HaveKeyWithValue (
166
+ "path" , "/etc/containerd/certs.d/_default/hosts.toml" ,
167
+ ),
168
+ gomega .HaveKeyWithValue (
169
+ "path" , "/etc/certs/registry.example.com.pem" ,
170
+ ),
171
+ gomega .HaveKeyWithValue (
172
+ "path" , "/etc/caren/containerd/patches/registry-config.toml" ,
173
+ ),
174
+ ),
175
+ },
176
+ },
177
+ },
178
+ {
179
+ Name : "files added in KubeadmConfigTemplate for registry mirror without CA certificate secret" ,
149
180
Vars : []runtimehooksv1.Variable {
150
181
capitest .VariableWithValue (
151
182
v1alpha1 .ClusterConfigVariableName ,
@@ -203,7 +234,7 @@ var _ = Describe("Generate Global mirror patches", func() {
203
234
},
204
235
),
205
236
},
206
- RequestItem : request .NewKubeadmConfigTemplateRequest ("" , workerRegistryAsMirrorCreds ),
237
+ RequestItem : request .NewKubeadmConfigTemplateRequestItem ("" ),
207
238
ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
208
239
{
209
240
Operation : "add" ,
@@ -246,7 +277,47 @@ var _ = Describe("Generate Global mirror patches", func() {
246
277
},
247
278
),
248
279
},
249
- RequestItem : request .NewKubeadmConfigTemplateRequest ("" , workerRegistryAsMirrorCreds ),
280
+ RequestItem : request .NewKubeadmConfigTemplateRequestItem ("" ),
281
+ ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
282
+ {
283
+ Operation : "add" ,
284
+ Path : "/spec/template/spec/files" ,
285
+ ValueMatcher : gomega .HaveExactElements (
286
+ gomega .HaveKeyWithValue (
287
+ "path" , "/etc/containerd/certs.d/_default/hosts.toml" ,
288
+ ),
289
+ gomega .HaveKeyWithValue (
290
+ "path" , "/etc/caren/containerd/patches/registry-config.toml" ,
291
+ ),
292
+ ),
293
+ },
294
+ },
295
+ },
296
+ {
297
+ Name : "files added in KubeadmConfigTemplate for image registry with secret for CA certificate" ,
298
+ Vars : []runtimehooksv1.Variable {
299
+ capitest .VariableWithValue (
300
+ v1alpha1 .ClusterConfigVariableName ,
301
+ []v1alpha1.ImageRegistry {{
302
+ URL : "https://registry.example.com" ,
303
+ Credentials : & v1alpha1.RegistryCredentials {
304
+ SecretRef : & v1alpha1.LocalObjectReference {
305
+ Name : validMirrorCASecretName ,
306
+ },
307
+ },
308
+ }},
309
+ v1alpha1 .ImageRegistriesVariableName ,
310
+ ),
311
+ capitest .VariableWithValue (
312
+ "builtin" ,
313
+ map [string ]any {
314
+ "machineDeployment" : map [string ]any {
315
+ "class" : names .SimpleNameGenerator .GenerateName ("worker-" ),
316
+ },
317
+ },
318
+ ),
319
+ },
320
+ RequestItem : request .NewKubeadmConfigTemplateRequestItem ("" ),
250
321
ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
251
322
{
252
323
Operation : "add" ,
@@ -255,6 +326,9 @@ var _ = Describe("Generate Global mirror patches", func() {
255
326
gomega .HaveKeyWithValue (
256
327
"path" , "/etc/containerd/certs.d/_default/hosts.toml" ,
257
328
),
329
+ gomega .HaveKeyWithValue (
330
+ "path" , "/etc/certs/registry.example.com.pem" ,
331
+ ),
258
332
gomega .HaveKeyWithValue (
259
333
"path" , "/etc/caren/containerd/patches/registry-config.toml" ,
260
334
),
0 commit comments