@@ -189,14 +189,14 @@ func (a *CRDTemplateAgentAddon) renderObjects(
189
189
return objects , err
190
190
}
191
191
192
- object , err = a .decorateObject (template , object , presetValues , privateValues )
192
+ object , err = a .decorateObject (addon , template , object , presetValues , privateValues )
193
193
if err != nil {
194
194
return objects , err
195
195
}
196
196
objects = append (objects , object )
197
197
}
198
198
199
- additionalObjects , err := a .injectAdditionalObjects (template , presetValues , privateValues )
199
+ additionalObjects , err := a .injectAdditionalObjects (addon , template , presetValues , privateValues )
200
200
if err != nil {
201
201
return objects , err
202
202
}
@@ -206,14 +206,16 @@ func (a *CRDTemplateAgentAddon) renderObjects(
206
206
}
207
207
208
208
func (a * CRDTemplateAgentAddon ) decorateObject (
209
+ addon * addonapiv1alpha1.ManagedClusterAddOn ,
209
210
template * addonapiv1alpha1.AddOnTemplate ,
210
211
obj * unstructured.Unstructured ,
211
212
orderedValues orderedValues ,
212
- privateValues addonfactory.Values ) (* unstructured.Unstructured , error ) {
213
+ privateValues addonfactory.Values ,
214
+ ) (* unstructured.Unstructured , error ) {
213
215
decorators := []decorator {
214
216
newDeploymentDecorator (a .logger , a .addonName , template , orderedValues , privateValues ),
215
217
newDaemonSetDecorator (a .logger , a .addonName , template , orderedValues , privateValues ),
216
- newNamespaceDecorator (privateValues ),
218
+ newNamespaceDecorator (addon . Spec . InstallNamespace , privateValues ),
217
219
}
218
220
219
221
var err error
@@ -228,6 +230,7 @@ func (a *CRDTemplateAgentAddon) decorateObject(
228
230
}
229
231
230
232
func (a * CRDTemplateAgentAddon ) injectAdditionalObjects (
233
+ addon * addonapiv1alpha1.ManagedClusterAddOn ,
231
234
template * addonapiv1alpha1.AddOnTemplate ,
232
235
orderedValues orderedValues ,
233
236
privateValues addonfactory.Values ) ([]runtime.Object , error ) {
@@ -237,7 +240,7 @@ func (a *CRDTemplateAgentAddon) injectAdditionalObjects(
237
240
238
241
decorators := []decorator {
239
242
// decorate the namespace of the additional objects
240
- newNamespaceDecorator (privateValues ),
243
+ newNamespaceDecorator (addon . Spec . InstallNamespace , privateValues ),
241
244
}
242
245
243
246
var objs []runtime.Object
@@ -296,47 +299,12 @@ func (a *CRDTemplateAgentAddon) getDesiredAddOnTemplateInner(
296
299
return template .DeepCopy (), nil
297
300
}
298
301
299
- // TemplateAgentRegistrationNamespaceFunc reads deployment/daemonset resources in the manifests and use that namespace
302
+ // TemplateAgentRegistrationNamespaceFunc reads the managedclusteraddon.spec.installnamespace
300
303
// as the default registration namespace. If addonDeploymentConfig is set, uses the namespace in it.
301
304
func (a * CRDTemplateAgentAddon ) TemplateAgentRegistrationNamespaceFunc (
302
305
addon * addonapiv1alpha1.ManagedClusterAddOn ) (string , error ) {
303
- template , err := a .getDesiredAddOnTemplateInner (addon .Name , addon .Status .ConfigReferences )
304
- if err != nil {
305
- return "" , err
306
- }
307
- if template == nil {
308
- return "" , fmt .Errorf ("addon %s template not found in status" , addon .Name )
309
- }
310
-
311
- // pick the namespace of the first deployment, if there is no deployment, pick the namespace of the first daemonset
312
- var desiredNS = "open-cluster-management-agent-addon"
313
- var firstDeploymentNamespace , firstDaemonSetNamespace string
314
- for _ , manifest := range template .Spec .AgentSpec .Workload .Manifests {
315
- object := & unstructured.Unstructured {}
316
- if err := object .UnmarshalJSON (manifest .Raw ); err != nil {
317
- a .logger .Error (err , "failed to extract the object" )
318
- continue
319
- }
320
-
321
- if firstDeploymentNamespace == "" {
322
- if _ , err = utils .ConvertToDeployment (object ); err == nil {
323
- firstDeploymentNamespace = object .GetNamespace ()
324
- break
325
- }
326
- }
327
- if firstDaemonSetNamespace == "" {
328
- if _ , err = utils .ConvertToDaemonSet (object ); err == nil {
329
- firstDaemonSetNamespace = object .GetNamespace ()
330
- }
331
- }
332
- }
333
-
334
- if firstDeploymentNamespace != "" {
335
- desiredNS = firstDeploymentNamespace
336
- } else if firstDaemonSetNamespace != "" {
337
- desiredNS = firstDaemonSetNamespace
338
- }
339
306
307
+ desiredNS := addon .Spec .InstallNamespace
340
308
overrideNs , err := utils .AgentInstallNamespaceFromDeploymentConfigFunc (
341
309
utils .NewAddOnDeploymentConfigGetter (a .addonClient ))(addon )
342
310
if err != nil {
0 commit comments