forked from argoproj/gitops-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
47 lines (39 loc) · 1.02 KB
/
type.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
45
46
47
package helm
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/argoproj/gitops-engine/pkg/sync/common"
resourceutil "github.com/argoproj/gitops-engine/pkg/sync/resource"
)
type Type string
const (
PreInstall Type = "pre-install"
PreUpgrade Type = "pre-upgrade"
PostUpgrade Type = "post-upgrade"
PostInstall Type = "post-install"
)
func NewType(t string) (Type, bool) {
return Type(t),
t == string(PreInstall) ||
t == string(PreUpgrade) ||
t == string(PostUpgrade) ||
t == string(PostInstall)
}
var hookTypes = map[Type]common.HookType{
PreInstall: common.HookTypePreSync,
PreUpgrade: common.HookTypePreSync,
PostUpgrade: common.HookTypePostSync,
PostInstall: common.HookTypePostSync,
}
func (t Type) HookType() common.HookType {
return hookTypes[t]
}
func Types(obj *unstructured.Unstructured) []Type {
var types []Type
for _, text := range resourceutil.GetAnnotationCSVs(obj, "helm.sh/hook") {
t, ok := NewType(text)
if ok {
types = append(types, t)
}
}
return types
}