From a22d504fdb613c49c12f4ffc4a41a7edd139e709 Mon Sep 17 00:00:00 2001 From: Manabu McCloskey Date: Mon, 5 Aug 2024 13:14:12 -0700 Subject: [PATCH] skip refresh if owned by app set (#354) Signed-off-by: Manabu McCloskey --- pkg/controllers/localbuild/argo_test.go | 49 ++++++++++++++++++++++++ pkg/controllers/localbuild/controller.go | 7 ++++ 2 files changed, 56 insertions(+) diff --git a/pkg/controllers/localbuild/argo_test.go b/pkg/controllers/localbuild/argo_test.go index 98c800a4..b45518d5 100644 --- a/pkg/controllers/localbuild/argo_test.go +++ b/pkg/controllers/localbuild/argo_test.go @@ -133,6 +133,55 @@ func TestArgoCDAppAnnotation(t *testing.T) { }, }, }, + { + err: nil, + listApps: []argov1alpha1.Application{ + { + TypeMeta: metav1.TypeMeta{ + Kind: argov1alpha1.ApplicationSchemaGroupVersionKind.Kind, + APIVersion: argov1alpha1.ApplicationSchemaGroupVersionKind.GroupVersion().String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "owned-by-appset", + Namespace: "argocd", + Annotations: map[string]string{ + "test": "value", + }, + OwnerReferences: []metav1.OwnerReference{ + { + Kind: "ApplicationSet", + }, + }, + }, + }, + }, + annotations: nil, + }, + { + err: nil, + listApps: []argov1alpha1.Application{ + { + TypeMeta: metav1.TypeMeta{ + Kind: argov1alpha1.ApplicationSchemaGroupVersionKind.Kind, + APIVersion: argov1alpha1.ApplicationSchemaGroupVersionKind.GroupVersion().String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "owned-by-non-appset", + Namespace: "argocd", + OwnerReferences: []metav1.OwnerReference{ + { + Kind: "Something", + }, + }, + }, + }, + }, + annotations: []map[string]string{ + { + argoCDApplicationAnnotationKeyRefresh: argoCDApplicationAnnotationValueRefreshNormal, + }, + }, + }, } for i := range cases { diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index 97091bea..b43fedfb 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -547,8 +547,15 @@ func (r *LocalbuildReconciler) requestArgoCDAppRefresh(ctx context.Context) erro return fmt.Errorf("listing argocd apps for refresh: %w", err) } +apps: for i := range apps.Items { app := apps.Items[i] + for _, o := range app.OwnerReferences { + // if this app is owned by an ApplicationSet, we should let the ApplicationSet refresh. + if o.Kind == argocdapp.ApplicationSetKind { + continue apps + } + } aErr := r.applyArgoCDAnnotation(ctx, &app, argocdapp.ApplicationKind, argoCDApplicationAnnotationKeyRefresh, argoCDApplicationAnnotationValueRefreshNormal) if aErr != nil { return aErr