@@ -230,7 +230,7 @@ func (a *CRDTemplateAgentAddon) getDesiredAddOnTemplateInner(
230230 return template .DeepCopy (), nil
231231}
232232
233- // TemplateAgentRegistrationNamespaceFunc reads deployment resource in the manifests and use that namespace
233+ // TemplateAgentRegistrationNamespaceFunc reads deployment/daemonset resources in the manifests and use that namespace
234234// as the default registration namespace. If addonDeploymentConfig is set, uses the namespace in it.
235235func (a * CRDTemplateAgentAddon ) TemplateAgentRegistrationNamespaceFunc (
236236 addon * addonapiv1alpha1.ManagedClusterAddOn ) (string , error ) {
@@ -242,21 +242,33 @@ func (a *CRDTemplateAgentAddon) TemplateAgentRegistrationNamespaceFunc(
242242 return "" , fmt .Errorf ("addon %s template not found in status" , addon .Name )
243243 }
244244
245- // pick the namespace of the first deployment
245+ // pick the namespace of the first deployment, if there is no deployment, pick the namespace of the first daemonset
246246 var desiredNS = "open-cluster-management-agent-addon"
247+ var firstDeploymentNamespace , firstDaemonSetNamespace string
247248 for _ , manifest := range template .Spec .AgentSpec .Workload .Manifests {
248249 object := & unstructured.Unstructured {}
249250 if err := object .UnmarshalJSON (manifest .Raw ); err != nil {
250251 a .logger .Error (err , "failed to extract the object" )
251252 continue
252253 }
253254
254- if _ , err = utils .ConvertToDeployment (object ); err != nil {
255- continue
255+ if firstDeploymentNamespace == "" {
256+ if _ , err = utils .ConvertToDeployment (object ); err == nil {
257+ firstDeploymentNamespace = object .GetNamespace ()
258+ break
259+ }
260+ }
261+ if firstDaemonSetNamespace == "" {
262+ if _ , err = utils .ConvertToDaemonSet (object ); err == nil {
263+ firstDaemonSetNamespace = object .GetNamespace ()
264+ }
256265 }
266+ }
257267
258- desiredNS = object .GetNamespace ()
259- break
268+ if firstDeploymentNamespace != "" {
269+ desiredNS = firstDeploymentNamespace
270+ } else if firstDaemonSetNamespace != "" {
271+ desiredNS = firstDaemonSetNamespace
260272 }
261273
262274 overrideNs , err := utils .AgentInstallNamespaceFromDeploymentConfigFunc (
0 commit comments