@@ -29,44 +29,20 @@ type k8sClient struct {
29
29
30
30
// GetApplication retrieves an application by name across all namespaces.
31
31
func (client * k8sClient ) GetApplication (ctx context.Context , appName string ) (* v1alpha1.Application , error ) {
32
- log .Debugf ("Getting application %s across all namespaces" , appName )
33
-
34
32
// List all applications across all namespaces (using empty labelSelector)
35
33
appList , err := client .ListApplications (v1 .NamespaceAll )
36
34
if err != nil {
37
35
return nil , fmt .Errorf ("error listing applications: %w" , err )
38
36
}
39
37
40
38
// Filter applications by name using nameMatchesPattern
41
- app , err := findApplicationByName (appList , appName )
42
- if err != nil {
43
- log .Errorf ("error getting application: %v" , err )
44
- return nil , fmt .Errorf ("error getting application: %w" , err )
45
- }
46
-
47
- // Retrieve the application in the specified namespace
48
- return app , nil
49
- }
50
-
51
- // ListApplications lists all applications across all namespaces.
52
- func (client * k8sClient ) ListApplications (labelSelector string ) ([]v1alpha1.Application , error ) {
53
- list , err := client .kubeClient .ApplicationsClientset .ArgoprojV1alpha1 ().Applications (v1 .NamespaceAll ).List (context .TODO (), v1.ListOptions {LabelSelector : labelSelector })
54
- if err != nil {
55
- return nil , fmt .Errorf ("error listing applications: %w" , err )
56
- }
57
- log .Debugf ("Applications listed: %d" , len (list .Items ))
58
- return list .Items , nil
59
- }
60
-
61
- // findApplicationByName filters the list of applications by name using nameMatchesPattern.
62
- func findApplicationByName (appList []v1alpha1.Application , appName string ) (* v1alpha1.Application , error ) {
63
- var matchedApps []* v1alpha1.Application
39
+ var matchedApps []v1alpha1.Application
64
40
65
41
for _ , app := range appList {
66
42
log .Debugf ("Found application: %s in namespace %s" , app .Name , app .Namespace )
67
43
if nameMatchesPattern (app .Name , []string {appName }) {
68
44
log .Debugf ("Application %s matches the pattern" , app .Name )
69
- matchedApps = append (matchedApps , & app )
45
+ matchedApps = append (matchedApps , app )
70
46
}
71
47
}
72
48
@@ -78,7 +54,18 @@ func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1a
78
54
return nil , fmt .Errorf ("multiple applications found matching %s" , appName )
79
55
}
80
56
81
- return matchedApps [0 ], nil
57
+ // Retrieve the application in the specified namespace
58
+ return & matchedApps [0 ], nil
59
+ }
60
+
61
+ // ListApplications lists all applications across all namespaces.
62
+ func (client * k8sClient ) ListApplications (labelSelector string ) ([]v1alpha1.Application , error ) {
63
+ list , err := client .kubeClient .ApplicationsClientset .ArgoprojV1alpha1 ().Applications (v1 .NamespaceAll ).List (context .TODO (), v1.ListOptions {LabelSelector : labelSelector })
64
+ if err != nil {
65
+ return nil , fmt .Errorf ("error listing applications: %w" , err )
66
+ }
67
+ log .Debugf ("Applications listed: %d" , len (list .Items ))
68
+ return list .Items , nil
82
69
}
83
70
84
71
func (client * k8sClient ) UpdateSpec (ctx context.Context , spec * application.ApplicationUpdateSpecRequest ) (* v1alpha1.ApplicationSpec , error ) {
0 commit comments