Skip to content

Commit

Permalink
Supports helm.sh/hook-weight. Closes argoproj#1396
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Jul 26, 2019
1 parent 351e964 commit db9620b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
2 changes: 2 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions controller/sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions controller/sync_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
})
}
}

0 comments on commit db9620b

Please sign in to comment.