Skip to content

Commit

Permalink
Issue #355 - Treat 'crd-install' hooks as normal k8s resource (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmt authored Nov 17, 2018
1 parent 44087fa commit 275b9e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ var (
// AnnotationHelmHook is the helm hook annotation
AnnotationHelmHook = "helm.sh/hook"

// HelmHookCRDInstall is a value of crd helm hook
HelmHookCRDInstall = "crd-install"

// LabelKeyApplicationControllerInstanceID is the label which allows to separate application among multiple running application controllers.
LabelKeyApplicationControllerInstanceID = application.ApplicationFullName + "/controller-instanceid"

Expand Down
3 changes: 3 additions & 0 deletions controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func TestIsHook(t *testing.T) {
pod.SetAnnotations(map[string]string{"helm.sh/hook": "post-install"})
assert.True(t, isHook(pod))

pod.SetAnnotations(map[string]string{"helm.sh/hook": "crd-install"})
assert.False(t, isHook(pod))

pod = newPod()
pod.SetAnnotations(map[string]string{"argocd.argoproj.io/hook": "PreSync"})
assert.True(t, isHook(pod))
Expand Down
16 changes: 15 additions & 1 deletion controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,24 @@ func isHelmHook(obj *unstructured.Unstructured) bool {
if annotations == nil {
return false
}
_, ok := annotations[common.AnnotationHelmHook]
hooks, ok := annotations[common.AnnotationHelmHook]

if ok && hasHook(hooks, common.HelmHookCRDInstall) {
return false
}

return ok
}

func hasHook(hooks string, hook string) bool {
for _, item := range strings.Split(hooks, ",") {
if strings.TrimSpace(item) == hook {
return true
}
}
return false
}

// isArgoHook indicates if the supplied object is an Argo CD application lifecycle hook
// (vs. a normal, synced application resource)
func isArgoHook(obj *unstructured.Unstructured) bool {
Expand Down

0 comments on commit 275b9e1

Please sign in to comment.