Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Set the first daemonset namespace to registration namespace if no deployments #536

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/addon/templateagent/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func newDaemonSetDecorator(

func (d *daemonSetDecorator) decorate(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) {
daemonSet, err := utils.ConvertToDaemonSet(obj)
// not a deployment, directly return
// not a daemonset, directly return
if err != nil {
return obj, nil
}
Expand All @@ -168,7 +168,7 @@ func (d *daemonSetDecorator) decorate(obj *unstructured.Unstructured) (*unstruct
}

type podTemplateSpecDecorator interface {
// decorate modifies the deployment in place
// decorate modifies the pod template in place
decorate(pod *corev1.PodTemplateSpec) error
}

Expand Down
24 changes: 18 additions & 6 deletions pkg/addon/templateagent/template_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (a *CRDTemplateAgentAddon) getDesiredAddOnTemplateInner(
return template.DeepCopy(), nil
}

// TemplateAgentRegistrationNamespaceFunc reads deployment resource in the manifests and use that namespace
// TemplateAgentRegistrationNamespaceFunc reads deployment/daemonset resources in the manifests and use that namespace
// as the default registration namespace. If addonDeploymentConfig is set, uses the namespace in it.
func (a *CRDTemplateAgentAddon) TemplateAgentRegistrationNamespaceFunc(
addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
Expand All @@ -242,21 +242,33 @@ func (a *CRDTemplateAgentAddon) TemplateAgentRegistrationNamespaceFunc(
return "", fmt.Errorf("addon %s template not found in status", addon.Name)
}

// pick the namespace of the first deployment
// pick the namespace of the first deployment, if there is no deployment, pick the namespace of the first daemonset
var desiredNS = "open-cluster-management-agent-addon"
var firstDeploymentNamespace, firstDaemonSetNamespace string
for _, manifest := range template.Spec.AgentSpec.Workload.Manifests {
object := &unstructured.Unstructured{}
if err := object.UnmarshalJSON(manifest.Raw); err != nil {
a.logger.Error(err, "failed to extract the object")
continue
}

if _, err = utils.ConvertToDeployment(object); err != nil {
continue
if firstDeploymentNamespace == "" {
if _, err = utils.ConvertToDeployment(object); err == nil {
firstDeploymentNamespace = object.GetNamespace()
break
}
}
if firstDaemonSetNamespace == "" {
if _, err = utils.ConvertToDaemonSet(object); err == nil {
firstDaemonSetNamespace = object.GetNamespace()
}
}
}

desiredNS = object.GetNamespace()
break
if firstDeploymentNamespace != "" {
desiredNS = firstDeploymentNamespace
} else if firstDaemonSetNamespace != "" {
desiredNS = firstDaemonSetNamespace
}

overrideNs, err := utils.AgentInstallNamespaceFromDeploymentConfigFunc(
Expand Down
Loading
Loading