Skip to content

Commit f3e1033

Browse files
authored
Fix: Process regular expressions at getSourceNamespaces (#1726)
Signed-off-by: nmirasch <[email protected]>
1 parent 10dafdb commit f3e1033

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
@@ -1460,7 +1460,7 @@ func (r *ReconcileArgoCD) getSourceNamespaces(cr *argoproj.ArgoCD) ([]string, er
14601460
}
14611461

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

controllers/argocd/util_test.go

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

10401077
func TestGenerateRandomString(t *testing.T) {
10411078

0 commit comments

Comments
 (0)