Skip to content
Open
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
5 changes: 4 additions & 1 deletion pkg/utils/addon_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (g *defaultAddOnDeploymentConfigGetter) Get(
// namespace from the addon deployment config. If the addon does not support addon deployment config or there is no
// matched addon deployment config, it will return an empty string.
func AgentInstallNamespaceFromDeploymentConfigFunc(
adcgetter AddOnDeploymentConfigGetter,
adcgetter AddOnDeploymentConfigGetter, defaultNs ...string,
) func(*addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
Comment on lines 37 to 39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -nP -C3 '\bAgentInstallNamespaceFromDeploymentConfigFunc\s*\(' --type=go

Repository: open-cluster-management-io/addon-framework

Length of output: 228


Address inconsistent nil config handling and update documentation.

Lines 55-59 return an empty string when config == nil without checking defaultNs, while lines 61-63 correctly apply the default namespace when config != nil but AgentInstallNamespace is empty. This inconsistency violates the function's intent. Additionally, the function documentation (lines 34-36) doesn't mention the new default namespace behavior.

Fix the nil config case to also check defaultNs (e.g., return first element if available), and update the function comment to document the fallback behavior.

🤖 Prompt for AI Agents
In pkg/utils/addon_config.go around lines 34 to 63, the function comment and
nil-config branch are inconsistent: update the function comment to state that if
the AddOnDeploymentConfig is nil or its AgentInstallNamespace is empty, the
function will fall back to the first element of the optional defaultNs (if
provided); then change the nil-config handling so it returns defaultNs[0] (when
defaultNs is non-empty) instead of an empty string, preserving the existing
behavior for when no defaultNs is provided and keeping the existing error return
path unchanged.

return func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
if addon == nil {
Expand All @@ -58,6 +58,9 @@ func AgentInstallNamespaceFromDeploymentConfigFunc(
return "", nil
}

if config.Spec.AgentInstallNamespace == "" && len(defaultNs) > 0 {
return defaultNs[0], nil
}
return config.Spec.AgentInstallNamespace, nil
}
}
Expand Down
Loading