Skip to content

Commit

Permalink
Use default namespace if addon deployment config is not configured
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <[email protected]>
  • Loading branch information
zhujian7 committed Apr 1, 2024
1 parent 693aed7 commit 604c08a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion examples/deploy/addon/helloworld-helm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace: open-cluster-management

resources:
- resources/addon_deployment_config.yaml
- resources/cluster_role.yaml
- resources/cluster_role_binding.yaml
- resources/service_account.yaml
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ spec:
supportedConfigs:
- group: addon.open-cluster-management.io
resource: addondeploymentconfigs
defaultConfig:
name: helloworldhelm-config
namespace: open-cluster-management
- resource: configmaps
5 changes: 4 additions & 1 deletion pkg/addonfactory/helm_agentaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ func (a *HelmAgentAddon) getValueAgentInstallNamespace(addon *addonapiv1alpha1.M
if a.agentInstallNamespace != nil {
ns, err := a.agentInstallNamespace(addon)
if err != nil {
klog.Errorf("failed to get agentInstallNamespace from addon %s. err:%v", addon.Name, err)
klog.Errorf("failed to get agentInstallNamespace from addon %s. err: %v", addon.Name, err)
return "", err
}
if len(ns) > 0 {
installNamespace = ns
} else {
klog.InfoS("Namespace for addon returned by agent install namespace func is empty",
"addonNamespace", addon.Namespace, "addonName", addon)
}
}
return installNamespace, nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/addonfactory/template_agentaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (a *TemplateAgentAddon) getBuiltinValues(
}
if len(ns) > 0 {
installNamespace = ns
} else {
klog.InfoS("Namespace for addon returned by agent install namespace func is empty",
"addonNamespace", addon.Namespace, "addonName", addon)
}
}
builtinValues.AddonInstallNamespace = installNamespace
Expand Down
4 changes: 2 additions & 2 deletions pkg/addonmanager/controllers/registration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func (c *addonRegistrationController) sync(ctx context.Context, syncCtx factory.
if len(ns) > 0 {
managedClusterAddonCopy.Status.Namespace = ns
} else {
klog.Infof("Namespace for addon %s/%s returned by agent install namespace func is empty",
managedClusterAddonCopy.Namespace, managedClusterAddonCopy.Name)
klog.InfoS("Namespace for addon returned by agent install namespace func is empty",
"addonNamespace", managedClusterAddonCopy.Namespace, "addonName", managedClusterAddonCopy.Name)
}
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/utils/addon_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ func AgentInstallNamespaceFromDeploymentConfigFunc(
if err != nil {
return "", fmt.Errorf("failed to get deployment config for addon %s: %v", addon.Name, err)
}

// For now, we have no way of knowing if the addon depleoyment config is not configured, or
// is configured but not yet been added to the managedclusteraddon status config references,
// we expect no error will be returned when the addon deployment config is not configured
// so we can use the default namespace.
// TODO: Find a way to distinguish between the above two cases
if config == nil {
return "", fmt.Errorf("failed to get deployment config for addon %s", addon.Name)
klog.InfoS("Addon deployment config is nil, return an empty string for agent install namespace",
"addonNamespace", addon.Namespace, "addonName", addon.Name)
return "", nil
}

return config.Spec.AgentInstallNamespace, nil
Expand Down

0 comments on commit 604c08a

Please sign in to comment.