8
8
"errors"
9
9
"fmt"
10
10
11
- corev1 "k8s.io/api/core/v1"
12
11
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
13
12
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14
13
"k8s.io/apimachinery/pkg/runtime"
@@ -26,8 +25,6 @@ import (
26
25
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
27
26
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
28
27
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client"
29
- "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/imageregistries"
30
- "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/mirrors"
31
28
handlersutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/utils"
32
29
)
33
30
@@ -46,7 +43,7 @@ func NewPatch(
46
43
return newImageRegistriesPatchHandler (
47
44
cl ,
48
45
v1alpha1 .ClusterConfigVariableName ,
49
- imageregistries . VariableName ,
46
+ v1alpha1 . ImageRegistriesVariableName ,
50
47
)
51
48
}
52
49
@@ -87,12 +84,12 @@ func (h *imageRegistriesPatchHandler) Mutate(
87
84
globalMirror , globalMirrorErr := variables .Get [v1alpha1.GlobalImageRegistryMirror ](
88
85
vars ,
89
86
h .variableName ,
90
- mirrors .GlobalMirrorVariableName ,
87
+ v1alpha1 .GlobalMirrorVariableName ,
91
88
)
92
89
93
90
switch {
94
91
case variables .IsNotFoundError (imageRegistriesErr ) && variables .IsNotFoundError (globalMirrorErr ):
95
- log .V (5 ).Info ("Image Registry Credentials variable not defined" )
92
+ log .V (5 ).Info ("Image Registry Credentials and Global Registry Mirror variable not defined" )
96
93
return nil
97
94
case imageRegistriesErr != nil && ! variables .IsNotFoundError (imageRegistriesErr ):
98
95
return imageRegistriesErr
@@ -287,7 +284,7 @@ func ensureOwnerReferenceOnCredentialsSecrets(
287
284
}
288
285
289
286
for _ , credential := range credentials {
290
- if secretName := secretNameForImageRegistryCredentials (credential ); secretName != "" {
287
+ if secretName := handlersutils . SecretNameForImageRegistryCredentials (credential ); secretName != "" {
291
288
// Ensure the Secret is owned by the Cluster so it is correctly moved and deleted with the Cluster.
292
289
// This code assumes that Secret exists and that was validated before calling this function.
293
290
err := handlersutils .EnsureOwnerReferenceForSecret (
@@ -317,7 +314,7 @@ func registryWithOptionalCredentialsFromImageRegistryCredentials(
317
314
registryWithOptionalCredentials := providerConfig {
318
315
URL : imageRegistry .URL ,
319
316
}
320
- secret , err := secretForImageRegistryCredentials (
317
+ secret , err := handlersutils . SecretForImageRegistryCredentials (
321
318
ctx ,
322
319
c ,
323
320
imageRegistry .Credentials ,
@@ -350,7 +347,7 @@ func mirrorConfigFromGlobalImageRegistryMirror(
350
347
URL : mirror .URL ,
351
348
Mirror : true ,
352
349
}
353
- secret , err := secretForImageRegistryCredentials (
350
+ secret , err := handlersutils . SecretForImageRegistryCredentials (
354
351
ctx ,
355
352
c ,
356
353
mirror .Credentials ,
@@ -438,28 +435,6 @@ func createSecretIfNeeded(
438
435
return nil
439
436
}
440
437
441
- // secretForImageRegistryCredentials returns the Secret for the given ImageRegistryCredentials.
442
- // Returns nil if the secret field is empty.
443
- func secretForImageRegistryCredentials (
444
- ctx context.Context ,
445
- c ctrlclient.Reader ,
446
- credentials * v1alpha1.RegistryCredentials ,
447
- objectNamespace string ,
448
- ) (* corev1.Secret , error ) {
449
- name := secretNameForImageRegistryCredentials (credentials )
450
- if name == "" {
451
- return nil , nil
452
- }
453
-
454
- key := ctrlclient.ObjectKey {
455
- Name : name ,
456
- Namespace : objectNamespace ,
457
- }
458
- secret := & corev1.Secret {}
459
- err := c .Get (ctx , key , secret )
460
- return secret , err
461
- }
462
-
463
438
// This handler reads input from two user provided variables: globalImageRegistryMirror and imageRegistries.
464
439
// We expect if imageRegistries is set it will either have static credentials
465
440
// or be for a registry where the credential plugin returns the credentials, ie ECR, GCR, ACR, etc,
@@ -491,12 +466,3 @@ func needImageRegistryCredentialsConfiguration(configs []providerConfig) (bool,
491
466
492
467
return true , nil
493
468
}
494
-
495
- // secretForImageRegistryCredentials returns the name of the Secret for the given RegistryCredentials.
496
- // Returns an empty string if the credentials or secret field is empty.
497
- func secretNameForImageRegistryCredentials (credentials * v1alpha1.RegistryCredentials ) string {
498
- if credentials == nil || credentials .SecretRef == nil || credentials .SecretRef .Name == "" {
499
- return ""
500
- }
501
- return credentials .SecretRef .Name
502
- }
0 commit comments