-
Notifications
You must be signed in to change notification settings - Fork 136
/
annotations.go
50 lines (40 loc) · 1.14 KB
/
annotations.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
48
49
50
package overlay
import (
"fmt"
"github.com/k14s/ytt/pkg/structmeta"
"github.com/k14s/ytt/pkg/template"
"github.com/k14s/ytt/pkg/yamlmeta"
)
const (
AnnotationNs structmeta.AnnotationNs = "overlay"
AnnotationMerge structmeta.AnnotationName = "overlay/merge" // default
AnnotationRemove structmeta.AnnotationName = "overlay/remove"
AnnotationReplace structmeta.AnnotationName = "overlay/replace"
AnnotationInsert structmeta.AnnotationName = "overlay/insert" // array only
AnnotationAppend structmeta.AnnotationName = "overlay/append" // array only
AnnotationMatch structmeta.AnnotationName = "overlay/match"
)
var (
allOps = []structmeta.AnnotationName{
AnnotationMerge,
AnnotationRemove,
AnnotationReplace,
AnnotationInsert,
AnnotationAppend,
}
)
func whichOp(node yamlmeta.Node) (structmeta.AnnotationName, error) {
var foundOp structmeta.AnnotationName
for _, op := range allOps {
if template.NewAnnotations(node).Has(op) {
if len(foundOp) > 0 {
return "", fmt.Errorf("Expected to find only one overlay operation")
}
foundOp = op
}
}
if len(foundOp) == 0 {
foundOp = AnnotationMerge
}
return foundOp, nil
}