-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathannotations.go
97 lines (77 loc) · 2.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package annotations
import (
corev1 "k8s.io/api/core/v1"
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
)
const (
PrimaryResourceStorage = "ydb.tech/primary-resource-storage"
PrimaryResourceDatabase = "ydb.tech/primary-resource-database"
RemoteResourceVersion = "ydb.tech/remote-resource-version"
ConfigurationChecksum = "ydb.tech/configuration-checksum"
LastApplied = "ydb.tech/last-applied"
)
var (
AcceptedDNSPolicy = []string{
string(corev1.DNSClusterFirstWithHostNet),
string(corev1.DNSClusterFirst),
string(corev1.DNSDefault),
string(corev1.DNSNone),
}
SupportedAnnotations = map[string]struct{}{
v1alpha1.AnnotationSkipInitialization: {},
v1alpha1.AnnotationUpdateStrategyOnDelete: {},
v1alpha1.AnnotationUpdateDNSPolicy: {},
v1alpha1.AnnotationDisableLivenessProbe: {},
v1alpha1.AnnotationDataCenter: {},
v1alpha1.AnnotationGRPCPublicHost: {},
v1alpha1.AnnotationNodeHost: {},
v1alpha1.AnnotationNodeDomain: {},
}
)
type Annotations map[string]string
func Common(objAnnotations Annotations) Annotations {
annotations := Annotations{}
annotations.Merge(getSupportedAnnotations(objAnnotations))
return annotations
}
func (an Annotations) Merge(other map[string]string) map[string]string {
if other == nil {
return an
}
for k, v := range other {
an[k] = v
}
return an
}
func (an Annotations) AsMap() map[string]string {
return an
}
func (an Annotations) Copy() Annotations {
res := Annotations{}
for k, v := range an {
res[k] = v
}
return res
}
func getSupportedAnnotations(annotations map[string]string) map[string]string {
common := make(map[string]string)
for key, value := range annotations {
if _, exists := SupportedAnnotations[key]; exists {
common[key] = value
}
}
return common
}
func CompareLastAppliedAnnotation(map1, map2 map[string]string) bool {
value1 := getLastAppliedAnnotation(map1)
value2 := getLastAppliedAnnotation(map2)
return value1 == value2
}
func getLastAppliedAnnotation(annotations map[string]string) string {
for key, value := range annotations {
if key == LastApplied {
return value
}
}
return ""
}