Skip to content

Commit 39d15ce

Browse files
MangaalsaumeyajparsaiJayendra Parsaiiam-veeramalla
authored
Add support for using wildcard chars in sourceNamespaces for ArgoCD Operator (#1218)
* adding a new variable in ReconcileArgoCD struct call SourceNamespaces which store all the SourceNamespaces defined in Argocd Spec. sourceNamespaces Signed-off-by: Mangaal <[email protected]> * range r.SourceNamespaces instead of cr.Spec.SourceNamespaces, cr.Spec.SourceNamespaces might contain wildcard which will lead to error i.e. Namespace * not found Signed-off-by: Mangaal <[email protected]> * range r.SourceNamespaces instead of cr.Spec.SourceNamespaces, cr.Spec.SourceNamespaces might contain wildcard which will lead to error i.e. Namespace * not found Signed-off-by: Mangaal <[email protected]> * adding func containsWildcard Signed-off-by: Mangaal <[email protected]> * adding func setManagedNamespaces Signed-off-by: Mangaal <[email protected]> * range r.SourceNamespaces instead of cr.Spec.SourceNamespaces, cr.Spec.SourceNamespaces might contain wildcard which will lead to error i.e. Namespace * not found Signed-off-by: Mangaal <[email protected]> * adding unit test for func setSourceNamespaces Signed-off-by: Mangaal <[email protected]> * adding unit test for func sourceNamespacemapper Signed-off-by: Mangaal <[email protected]> * update unit test for func reconcileRoleForApplicationSourceNamespaces Signed-off-by: Mangaal <[email protected]> * update func SetupWithManager to watch newly created ns Signed-off-by: Mangaal <[email protected]> * adding func sourceNamespacemapper which filter newly created ns Signed-off-by: Mangaal <[email protected]> * update func setResourceWatches to watch newly created ns. added func sourceNamespaceFilterPredicate Signed-off-by: Mangaal <[email protected]> * go.mod/go.sum Signed-off-by: Mangaal <[email protected]> * unit tests func update Signed-off-by: Mangaal <[email protected]> * adding func getSourceNamespaces Signed-off-by: Mangaal <[email protected]> * adding unit test for func getSourceNamespaces. TestGetSourceNamespaces Signed-off-by: Mangaal <[email protected]> * remove SourceNamespaces from ReconcileArgoCD struct and use func getSourceNamespaces to get SourceNamespaces Signed-off-by: Mangaal <[email protected]> * add to reviewers (#1196) Signed-off-by: saumeya <[email protected]> Signed-off-by: Mangaal <[email protected]> * fix: Operator doesn't reflect deletion of SA from repo setting (#1169) Signed-off-by: Jayendra Parsai <[email protected]> Co-authored-by: Jayendra Parsai <[email protected]> Signed-off-by: Mangaal <[email protected]> * feat: Notification service monitor (#1187) * feat: Expose notifications controller metrics to prometheus monitoring --------- Signed-off-by: iam-veeramalla <[email protected]> Signed-off-by: Mangaal <[email protected]> * Fix status operation value to allow less than 10 (#1198) * fix logic to allow processor operation to be less than default --------- Signed-off-by: Anand Kumar Singh <[email protected]> Signed-off-by: Mangaal <[email protected]> * comment remove Signed-off-by: Mangaal <[email protected]> * fix goimports Signed-off-by: Mangaal <[email protected]> * undo changes in generated codes Signed-off-by: Mangaal <[email protected]> * Revert "comment remove" This reverts commit c5d2f57. Signed-off-by: Mangaal <[email protected]> * remove comments and rename sourceNamespacemapper function to sourceNamespaceMapper Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for source namespace without wildcard Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for source namespace with wildcard pattern Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for source namespace with wildcard '*' Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for sourceNamespaces Signed-off-by: Mangaal <[email protected]> * update with master branch and remove verbs from role in e2e test assert and errors Signed-off-by: Mangaal <[email protected]> * comment for sourceNamespaceMapper function Signed-off-by: Mangaal <[email protected]> * Change the variable name sourceNamespacemapper to sourceNamespaceMapper Signed-off-by: Mangaal <[email protected]> * Removed unwanted blank lines in this function. Signed-off-by: Mangaal <[email protected]> * adeed comment for sourceNamespaceFilterPredicate and getSourceNamespaces Signed-off-by: Mangaal <[email protected]> * adding a new variable in ReconcileArgoCD struct call SourceNamespaces which store all the SourceNamespaces defined in Argocd Spec. sourceNamespaces Signed-off-by: Mangaal <[email protected]> * range r.SourceNamespaces instead of cr.Spec.SourceNamespaces, cr.Spec.SourceNamespaces might contain wildcard which will lead to error i.e. Namespace * not found Signed-off-by: Mangaal <[email protected]> * range r.SourceNamespaces instead of cr.Spec.SourceNamespaces, cr.Spec.SourceNamespaces might contain wildcard which will lead to error i.e. Namespace * not found Signed-off-by: Mangaal <[email protected]> * adding func containsWildcard Signed-off-by: Mangaal <[email protected]> * adding func setManagedNamespaces Signed-off-by: Mangaal <[email protected]> * range r.SourceNamespaces instead of cr.Spec.SourceNamespaces, cr.Spec.SourceNamespaces might contain wildcard which will lead to error i.e. Namespace * not found Signed-off-by: Mangaal <[email protected]> * adding unit test for func setSourceNamespaces Signed-off-by: Mangaal <[email protected]> * adding unit test for func sourceNamespacemapper Signed-off-by: Mangaal <[email protected]> * update unit test for func reconcileRoleForApplicationSourceNamespaces Signed-off-by: Mangaal <[email protected]> * update func SetupWithManager to watch newly created ns Signed-off-by: Mangaal <[email protected]> * adding func sourceNamespacemapper which filter newly created ns Signed-off-by: Mangaal <[email protected]> * update func setResourceWatches to watch newly created ns. added func sourceNamespaceFilterPredicate Signed-off-by: Mangaal <[email protected]> * go.mod/go.sum Signed-off-by: Mangaal <[email protected]> * unit tests func update Signed-off-by: Mangaal <[email protected]> * adding func getSourceNamespaces Signed-off-by: Mangaal <[email protected]> * adding unit test for func getSourceNamespaces. TestGetSourceNamespaces Signed-off-by: Mangaal <[email protected]> * remove SourceNamespaces from ReconcileArgoCD struct and use func getSourceNamespaces to get SourceNamespaces Signed-off-by: Mangaal <[email protected]> * Fix status operation value to allow less than 10 (#1198) * fix logic to allow processor operation to be less than default --------- Signed-off-by: Anand Kumar Singh <[email protected]> Signed-off-by: Mangaal <[email protected]> * comment remove Signed-off-by: Mangaal <[email protected]> * fix goimports Signed-off-by: Mangaal <[email protected]> * undo changes in generated codes Signed-off-by: Mangaal <[email protected]> * Revert "comment remove" This reverts commit c5d2f57. Signed-off-by: Mangaal <[email protected]> * remove comments and rename sourceNamespacemapper function to sourceNamespaceMapper Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for source namespace without wildcard Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for source namespace with wildcard pattern Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for source namespace with wildcard '*' Signed-off-by: Mangaal <[email protected]> * e2e test to valitade role and rolebinding for sourceNamespaces Signed-off-by: Mangaal <[email protected]> * update with master branch and remove verbs from role in e2e test assert and errors Signed-off-by: Mangaal <[email protected]> * comment for sourceNamespaceMapper function Signed-off-by: Mangaal <[email protected]> * Change the variable name sourceNamespacemapper to sourceNamespaceMapper Signed-off-by: Mangaal <[email protected]> * Removed unwanted blank lines in this function. Signed-off-by: Mangaal <[email protected]> * adeed comment for sourceNamespaceFilterPredicate and getSourceNamespaces Signed-off-by: Mangaal <[email protected]> * resolve merge conficts Signed-off-by: Mangaal <[email protected]> * resolve merge conficts Signed-off-by: Mangaal <[email protected]> * removed unwanted blank lines Signed-off-by: Mangaal <[email protected]> * removed unwanted blank lines Signed-off-by: Mangaal <[email protected]> * added unit test cases for getSourceNamespaces and sourceNamespaceMapper func Signed-off-by: Mangaal <[email protected]> * added unit test for multiple sourceNamespaces Signed-off-by: Mangaal <[email protected]> * added e2e test for multiple sourceNamespaces Signed-off-by: Mangaal <[email protected]> * eremoved extra lines from sourceNamespaceMapper Signed-off-by: Mangaal <[email protected]> * documentation for supporting wildcard Signed-off-by: Mangaal <[email protected]> * documentation for supporting wildcard Signed-off-by: Mangaal <[email protected]> * documentation for supporting wildcard Signed-off-by: Mangaal <[email protected]> * documentation for supporting wildcard and Link for Allowing additional namespaces in an AppProject Signed-off-by: Mangaal <[email protected]> * remove placeholder code Signed-off-by: Mangaal <[email protected]> * removed additional lines Signed-off-by: Mangaal <[email protected]> * remote extra watch on namespace resource Signed-off-by: Mangaal <[email protected]> * remote sourceNamespaceFilterPredicate func Signed-off-by: Mangaal <[email protected]> * update TestReconcileApplicationSet_Deployments_Command func. getSourceNamespaces expect ns must exist Signed-off-by: Mangaal <[email protected]> * remove extra lines Signed-off-by: Mangaal <[email protected]> * small update on documentation Signed-off-by: Mangaal <[email protected]> * remove extra lines Signed-off-by: Mangaal <[email protected]> * remove extra lines Signed-off-by: Mangaal <[email protected]> * add e2e test to validate labels,role and rolebinding,after removing namespace from sourcenamespace Signed-off-by: Mangaal <[email protected]> * update e2e test to check for labels in ns which is in sourceNamespace Signed-off-by: Mangaal <[email protected]> --------- Signed-off-by: Mangaal <[email protected]> Signed-off-by: saumeya <[email protected]> Signed-off-by: Jayendra Parsai <[email protected]> Signed-off-by: iam-veeramalla <[email protected]> Signed-off-by: Anand Kumar Singh <[email protected]> Co-authored-by: Saumeya Katyal <[email protected]> Co-authored-by: Jayendra Parsai <[email protected]> Co-authored-by: Jayendra Parsai <[email protected]> Co-authored-by: Abhishek Veeramalla <[email protected]> Co-authored-by: Anand Kumar Singh <[email protected]>
1 parent 4bd23cb commit 39d15ce

28 files changed

+1100
-26
lines changed

controllers/argocd/applicationset_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,17 @@ func TestReconcileApplicationSet_Deployments_Command(t *testing.T) {
481481
t.Run(test.name, func(t *testing.T) {
482482

483483
a := makeTestArgoCD()
484-
resObjs := []client.Object{a}
484+
ns1 := v1.Namespace{
485+
ObjectMeta: metav1.ObjectMeta{
486+
Name: "foo",
487+
},
488+
}
489+
ns2 := v1.Namespace{
490+
ObjectMeta: metav1.ObjectMeta{
491+
Name: "bar",
492+
},
493+
}
494+
resObjs := []client.Object{a, &ns1, &ns2}
485495
subresObjs := []client.Object{a}
486496
runtimeObjs := []runtime.Object{}
487497
sch := makeTestReconcilerScheme(argoproj.AddToScheme)

controllers/argocd/custommapper.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/argoproj/argo-cd/v2/util/glob"
9+
810
argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
911
"github.com/argoproj-labs/argocd-operator/common"
1012

@@ -130,17 +132,16 @@ func (r *ReconcileArgoCD) tlsSecretMapper(ctx context.Context, o client.Object)
130132
func (r *ReconcileArgoCD) namespaceResourceMapper(ctx context.Context, o client.Object) []reconcile.Request {
131133
var result = []reconcile.Request{}
132134

135+
argocds := &argoproj.ArgoCDList{}
133136
labels := o.GetLabels()
137+
namespaceName := o.GetName()
134138
if v, ok := labels[common.ArgoCDManagedByLabel]; ok {
135-
argocds := &argoproj.ArgoCDList{}
136139
if err := r.Client.List(context.TODO(), argocds, &client.ListOptions{Namespace: v}); err != nil {
137140
return result
138141
}
139-
140142
if len(argocds.Items) != 1 {
141143
return result
142144
}
143-
144145
argocd := argocds.Items[0]
145146
namespacedName := client.ObjectKey{
146147
Name: argocd.Name,
@@ -149,6 +150,23 @@ func (r *ReconcileArgoCD) namespaceResourceMapper(ctx context.Context, o client.
149150
result = []reconcile.Request{
150151
{NamespacedName: namespacedName},
151152
}
153+
} else {
154+
// If the namespace does not have the expected managed-by label,
155+
// iterate through each ArgoCD instance to identify if the observed namespace
156+
// matches any configured sourceNamespace pattern. If a match is found,
157+
// generate a reconcile request for the instances.
158+
if err := r.Client.List(ctx, argocds, &client.ListOptions{}); err != nil {
159+
return result
160+
}
161+
for _, argocd := range argocds.Items {
162+
if glob.MatchStringInList(argocd.Spec.SourceNamespaces, namespaceName, false) {
163+
namespacedName := client.ObjectKey{
164+
Name: argocd.Name,
165+
Namespace: argocd.Namespace,
166+
}
167+
result = append(result, reconcile.Request{NamespacedName: namespacedName})
168+
}
169+
}
152170
}
153171

154172
return result

controllers/argocd/custommapper_test.go

Lines changed: 312 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ func TestReconcileArgoCD_tlsSecretMapperRedis(t *testing.T) {
569569

570570
}
571571

572-
func TestReconcileArgoCD_namespaceResourceMapper(t *testing.T) {
572+
func TestReconcileArgoCD_namespaceResourceMapperWithManagedByLabel(t *testing.T) {
573573
a := makeTestArgoCD()
574574

575575
resObjs := []client.Object{a}
@@ -631,3 +631,314 @@ func TestReconcileArgoCD_namespaceResourceMapper(t *testing.T) {
631631
})
632632
}
633633
}
634+
635+
func TestReconcileArgoCD_namespaceResourceMapperForSpecificNamespaceWithoutManagedByLabel(t *testing.T) {
636+
argocd1 := makeTestArgoCD()
637+
resObjs := []client.Object{argocd1}
638+
subresObjs := []client.Object{argocd1}
639+
runtimeObjs := []runtime.Object{}
640+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
641+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
642+
r := makeTestReconciler(cl, sch)
643+
644+
argocd1.Name = "argocd1"
645+
argocd1.Namespace = "argo-test-1"
646+
argocd1.Spec.SourceNamespaces = append(argocd1.Spec.SourceNamespaces, "test-namespace-1")
647+
// Fake client returns an error if ResourceVersion is not nil
648+
argocd1.ResourceVersion = ""
649+
650+
assert.NoError(t, r.Client.Create(context.TODO(), argocd1))
651+
652+
type test struct {
653+
name string
654+
o client.Object
655+
want []reconcile.Request
656+
}
657+
658+
tests := []test{
659+
{
660+
name: "Reconcile for Namespace 'test-namespace-1'",
661+
o: &corev1.Namespace{
662+
ObjectMeta: metav1.ObjectMeta{
663+
Name: "test-namespace-1",
664+
},
665+
},
666+
want: []reconcile.Request{
667+
{
668+
NamespacedName: types.NamespacedName{
669+
Name: argocd1.Name,
670+
Namespace: argocd1.Namespace,
671+
},
672+
},
673+
},
674+
},
675+
{
676+
name: "No Reconcile for Namespace 'test-namespace-2'",
677+
o: &corev1.Namespace{
678+
ObjectMeta: metav1.ObjectMeta{
679+
Name: "test-namespace-2",
680+
},
681+
},
682+
want: []reconcile.Request{},
683+
},
684+
}
685+
686+
for _, tt := range tests {
687+
t.Run(tt.name, func(t *testing.T) {
688+
if got := r.namespaceResourceMapper(context.TODO(), tt.o); !assert.ElementsMatch(t, got, tt.want) {
689+
t.Errorf("ReconcileArgoCD.sourceNamespaceMapper(), got = %v, want = %v", got, tt.want)
690+
}
691+
})
692+
}
693+
}
694+
695+
func TestReconcileArgoCD_namespaceResourceMapperForWildCardPatternNamespaceWithoutManagedByLabel(t *testing.T) {
696+
argocd1 := makeTestArgoCD()
697+
resObjs := []client.Object{argocd1}
698+
subresObjs := []client.Object{argocd1}
699+
runtimeObjs := []runtime.Object{}
700+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
701+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
702+
r := makeTestReconciler(cl, sch)
703+
704+
argocd1.Name = "argocd1"
705+
argocd1.Namespace = "argo-test-1"
706+
argocd1.Spec.SourceNamespaces = append(argocd1.Spec.SourceNamespaces, "test*")
707+
// Fake client returns an error if ResourceVersion is not nil
708+
argocd1.ResourceVersion = ""
709+
710+
assert.NoError(t, r.Client.Create(context.TODO(), argocd1))
711+
712+
type test struct {
713+
name string
714+
o client.Object
715+
want []reconcile.Request
716+
}
717+
718+
tests := []test{
719+
{
720+
name: "Reconcile for Namespace 'test-namespace-1'",
721+
o: &corev1.Namespace{
722+
ObjectMeta: metav1.ObjectMeta{
723+
Name: "test-namespace-1",
724+
},
725+
},
726+
want: []reconcile.Request{
727+
{
728+
NamespacedName: types.NamespacedName{
729+
Name: argocd1.Name,
730+
Namespace: argocd1.Namespace,
731+
},
732+
},
733+
},
734+
},
735+
{
736+
name: "Reconcile for Namespace 'test-namespace-2'",
737+
o: &corev1.Namespace{
738+
ObjectMeta: metav1.ObjectMeta{
739+
Name: "test-namespace-2",
740+
},
741+
},
742+
want: []reconcile.Request{
743+
{
744+
NamespacedName: types.NamespacedName{
745+
Name: argocd1.Name,
746+
Namespace: argocd1.Namespace,
747+
},
748+
},
749+
},
750+
},
751+
{
752+
name: "No Reconcile for Namespace 'prod-namespace-1'",
753+
o: &corev1.Namespace{
754+
ObjectMeta: metav1.ObjectMeta{
755+
Name: "prod-namespace-1",
756+
},
757+
},
758+
want: []reconcile.Request{},
759+
},
760+
}
761+
762+
for _, tt := range tests {
763+
t.Run(tt.name, func(t *testing.T) {
764+
if got := r.namespaceResourceMapper(context.TODO(), tt.o); !assert.ElementsMatch(t, got, tt.want) {
765+
t.Errorf("ReconcileArgoCD.sourceNamespaceMapper(), got = %v, want = %v", got, tt.want)
766+
}
767+
})
768+
}
769+
}
770+
771+
func TestReconcileArgoCD_namespaceResourceMapperForMultipleSourceNamespacesWithoutManagedByLabel(t *testing.T) {
772+
argocd1 := makeTestArgoCD()
773+
resObjs := []client.Object{argocd1}
774+
subresObjs := []client.Object{argocd1}
775+
runtimeObjs := []runtime.Object{}
776+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
777+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
778+
r := makeTestReconciler(cl, sch)
779+
780+
argocd1.Name = "argocd1"
781+
argocd1.Namespace = "argo-test-1"
782+
argocd1.Spec.SourceNamespaces = append(argocd1.Spec.SourceNamespaces, "test*", "dev*")
783+
// Fake client returns an error if ResourceVersion is not nil
784+
argocd1.ResourceVersion = ""
785+
786+
assert.NoError(t, r.Client.Create(context.TODO(), argocd1))
787+
788+
type test struct {
789+
name string
790+
o client.Object
791+
want []reconcile.Request
792+
}
793+
794+
tests := []test{
795+
{
796+
name: "Reconcile for Namespace 'test-namespace-1'",
797+
o: &corev1.Namespace{
798+
ObjectMeta: metav1.ObjectMeta{
799+
Name: "test-namespace-1",
800+
},
801+
},
802+
want: []reconcile.Request{
803+
{
804+
NamespacedName: types.NamespacedName{
805+
Name: argocd1.Name,
806+
Namespace: argocd1.Namespace,
807+
},
808+
},
809+
},
810+
},
811+
{
812+
name: "Reconcile for Namespace 'test-namespace-2'",
813+
o: &corev1.Namespace{
814+
ObjectMeta: metav1.ObjectMeta{
815+
Name: "test-namespace-2",
816+
},
817+
},
818+
want: []reconcile.Request{
819+
{
820+
NamespacedName: types.NamespacedName{
821+
Name: argocd1.Name,
822+
Namespace: argocd1.Namespace,
823+
},
824+
},
825+
},
826+
},
827+
{
828+
name: "Reconcile for Namespace 'dev-namespace-1'",
829+
o: &corev1.Namespace{
830+
ObjectMeta: metav1.ObjectMeta{
831+
Name: "dev-namespace-1",
832+
},
833+
},
834+
want: []reconcile.Request{
835+
{
836+
NamespacedName: types.NamespacedName{
837+
Name: argocd1.Name,
838+
Namespace: argocd1.Namespace,
839+
},
840+
},
841+
},
842+
},
843+
{
844+
name: "No Reconcile for Namespace 'prod-namespace-1'",
845+
o: &corev1.Namespace{
846+
ObjectMeta: metav1.ObjectMeta{
847+
Name: "prod-namespace-1",
848+
},
849+
},
850+
want: []reconcile.Request{},
851+
},
852+
}
853+
854+
for _, tt := range tests {
855+
t.Run(tt.name, func(t *testing.T) {
856+
if got := r.namespaceResourceMapper(context.TODO(), tt.o); !assert.ElementsMatch(t, got, tt.want) {
857+
t.Errorf("ReconcileArgoCD.sourceNamespaceMapper(), got = %v, want = %v", got, tt.want)
858+
}
859+
})
860+
}
861+
}
862+
863+
func TestReconcileArgoCD_namespaceResourceMapperForWildCardNamespaceWithoutManagedByLabel(t *testing.T) {
864+
argocd1 := makeTestArgoCD()
865+
resObjs := []client.Object{argocd1}
866+
subresObjs := []client.Object{argocd1}
867+
runtimeObjs := []runtime.Object{}
868+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
869+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
870+
r := makeTestReconciler(cl, sch)
871+
872+
argocd1.Name = "argocd1"
873+
argocd1.Namespace = "argo-test-1"
874+
argocd1.Spec.SourceNamespaces = append(argocd1.Spec.SourceNamespaces, "*")
875+
// Fake client returns an error if ResourceVersion is not nil
876+
argocd1.ResourceVersion = ""
877+
878+
assert.NoError(t, r.Client.Create(context.TODO(), argocd1))
879+
880+
type test struct {
881+
name string
882+
o client.Object
883+
want []reconcile.Request
884+
}
885+
886+
tests := []test{
887+
{
888+
name: "Reconcile for Namespace 'test-namespace-1'",
889+
o: &corev1.Namespace{
890+
ObjectMeta: metav1.ObjectMeta{
891+
Name: "test-namespace-1",
892+
},
893+
},
894+
want: []reconcile.Request{
895+
{
896+
NamespacedName: types.NamespacedName{
897+
Name: argocd1.Name,
898+
Namespace: argocd1.Namespace,
899+
},
900+
},
901+
},
902+
},
903+
{
904+
name: "Reconcile for Namespace 'test-namespace-2'",
905+
o: &corev1.Namespace{
906+
ObjectMeta: metav1.ObjectMeta{
907+
Name: "test-namespace-2",
908+
},
909+
},
910+
want: []reconcile.Request{
911+
{
912+
NamespacedName: types.NamespacedName{
913+
Name: argocd1.Name,
914+
Namespace: argocd1.Namespace,
915+
},
916+
},
917+
},
918+
},
919+
{
920+
name: "Reconcile for Namespace 'prod-namespace-1'",
921+
o: &corev1.Namespace{
922+
ObjectMeta: metav1.ObjectMeta{
923+
Name: "prod-namespace-1",
924+
},
925+
},
926+
want: []reconcile.Request{
927+
{
928+
NamespacedName: types.NamespacedName{
929+
Name: argocd1.Name,
930+
Namespace: argocd1.Namespace,
931+
},
932+
},
933+
},
934+
},
935+
}
936+
937+
for _, tt := range tests {
938+
t.Run(tt.name, func(t *testing.T) {
939+
if got := r.namespaceResourceMapper(context.TODO(), tt.o); !assert.ElementsMatch(t, got, tt.want) {
940+
t.Errorf("ReconcileArgoCD.sourceNamespaceMapper(), got = %v, want = %v", got, tt.want)
941+
}
942+
})
943+
}
944+
}

0 commit comments

Comments
 (0)