Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/applicationset/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func (s *Server) List(ctx context.Context, q *applicationset.ApplicationSetListQ
return nil, fmt.Errorf("error parsing the selector: %w", err)
}

appIf := s.appclientset.ArgoprojV1alpha1().ApplicationSets(q.AppsetNamespace)
namespace := s.appsetNamespaceOrDefault(q.AppsetNamespace)

appIf := s.appclientset.ArgoprojV1alpha1().ApplicationSets(namespace)
appsetList, err := appIf.List(ctx, metav1.ListOptions{LabelSelector: selector.String()})
if err != nil {
return nil, fmt.Errorf("error listing ApplicationSets with selectors: %w", err)
Expand Down
37 changes: 32 additions & 5 deletions server/applicationset/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,22 @@ func testListAppsetsWithLabels(t *testing.T, appsetQuery applicationset.Applicat
}

func TestListAppSetsInNamespaceWithLabels(t *testing.T) {
testNamespace := "test-namespace"
appSetServer := newTestAppSetServer(newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet1"
appset.ObjectMeta.Namespace = "test-namespace"
appset.ObjectMeta.Namespace = testNamespace
appset.SetLabels(map[string]string{"key1": "value1", "key2": "value1"})
}), newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet2"
appset.ObjectMeta.Namespace = "test-namespace"
appset.ObjectMeta.Namespace = testNamespace
appset.SetLabels(map[string]string{"key1": "value2"})
}), newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet3"
appset.ObjectMeta.Namespace = "test-namespace"
appset.ObjectMeta.Namespace = testNamespace
appset.SetLabels(map[string]string{"key1": "value3"})
}))
appSetServer.ns = "test-namespace"
appsetQuery := applicationset.ApplicationSetListQuery{AppsetNamespace: "test-namespace"}
appSetServer.enabledNamespaces = []string{testNamespace}
appsetQuery := applicationset.ApplicationSetListQuery{AppsetNamespace: testNamespace}

testListAppsetsWithLabels(t, appsetQuery, appSetServer)
}
Expand All @@ -258,6 +259,32 @@ func TestListAppSetsInDefaultNSWithLabels(t *testing.T) {
testListAppsetsWithLabels(t, appsetQuery, appSetServer)
}

// This test covers https://github.com/argoproj/argo-cd/issues/15429
// If the namespace isn't provided during listing action, argocd's
// default namespace must be used and not all the namespaces
func TestListAppSetsWithoutNamespace(t *testing.T) {
testNamespace := "test-namespace"
appSetServer := newTestAppSetServer(newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet1"
appset.ObjectMeta.Namespace = testNamespace
appset.SetLabels(map[string]string{"key1": "value1", "key2": "value1"})
}), newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet2"
appset.ObjectMeta.Namespace = testNamespace
appset.SetLabels(map[string]string{"key1": "value2"})
}), newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet3"
appset.ObjectMeta.Namespace = testNamespace
appset.SetLabels(map[string]string{"key1": "value3"})
}))
appSetServer.enabledNamespaces = []string{testNamespace}
appsetQuery := applicationset.ApplicationSetListQuery{}

res, err := appSetServer.List(context.Background(), &appsetQuery)
assert.NoError(t, err)
assert.Equal(t, 0, len(res.Items))
}

func TestCreateAppSet(t *testing.T) {
testAppSet := newTestAppSet()
appServer := newTestAppSetServer()
Expand Down