@@ -161,56 +161,73 @@ func withCABundle(caBundle string) kubeCloudConfigOption {
161
161
}
162
162
}
163
163
164
- func TestReconcileSimpleContentAccessSecret (t * testing.T ) {
164
+ func TestMachineOSBuilderSecretReconciliation (t * testing.T ) {
165
165
masterPool := helpers .NewMachineConfigPool ("master" , nil , helpers .MasterSelector , "v0" )
166
166
workerPool := helpers .NewMachineConfigPool ("worker" , nil , helpers .MasterSelector , "v0" )
167
167
infraPool := helpers .NewMachineConfigPool ("infra" , nil , helpers .MasterSelector , "v0" )
168
168
entitlementSecret := helpers .NewOpaqueSecret (ctrlcommon .SimpleContentAccessSecretName , ctrlcommon .OpenshiftConfigManagedNamespace , "abc" )
169
169
workerEntitlementSecret := helpers .NewOpaqueSecretWithOwnerPool (ctrlcommon .SimpleContentAccessSecretName + "-" + workerPool .Name , ctrlcommon .MCONamespace , "abc" , * workerPool )
170
170
infraEntitlementSecret := helpers .NewOpaqueSecretWithOwnerPool (ctrlcommon .SimpleContentAccessSecretName + "-" + infraPool .Name , ctrlcommon .MCONamespace , "abc" , * infraPool )
171
171
outOfDateInfraEntitlementSecret := helpers .NewOpaqueSecretWithOwnerPool (ctrlcommon .SimpleContentAccessSecretName + "-" + infraPool .Name , ctrlcommon .MCONamespace , "123" , * infraPool )
172
+ globalPullSecret := helpers .NewDockerCfgJSONSecret (ctrlcommon .GlobalPullSecretName , ctrlcommon .OpenshiftConfigNamespace , "abc" )
173
+ outOfDateGlobalPullSecretCopy := helpers .NewDockerCfgJSONSecret (ctrlcommon .GlobalPullSecretCopyName , ctrlcommon .MCONamespace , "123" )
174
+ globalPullSecretCopy := helpers .NewDockerCfgJSONSecret (ctrlcommon .GlobalPullSecretCopyName , ctrlcommon .MCONamespace , "abc" )
172
175
173
176
cases := []struct {
174
177
name string
175
178
mcoSecrets []* corev1.Secret
179
+ ocSecrets []* corev1.Secret
176
180
ocManagedSecrets []* corev1.Secret
177
181
expectedMCOSecrets []corev1.Secret
178
182
layeredMCPs []* mcfgv1.MachineConfigPool
179
183
}{
180
184
{
181
185
name : "no entitlement secret on cluster, with opted-in pool" ,
186
+ ocSecrets : []* corev1.Secret {globalPullSecret .DeepCopy ()},
182
187
ocManagedSecrets : []* corev1.Secret {},
183
188
mcoSecrets : []* corev1.Secret {},
184
- expectedMCOSecrets : []corev1.Secret {},
185
189
layeredMCPs : []* mcfgv1.MachineConfigPool {infraPool .DeepCopy ()},
190
+ expectedMCOSecrets : []corev1.Secret {* globalPullSecretCopy .DeepCopy ()},
186
191
},
187
192
{
188
193
name : "entitlement secret on cluster, with opted-in pool" ,
194
+ ocSecrets : []* corev1.Secret {globalPullSecret .DeepCopy ()},
189
195
ocManagedSecrets : []* corev1.Secret {entitlementSecret .DeepCopy ()},
190
196
mcoSecrets : []* corev1.Secret {},
191
197
layeredMCPs : []* mcfgv1.MachineConfigPool {infraPool .DeepCopy ()},
192
- expectedMCOSecrets : []corev1.Secret {* infraEntitlementSecret .DeepCopy ()},
198
+ expectedMCOSecrets : []corev1.Secret {* infraEntitlementSecret .DeepCopy (), * globalPullSecretCopy . DeepCopy () },
193
199
},
194
200
{
195
201
name : "entitlement secret on cluster, with multiple opted-in pools" ,
202
+ ocSecrets : []* corev1.Secret {globalPullSecret .DeepCopy ()},
196
203
ocManagedSecrets : []* corev1.Secret {entitlementSecret .DeepCopy ()},
197
204
mcoSecrets : []* corev1.Secret {},
198
205
layeredMCPs : []* mcfgv1.MachineConfigPool {workerPool .DeepCopy (), infraPool .DeepCopy ()},
199
- expectedMCOSecrets : []corev1.Secret {* workerEntitlementSecret .DeepCopy (), * infraEntitlementSecret .DeepCopy ()},
206
+ expectedMCOSecrets : []corev1.Secret {* workerEntitlementSecret .DeepCopy (), * infraEntitlementSecret .DeepCopy (), * globalPullSecretCopy . DeepCopy () },
200
207
},
201
208
{
202
- name : "entitlement and cloned secret on cluster, with no opted-in pools" ,
209
+ name : "entitlement, cloned secret and global pull secret copy on cluster, with no opted-in pools" ,
210
+ ocSecrets : []* corev1.Secret {globalPullSecret .DeepCopy ()},
203
211
ocManagedSecrets : []* corev1.Secret {entitlementSecret .DeepCopy ()},
204
- mcoSecrets : []* corev1.Secret {infraEntitlementSecret .DeepCopy ()},
212
+ mcoSecrets : []* corev1.Secret {infraEntitlementSecret .DeepCopy (), globalPullSecretCopy . DeepCopy () },
205
213
layeredMCPs : []* mcfgv1.MachineConfigPool {},
206
214
expectedMCOSecrets : []corev1.Secret {},
207
215
},
208
216
{
209
217
name : "entitlement and cloned secret on cluster, with an outdated cloned secret" ,
218
+ ocSecrets : []* corev1.Secret {globalPullSecret .DeepCopy ()},
210
219
ocManagedSecrets : []* corev1.Secret {entitlementSecret .DeepCopy ()},
211
220
mcoSecrets : []* corev1.Secret {outOfDateInfraEntitlementSecret .DeepCopy ()},
212
221
layeredMCPs : []* mcfgv1.MachineConfigPool {infraPool .DeepCopy ()},
213
- expectedMCOSecrets : []corev1.Secret {* infraEntitlementSecret .DeepCopy ()},
222
+ expectedMCOSecrets : []corev1.Secret {* infraEntitlementSecret .DeepCopy (), * globalPullSecretCopy .DeepCopy ()},
223
+ },
224
+ {
225
+ name : "outdated global pull secret copy on cluster" ,
226
+ ocSecrets : []* corev1.Secret {globalPullSecret .DeepCopy ()},
227
+ ocManagedSecrets : []* corev1.Secret {},
228
+ mcoSecrets : []* corev1.Secret {outOfDateGlobalPullSecretCopy .DeepCopy ()},
229
+ layeredMCPs : []* mcfgv1.MachineConfigPool {infraPool .DeepCopy ()},
230
+ expectedMCOSecrets : []corev1.Secret {* globalPullSecretCopy .DeepCopy ()},
214
231
},
215
232
}
216
233
for _ , tc := range cases {
@@ -222,6 +239,7 @@ func TestReconcileSimpleContentAccessSecret(t *testing.T) {
222
239
sharedInformerFactory := informers .NewSharedInformerFactory (kubeClient , 0 )
223
240
mcoSecretInformer := sharedInformerFactory .Core ().V1 ().Secrets ()
224
241
ocManagedSecretInformer := sharedInformerFactory .Core ().V1 ().Secrets ()
242
+ ocSecretInformer := sharedInformerFactory .Core ().V1 ().Secrets ()
225
243
226
244
// Add secrets to informer and client
227
245
for _ , secret := range tc .mcoSecrets {
@@ -234,6 +252,11 @@ func TestReconcileSimpleContentAccessSecret(t *testing.T) {
234
252
_ , err := kubeClient .CoreV1 ().Secrets (ctrlcommon .OpenshiftConfigManagedNamespace ).Create (context .TODO (), secret , metav1.CreateOptions {})
235
253
assert .NoError (t , err )
236
254
}
255
+ for _ , secret := range tc .ocSecrets {
256
+ ocSecretInformer .Informer ().GetIndexer ().Add (secret )
257
+ _ , err := kubeClient .CoreV1 ().Secrets (ctrlcommon .OpenshiftConfigNamespace ).Create (context .TODO (), secret , metav1.CreateOptions {})
258
+ assert .NoError (t , err )
259
+ }
237
260
238
261
// Create MCO specific clients
239
262
mcfgClient := fakeclientmachineconfigv1 .NewSimpleClientset ()
@@ -250,11 +273,15 @@ func TestReconcileSimpleContentAccessSecret(t *testing.T) {
250
273
kubeClient : kubeClient ,
251
274
mcpLister : mcpInformer .Lister (),
252
275
mcoSecretLister : mcoSecretInformer .Lister (),
276
+ ocSecretLister : ocSecretInformer .Lister (),
253
277
ocManagedSecretLister : ocManagedSecretInformer .Lister (),
254
278
}
255
279
err := optr .reconcileSimpleContentAccessSecrets (tc .layeredMCPs )
256
280
assert .NoError (t , err )
257
281
282
+ err = optr .reconcileGlobalPullSecretCopy (tc .layeredMCPs )
283
+ assert .NoError (t , err )
284
+
258
285
// Verify secrets in MCO namespace are as expected
259
286
secrets , err := kubeClient .CoreV1 ().Secrets (ctrlcommon .MCONamespace ).List (context .TODO (), metav1.ListOptions {})
260
287
assert .NoError (t , err )
0 commit comments