@@ -76,6 +76,11 @@ const (
7676 sveltosAgentClusterTypeLabel = "cluster-type"
7777)
7878
79+ const (
80+ namespaceKind = "Namespace"
81+ clusterRoleBindingKind = "ClusterRoleBinding"
82+ )
83+
7984const (
8085 // This optional annotation enables **per-cluster configuration overrides** for Sveltos sveltos-agent,
8186 // addressing the limitation of the global configuration.
@@ -1672,17 +1677,23 @@ func deploySveltosAgentInManagementCluster(ctx context.Context, restConfig *rest
16721677}
16731678
16741679// updateResourceNamespace sets the namespace on a resource that requires it.
1680+ // For Namespace resources the metadata.name is updated (the namespace is its identity).
16751681// For namespaced resources the object metadata namespace is updated.
16761682// For ClusterRoleBinding the subjects are also patched: the resource is cluster-scoped so
16771683// GetNamespace() returns "" and the plain SetNamespace call would not reach it, but each
16781684// ServiceAccount subject still carries an explicit namespace that must match the actual
16791685// location of the ServiceAccount.
16801686func updateResourceNamespace (policy * unstructured.Unstructured , namespace string ) error {
1687+ if policy .GetKind () == namespaceKind {
1688+ policy .SetName (namespace )
1689+ return nil
1690+ }
1691+
16811692 if policy .GetNamespace () != "" {
16821693 policy .SetNamespace (namespace )
16831694 }
16841695
1685- if policy .GetKind () != "ClusterRoleBinding" {
1696+ if policy .GetKind () != clusterRoleBindingKind {
16861697 return nil
16871698 }
16881699
@@ -1975,7 +1986,9 @@ func removeSveltosAgentFromManagementCluster(ctx context.Context,
19751986 return err
19761987 }
19771988
1978- if policy .GetNamespace () != "" {
1989+ if policy .GetKind () == namespaceKind {
1990+ policy .SetName (getSveltosNamespace ())
1991+ } else if policy .GetNamespace () != "" {
19791992 policy .SetNamespace (getSveltosNamespace ())
19801993 }
19811994
0 commit comments