@@ -82,132 +82,129 @@ func (h *imageRegistriesPatchHandler) Mutate(
82
82
return nil
83
83
}
84
84
85
- // TODO: Add support for multiple registries.
86
- if len (imageRegistries ) > 1 {
87
- return fmt .Errorf ("multiple Image Registry are not supported at this time. " +
88
- "Provide a single registry entry for %s variable" , imageregistries .VariableName )
89
- }
90
-
91
- imageRegistry := imageRegistries [0 ]
92
-
93
- log = log .WithValues (
94
- "variableName" ,
95
- h .variableName ,
96
- "variableFieldPath" ,
97
- h .variableFieldPath ,
98
- "variableValue" ,
99
- imageRegistry ,
100
- )
85
+ // TODO: Support for multiple registries is constrained with variable schema of ImageRegistries.
86
+ // currently only one registry is supported. Implement support for multiple registries in
87
+ // DynamicCredentialProviderConfig
88
+ for _ , imageRegistry := range imageRegistries {
89
+ log = log .WithValues (
90
+ "variableName" ,
91
+ h .variableName ,
92
+ "variableFieldPath" ,
93
+ h .variableFieldPath ,
94
+ "variableValue" ,
95
+ imageRegistry ,
96
+ )
101
97
102
- if err := patches .MutateIfApplicable (
103
- obj , vars , & holderRef , selectors .ControlPlane (), log ,
104
- func (obj * controlplanev1.KubeadmControlPlaneTemplate ) error {
105
- registryWithOptionalCredentials , generateErr := registryWithOptionalCredentialsFromImageRegistryCredentials (
106
- ctx , h .client , imageRegistry , obj ,
107
- )
108
- if generateErr != nil {
109
- return generateErr
110
- }
111
- files , commands , generateErr := generateFilesAndCommands (
112
- registryWithOptionalCredentials ,
113
- obj .GetName ())
114
- if generateErr != nil {
115
- return generateErr
116
- }
117
-
118
- log .WithValues (
119
- "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
120
- "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
121
- ).Info ("adding files to control plane kubeadm config spec" )
122
- obj .Spec .Template .Spec .KubeadmConfigSpec .Files = append (
123
- obj .Spec .Template .Spec .KubeadmConfigSpec .Files ,
124
- files ... ,
125
- )
126
-
127
- log .WithValues (
128
- "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
129
- "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
130
- ).Info ("adding PreKubeadmCommands to control plane kubeadm config spec" )
131
- obj .Spec .Template .Spec .KubeadmConfigSpec .PreKubeadmCommands = append (
132
- obj .Spec .Template .Spec .KubeadmConfigSpec .PreKubeadmCommands ,
133
- commands ... ,
134
- )
135
-
136
- generateErr = createSecretIfNeeded (ctx , h .client , registryWithOptionalCredentials , obj , clusterKey )
137
- if generateErr != nil {
138
- return generateErr
139
- }
140
-
141
- initConfiguration := obj .Spec .Template .Spec .KubeadmConfigSpec .InitConfiguration
142
- if initConfiguration == nil {
143
- initConfiguration = & bootstrapv1.InitConfiguration {}
144
- }
145
- obj .Spec .Template .Spec .KubeadmConfigSpec .InitConfiguration = initConfiguration
146
- if initConfiguration .NodeRegistration .KubeletExtraArgs == nil {
147
- initConfiguration .NodeRegistration .KubeletExtraArgs = map [string ]string {}
148
- }
149
- addImageCredentialProviderArgs (initConfiguration .NodeRegistration .KubeletExtraArgs )
150
-
151
- joinConfiguration := obj .Spec .Template .Spec .KubeadmConfigSpec .JoinConfiguration
152
- if joinConfiguration == nil {
153
- joinConfiguration = & bootstrapv1.JoinConfiguration {}
154
- }
155
- obj .Spec .Template .Spec .KubeadmConfigSpec .JoinConfiguration = joinConfiguration
156
- if joinConfiguration .NodeRegistration .KubeletExtraArgs == nil {
157
- joinConfiguration .NodeRegistration .KubeletExtraArgs = map [string ]string {}
158
- }
159
- addImageCredentialProviderArgs (joinConfiguration .NodeRegistration .KubeletExtraArgs )
160
- return nil
161
- }); err != nil {
162
- return err
163
- }
98
+ if err := patches .MutateIfApplicable (
99
+ obj , vars , & holderRef , selectors .ControlPlane (), log ,
100
+ func (obj * controlplanev1.KubeadmControlPlaneTemplate ) error {
101
+ registryWithOptionalCredentials , generateErr := registryWithOptionalCredentialsFromImageRegistryCredentials (
102
+ ctx , h .client , imageRegistry , obj ,
103
+ )
104
+ if generateErr != nil {
105
+ return generateErr
106
+ }
107
+ files , commands , generateErr := generateFilesAndCommands (
108
+ registryWithOptionalCredentials ,
109
+ obj .GetName ())
110
+ if generateErr != nil {
111
+ return generateErr
112
+ }
113
+
114
+ log .WithValues (
115
+ "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
116
+ "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
117
+ ).Info ("adding files to control plane kubeadm config spec" )
118
+ obj .Spec .Template .Spec .KubeadmConfigSpec .Files = append (
119
+ obj .Spec .Template .Spec .KubeadmConfigSpec .Files ,
120
+ files ... ,
121
+ )
122
+
123
+ log .WithValues (
124
+ "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
125
+ "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
126
+ ).Info ("adding PreKubeadmCommands to control plane kubeadm config spec" )
127
+ obj .Spec .Template .Spec .KubeadmConfigSpec .PreKubeadmCommands = append (
128
+ obj .Spec .Template .Spec .KubeadmConfigSpec .PreKubeadmCommands ,
129
+ commands ... ,
130
+ )
131
+
132
+ generateErr = createSecretIfNeeded (ctx , h .client , registryWithOptionalCredentials , obj , clusterKey )
133
+ if generateErr != nil {
134
+ return generateErr
135
+ }
136
+
137
+ initConfiguration := obj .Spec .Template .Spec .KubeadmConfigSpec .InitConfiguration
138
+ if initConfiguration == nil {
139
+ initConfiguration = & bootstrapv1.InitConfiguration {}
140
+ }
141
+ obj .Spec .Template .Spec .KubeadmConfigSpec .InitConfiguration = initConfiguration
142
+ if initConfiguration .NodeRegistration .KubeletExtraArgs == nil {
143
+ initConfiguration .NodeRegistration .KubeletExtraArgs = map [string ]string {}
144
+ }
145
+ addImageCredentialProviderArgs (initConfiguration .NodeRegistration .KubeletExtraArgs )
146
+
147
+ joinConfiguration := obj .Spec .Template .Spec .KubeadmConfigSpec .JoinConfiguration
148
+ if joinConfiguration == nil {
149
+ joinConfiguration = & bootstrapv1.JoinConfiguration {}
150
+ }
151
+ obj .Spec .Template .Spec .KubeadmConfigSpec .JoinConfiguration = joinConfiguration
152
+ if joinConfiguration .NodeRegistration .KubeletExtraArgs == nil {
153
+ joinConfiguration .NodeRegistration .KubeletExtraArgs = map [string ]string {}
154
+ }
155
+ addImageCredentialProviderArgs (joinConfiguration .NodeRegistration .KubeletExtraArgs )
156
+ return nil
157
+ }); err != nil {
158
+ return err
159
+ }
164
160
165
- if err := patches .MutateIfApplicable (
166
- obj , vars , & holderRef , selectors .WorkersKubeadmConfigTemplateSelector (), log ,
167
- func (obj * bootstrapv1.KubeadmConfigTemplate ) error {
168
- registryWithOptionalCredentials , generateErr := registryWithOptionalCredentialsFromImageRegistryCredentials (
169
- ctx , h .client , imageRegistry , obj ,
170
- )
171
- if generateErr != nil {
172
- return generateErr
173
- }
174
- files , commands , generateErr := generateFilesAndCommands (
175
- registryWithOptionalCredentials ,
176
- obj .GetName ())
177
- if generateErr != nil {
178
- return generateErr
179
- }
180
-
181
- log .WithValues (
182
- "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
183
- "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
184
- ).Info ("adding files to worker node kubeadm config template" )
185
- obj .Spec .Template .Spec .Files = append (obj .Spec .Template .Spec .Files , files ... )
186
-
187
- log .WithValues (
188
- "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
189
- "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
190
- ).Info ("adding PreKubeadmCommands to worker node kubeadm config template" )
191
- obj .Spec .Template .Spec .PreKubeadmCommands = append (obj .Spec .Template .Spec .PreKubeadmCommands , commands ... )
192
-
193
- generateErr = createSecretIfNeeded (ctx , h .client , registryWithOptionalCredentials , obj , clusterKey )
194
- if generateErr != nil {
195
- return generateErr
196
- }
197
-
198
- joinConfiguration := obj .Spec .Template .Spec .JoinConfiguration
199
- if joinConfiguration == nil {
200
- joinConfiguration = & bootstrapv1.JoinConfiguration {}
201
- }
202
- obj .Spec .Template .Spec .JoinConfiguration = joinConfiguration
203
- if joinConfiguration .NodeRegistration .KubeletExtraArgs == nil {
204
- joinConfiguration .NodeRegistration .KubeletExtraArgs = map [string ]string {}
205
- }
206
- addImageCredentialProviderArgs (joinConfiguration .NodeRegistration .KubeletExtraArgs )
207
-
208
- return nil
209
- }); err != nil {
210
- return err
161
+ if err := patches .MutateIfApplicable (
162
+ obj , vars , & holderRef , selectors .WorkersKubeadmConfigTemplateSelector (), log ,
163
+ func (obj * bootstrapv1.KubeadmConfigTemplate ) error {
164
+ registryWithOptionalCredentials , generateErr := registryWithOptionalCredentialsFromImageRegistryCredentials (
165
+ ctx , h .client , imageRegistry , obj ,
166
+ )
167
+ if generateErr != nil {
168
+ return generateErr
169
+ }
170
+ files , commands , generateErr := generateFilesAndCommands (
171
+ registryWithOptionalCredentials ,
172
+ obj .GetName ())
173
+ if generateErr != nil {
174
+ return generateErr
175
+ }
176
+
177
+ log .WithValues (
178
+ "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
179
+ "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
180
+ ).Info ("adding files to worker node kubeadm config template" )
181
+ obj .Spec .Template .Spec .Files = append (obj .Spec .Template .Spec .Files , files ... )
182
+
183
+ log .WithValues (
184
+ "patchedObjectKind" , obj .GetObjectKind ().GroupVersionKind ().String (),
185
+ "patchedObjectName" , ctrlclient .ObjectKeyFromObject (obj ),
186
+ ).Info ("adding PreKubeadmCommands to worker node kubeadm config template" )
187
+ obj .Spec .Template .Spec .PreKubeadmCommands = append (obj .Spec .Template .Spec .PreKubeadmCommands , commands ... )
188
+
189
+ generateErr = createSecretIfNeeded (ctx , h .client , registryWithOptionalCredentials , obj , clusterKey )
190
+ if generateErr != nil {
191
+ return generateErr
192
+ }
193
+
194
+ joinConfiguration := obj .Spec .Template .Spec .JoinConfiguration
195
+ if joinConfiguration == nil {
196
+ joinConfiguration = & bootstrapv1.JoinConfiguration {}
197
+ }
198
+ obj .Spec .Template .Spec .JoinConfiguration = joinConfiguration
199
+ if joinConfiguration .NodeRegistration .KubeletExtraArgs == nil {
200
+ joinConfiguration .NodeRegistration .KubeletExtraArgs = map [string ]string {}
201
+ }
202
+ addImageCredentialProviderArgs (joinConfiguration .NodeRegistration .KubeletExtraArgs )
203
+
204
+ return nil
205
+ }); err != nil {
206
+ return err
207
+ }
211
208
}
212
209
213
210
return nil
0 commit comments