forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.go
44 lines (39 loc) · 1.04 KB
/
hook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package hook
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/argoproj/argo-cd/common"
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
helmhook "github.com/argoproj/argo-cd/util/hook/helm"
"github.com/argoproj/argo-cd/util/resource"
)
func IsHook(obj *unstructured.Unstructured) bool {
_, ok := obj.GetAnnotations()[common.AnnotationKeyHook]
if ok {
return !Skip(obj)
}
return helmhook.IsHook(obj)
}
func Skip(obj *unstructured.Unstructured) bool {
for _, hookType := range Types(obj) {
if hookType == v1alpha1.HookTypeSkip {
return len(Types(obj)) == 1
}
}
return false
}
func Types(obj *unstructured.Unstructured) []v1alpha1.HookType {
var types []v1alpha1.HookType
for _, text := range resource.GetAnnotationCSVs(obj, common.AnnotationKeyHook) {
t, ok := v1alpha1.NewHookType(text)
if ok {
types = append(types, t)
}
}
// we ignore Helm hooks if we have Argo hook
if len(types) == 0 {
for _, t := range helmhook.Types(obj) {
types = append(types, t.HookType())
}
}
return types
}