-
Notifications
You must be signed in to change notification settings - Fork 865
/
annotation.go
31 lines (26 loc) · 1.01 KB
/
annotation.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
package util
import "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
// MergeAnnotation adds annotation for the given object.
func MergeAnnotation(obj *unstructured.Unstructured, annotationKey string, annotationValue string) {
objectAnnotation := obj.GetAnnotations()
if objectAnnotation == nil {
objectAnnotation = make(map[string]string, 1)
}
if _, exist := objectAnnotation[annotationKey]; !exist {
objectAnnotation[annotationKey] = annotationValue
obj.SetAnnotations(objectAnnotation)
}
}
// MergeAnnotations merges the annotations from 'src' to 'dst'.
func MergeAnnotations(dst *unstructured.Unstructured, src *unstructured.Unstructured) {
for key, value := range src.GetAnnotations() {
MergeAnnotation(dst, key, value)
}
}
// GetAnnotationValue retrieves the value via 'annotationKey' (if it exists), otherwise an empty string is returned.
func GetAnnotationValue(annotations map[string]string, annotationKey string) string {
if annotations == nil {
return ""
}
return annotations[annotationKey]
}