Skip to content

Commit 1a44db3

Browse files
committed
Avoid listing applications in all namespaces if single namespace is configured
Signed-off-by: Graham Beckley <gbeckley@mozilla.com>
1 parent 700e3a5 commit 1a44db3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/argocd/argocd.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ type k8sClient struct {
2929
appNamespace *string
3030
}
3131

32-
// GetApplication retrieves an application by name across all namespaces.
32+
// GetApplication retrieves an application by name, either in a specific namespace or all namespaces depending on client configuration.
3333
func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v1alpha1.Application, error) {
3434
// List all applications across configured namespace or all namespaces (using empty labelSelector)
35+
if *client.appNamespace != v1.NamespaceAll {
36+
return client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(*client.appNamespace).Get(ctx, appName, v1.GetOptions{})
37+
}
38+
return client.getApplicationInAllNamespaces(ctx, appName)
39+
}
40+
41+
func (client *k8sClient) getApplicationInAllNamespaces(ctx context.Context, appName string) (*v1alpha1.Application, error) {
3542
appList, err := client.ListApplications("")
3643
if err != nil {
3744
return nil, fmt.Errorf("error listing applications: %w", err)

0 commit comments

Comments
 (0)