summaryrefslogtreecommitdiff
path: root/pkg/argocd/argocd.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/argocd/argocd.go')
-rw-r--r--pkg/argocd/argocd.go41
1 files changed, 14 insertions, 27 deletions
diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go
index 63ac7a7..f064eaa 100644
--- a/pkg/argocd/argocd.go
+++ b/pkg/argocd/argocd.go
@@ -29,8 +29,6 @@ type k8sClient struct {
// GetApplication retrieves an application by name across all namespaces.
func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v1alpha1.Application, error) {
- log.Debugf("Getting application %s across all namespaces", appName)
-
// List all applications across all namespaces (using empty labelSelector)
appList, err := client.ListApplications(v1.NamespaceAll)
if err != nil {
@@ -38,35 +36,13 @@ func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v
}
// Filter applications by name using nameMatchesPattern
- app, err := findApplicationByName(appList, appName)
- if err != nil {
- log.Errorf("error getting application: %v", err)
- return nil, fmt.Errorf("error getting application: %w", err)
- }
-
- // Retrieve the application in the specified namespace
- return app, nil
-}
-
-// ListApplications lists all applications across all namespaces.
-func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) {
- list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(v1.NamespaceAll).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector})
- if err != nil {
- return nil, fmt.Errorf("error listing applications: %w", err)
- }
- log.Debugf("Applications listed: %d", len(list.Items))
- return list.Items, nil
-}
-
-// findApplicationByName filters the list of applications by name using nameMatchesPattern.
-func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1alpha1.Application, error) {
- var matchedApps []*v1alpha1.Application
+ var matchedApps []v1alpha1.Application
for _, app := range appList {
log.Debugf("Found application: %s in namespace %s", app.Name, app.Namespace)
if nameMatchesPattern(app.Name, []string{appName}) {
log.Debugf("Application %s matches the pattern", app.Name)
- matchedApps = append(matchedApps, &app)
+ matchedApps = append(matchedApps, app)
}
}
@@ -78,7 +54,18 @@ func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1a
return nil, fmt.Errorf("multiple applications found matching %s", appName)
}
- return matchedApps[0], nil
+ // Retrieve the application in the specified namespace
+ return &matchedApps[0], nil
+}
+
+// ListApplications lists all applications across all namespaces.
+func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) {
+ list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(v1.NamespaceAll).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector})
+ if err != nil {
+ return nil, fmt.Errorf("error listing applications: %w", err)
+ }
+ log.Debugf("Applications listed: %d", len(list.Items))
+ return list.Items, nil
}
func (client *k8sClient) UpdateSpec(ctx context.Context, spec *application.ApplicationUpdateSpecRequest) (*v1alpha1.ApplicationSpec, error) {