From db9620bb906aad012ac36cf73429a11095bef3ff Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Fri, 26 Jul 2019 11:09:53 -0700 Subject: [PATCH] Supports helm.sh/hook-weight. Closes #1396 --- common/common.go | 2 ++ controller/sync_task.go | 18 +++++++++--------- controller/sync_task_test.go | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/common/common.go b/common/common.go index 211090636b9eb..b5e473ad35e32 100644 --- a/common/common.go +++ b/common/common.go @@ -116,6 +116,8 @@ const ( AnnotationValueManagedByArgoCD = "argocd.argoproj.io" // AnnotationKeyHelmHook is the helm hook annotation AnnotationKeyHelmHook = "helm.sh/hook" + // AnnotationHelmWeight is the weight of the hook. + AnnotationHelmWeight = "helm.sh/hook-weight" // AnnotationValueHelmHookCRDInstall is a value of crd helm hook AnnotationValueHelmHookCRDInstall = "crd-install" // ResourcesFinalizerName the finalizer value which we inject to finalize deletion of an application diff --git a/controller/sync_task.go b/controller/sync_task.go index a2dbca524d284..fd50cfb2f1b14 100644 --- a/controller/sync_task.go +++ b/controller/sync_task.go @@ -54,17 +54,17 @@ func (t *syncTask) obj() *unstructured.Unstructured { func (t *syncTask) wave() int { - text := t.obj().GetAnnotations()[common.AnnotationSyncWave] - if text == "" { - return 0 + for _, annotation := range []string{common.AnnotationSyncWave, common.AnnotationHelmWeight} { + text, ok := t.obj().GetAnnotations()[annotation] + if ok { + val, err := strconv.Atoi(text) + if err == nil { + return val + } + } } - val, err := strconv.Atoi(text) - if err != nil { - return 0 - } - - return val + return 0 } func (t *syncTask) isHook() bool { diff --git a/controller/sync_task_test.go b/controller/sync_task_test.go index 326c69ecc2d1b..324d21cc81708 100644 --- a/controller/sync_task_test.go +++ b/controller/sync_task_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/argoproj/argo-cd/common" . "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/test" ) @@ -36,3 +37,21 @@ func Test_syncTask_hookType(t *testing.T) { }) } } + +func Test_syncTask_wave(t *testing.T) { + tests := []struct { + name string + obj *unstructured.Unstructured + want int + }{ + {"Empty", test.NewPod(), 0}, + {"SyncWave", test.Annotate(test.NewPod(), common.AnnotationSyncWave, "1"), 1}, + {"HookWeight", test.Annotate(test.NewPod(), common.AnnotationHelmWeight, "1"), 1}, + } + for _, tt := range tests { + t.Run(tt.name, func(t1 *testing.T) { + task := &syncTask{liveObj: tt.obj} + assert.Equal(t1, tt.want, task.wave()) + }) + } +}