Skip to content

Add NamespaceManagement reconciliation #1687

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

Rizwana777
Copy link
Contributor

@Rizwana777 Rizwana777 commented Mar 10, 2025

What type of PR is this?

Add NamespaceManagement reconciliation
Add NamespaceManagement CR
Add .Spec.NamespaceManagement field in ArgoCDSpec CR
Unit tests
e2e for glob match on .Spec.NamespaceManagement field

Moved
k8sClient, err := initK8sClient()
if err != nil {
setupLog.Error(err, "Failed to initialize Kubernetes client")
os.Exit(1)
}
to main.go and also passing k8sClient in ReconcileArgoCD object to use it in code to avoid these
Failed to initialize Kubernetes client {"error": "invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable", "errorCauses": [{"error": "no configuration has been provided, try setting KUBERNETES_MASTER environment variable"}]} errors

and also e2e tests was failing because of this, I found out that initializing k8sClient in main.go would be the better option
let me know if this method is incorrect and needs modification

JIRA - https://issues.redhat.com/browse/GITOPS-6179

@Rizwana777 Rizwana777 marked this pull request as draft March 10, 2025 11:11
@Rizwana777 Rizwana777 force-pushed the issue-6179 branch 15 times, most recently from c16e6e4 to f353e2a Compare March 13, 2025 15:25
@Rizwana777 Rizwana777 force-pushed the issue-6179 branch 2 times, most recently from c7bcc4e to ccecd06 Compare March 24, 2025 10:57
@Rizwana777 Rizwana777 marked this pull request as ready for review March 24, 2025 12:02
@Rizwana777 Rizwana777 force-pushed the issue-6179 branch 3 times, most recently from 0788240 to 0d67be6 Compare April 16, 2025 13:27
@Rizwana777 Rizwana777 force-pushed the issue-6179 branch 3 times, most recently from 8da9978 to 1495dbc Compare April 28, 2025 10:49
@Rizwana777 Rizwana777 force-pushed the issue-6179 branch 3 times, most recently from 53e5090 to c4a47fa Compare May 6, 2025 06:51
@Rizwana777 Rizwana777 force-pushed the issue-6179 branch 7 times, most recently from f6d3ea6 to 974290d Compare May 15, 2025 17:25
allowedNamespaces := make(map[string]bool)
if argocd.Spec.NamespaceManagement != nil {
for _, nm := range argocd.Spec.NamespaceManagement {
allowedNamespaces[nm.Name] = nm.AllowManagedBy
Copy link
Member

Choose a reason for hiding this comment

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

nm.Name can be a pattern; this logic isn't correct when nm.Name is a pattern instead of a namespace name.

// Only act on namespaces in ArgoCD.spec.namespaceManagement that are truly managed by this ArgoCD
for _, ns := range argocd.Spec.NamespaceManagement {
nsName := ns.Name
if !managedNamespaces[nsName] {
Copy link
Member

Choose a reason for hiding this comment

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

nsName can be a pattern, rather than just a name, so this logic likely isn't correct.

allowedNamespaceMap := make(map[string]bool)
for _, entry := range cr.Spec.NamespaceManagement {
if entry.AllowManagedBy {
allowedNamespaceMap[entry.Name] = true
Copy link
Member

Choose a reason for hiding this comment

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

entry.Name can be a pattern, not just a name. So this logic is likely not correct.


for _, ns := range oldList {
oldNamespaces[ns.Name] = true
oldNamespaceSettings[ns.Name] = ns.AllowManagedBy // Store old setting
Copy link
Member

Choose a reason for hiding this comment

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

Given that ns.name can be a pattern, I think this logic isn't correct. (The function that calls this assumes that the []string result are actual namespace names)

assert.Equal(t, "ErrorOccurred", reconciledCondition.Reason)
}

func TestHandleFeatureDisable_NoNamespaceManagement(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Could use a few more tests that verify the logic in disableNamespaceManagement

}

// getNamespacesToDelete determines which namespaces were removed or had allowManagedBy changed.
func getNamespacesToDelete(oldList, newList []argoproj.ManagedNamespaces) []string {
Copy link
Member

Choose a reason for hiding this comment

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

Could use some unit tests for getNamespacesToDelete

Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Signed-off-by: Rizwana777 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants