@@ -25,13 +25,14 @@ import (
25
25
26
26
// Kubernetes based client
27
27
type k8sClient struct {
28
- kubeClient * kube.ImageUpdaterKubernetesClient
28
+ kubeClient * kube.ImageUpdaterKubernetesClient
29
+ appNamespace * string
29
30
}
30
31
31
32
// GetApplication retrieves an application by name across all namespaces.
32
33
func (client * k8sClient ) GetApplication (ctx context.Context , appName string ) (* v1alpha1.Application , error ) {
33
- // List all applications across all namespaces (using empty labelSelector)
34
- appList , err := client .ListApplications (v1 . NamespaceAll )
34
+ // List all applications across configured namespace or all namespaces (using empty labelSelector)
35
+ appList , err := client .ListApplications ("" )
35
36
if err != nil {
36
37
return nil , fmt .Errorf ("error listing applications: %w" , err )
37
38
}
@@ -61,7 +62,7 @@ func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v
61
62
62
63
// ListApplications lists all applications across all namespaces.
63
64
func (client * k8sClient ) ListApplications (labelSelector string ) ([]v1alpha1.Application , error ) {
64
- list , err := client .kubeClient .ApplicationsClientset .ArgoprojV1alpha1 ().Applications (v1 . NamespaceAll ).List (context .TODO (), v1.ListOptions {LabelSelector : labelSelector })
65
+ list , err := client .kubeClient .ApplicationsClientset .ArgoprojV1alpha1 ().Applications (* client . appNamespace ).List (context .TODO (), v1.ListOptions {LabelSelector : labelSelector })
65
66
if err != nil {
66
67
return nil , fmt .Errorf ("error listing applications: %w" , err )
67
68
}
@@ -99,9 +100,23 @@ func (client *k8sClient) UpdateSpec(ctx context.Context, spec *application.Appli
99
100
return nil , fmt .Errorf ("max retries(%d) reached while updating application: %s" , maxRetries , spec .GetName ())
100
101
}
101
102
103
+ type K8SClientOptions struct {
104
+ AppNamespace string
105
+ }
106
+
102
107
// NewK8SClient creates a new kubernetes client to interact with kubernetes api-server.
103
- func NewK8SClient (kubeClient * kube.ImageUpdaterKubernetesClient ) (ArgoCD , error ) {
104
- return & k8sClient {kubeClient : kubeClient }, nil
108
+ func NewK8SClient (kubeClient * kube.ImageUpdaterKubernetesClient , opts * K8SClientOptions ) (ArgoCD , error ) {
109
+ // Provide default options if nil
110
+ if opts == nil {
111
+ opts = & K8SClientOptions {
112
+ AppNamespace : v1 .NamespaceAll ,
113
+ }
114
+ }
115
+
116
+ return & k8sClient {
117
+ kubeClient : kubeClient ,
118
+ appNamespace : & opts .AppNamespace ,
119
+ }, nil
105
120
}
106
121
107
122
// Native
0 commit comments