Skip to content

Commit e624ae0

Browse files
authored
Fix: Process regular expressions at getSourceNamespaces (#1726) (#1741)
(cherry picked from commit f3e1033) Signed-off-by: nmirasch <[email protected]>
1 parent f66b337 commit e624ae0

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

controllers/argocd/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ func (r *ReconcileArgoCD) getSourceNamespaces(cr *argoproj.ArgoCD) ([]string, er
14581458
}
14591459

14601460
for _, namespace := range namespaces.Items {
1461-
if glob.MatchStringInList(cr.Spec.SourceNamespaces, namespace.Name, glob.GLOB) {
1461+
if glob.MatchStringInList(cr.Spec.SourceNamespaces, namespace.Name, glob.REGEXP) {
14621462
sourceNamespaces = append(sourceNamespaces, namespace.Name)
14631463
}
14641464
}

controllers/argocd/util_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,43 @@ func TestGetSourceNamespacesWithWildCardNamespace(t *testing.T) {
10381038
assert.Contains(t, sourceNamespaces, "test-namespace-1")
10391039
assert.Contains(t, sourceNamespaces, "test-namespace-2")
10401040
}
1041+
func TestGetSourceNamespacesWithRegExpNamespace(t *testing.T) {
1042+
a := makeTestArgoCD()
1043+
a.Spec = argoproj.ArgoCDSpec{
1044+
SourceNamespaces: []string{
1045+
"/^test.*test$/",
1046+
},
1047+
}
1048+
ns1 := v1.Namespace{
1049+
ObjectMeta: metav1.ObjectMeta{
1050+
Name: "testtest",
1051+
},
1052+
}
1053+
ns2 := v1.Namespace{
1054+
ObjectMeta: metav1.ObjectMeta{
1055+
Name: "test123test",
1056+
},
1057+
}
1058+
ns3 := v1.Namespace{
1059+
ObjectMeta: metav1.ObjectMeta{
1060+
Name: "test-abc-test",
1061+
},
1062+
}
1063+
1064+
resObjs := []client.Object{a, &ns1, &ns2, &ns3}
1065+
subresObjs := []client.Object{a}
1066+
runtimeObjs := []runtime.Object{}
1067+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
1068+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
1069+
r := makeTestReconciler(cl, sch)
1070+
1071+
sourceNamespaces, err := r.getSourceNamespaces(a)
1072+
assert.NoError(t, err)
1073+
assert.Equal(t, 3, len(sourceNamespaces))
1074+
assert.Contains(t, sourceNamespaces, "testtest")
1075+
assert.Contains(t, sourceNamespaces, "test123test")
1076+
assert.Contains(t, sourceNamespaces, "test-abc-test")
1077+
}
10411078

10421079
func TestGenerateRandomString(t *testing.T) {
10431080

0 commit comments

Comments
 (0)