/
default_transforms.go
76 lines (67 loc) · 2.17 KB
/
default_transforms.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
package v2
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/kyma-project/lifecycle-manager/api/shared"
)
const (
OperatorName = "module-manager"
ManagedByLabelValue = "declarative-v2"
DisclaimerAnnotation = shared.OperatorGroup + shared.Separator + "managed-by-reconciler-disclaimer"
DisclaimerAnnotationValue = "DO NOT EDIT - This resource is managed by Kyma.\n" +
"Any modifications are discarded and the resource is reverted to the original state."
OwnedByFormat = "%s/%s"
)
func DisclaimerTransform(_ context.Context, _ Object, resources []*unstructured.Unstructured) error {
for _, resource := range resources {
annotations := resource.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations[DisclaimerAnnotation] = DisclaimerAnnotationValue
resource.SetAnnotations(annotations)
}
return nil
}
func KymaComponentTransform(_ context.Context, obj Object, resources []*unstructured.Unstructured) error {
for _, resource := range resources {
lbls := resource.GetLabels()
if lbls == nil {
lbls = make(map[string]string)
}
lbls["app.kubernetes.io/component"] = obj.GetName()
lbls["app.kubernetes.io/part-of"] = "Kyma"
resource.SetLabels(lbls)
}
return nil
}
func ManagedByDeclarativeV2(_ context.Context, _ Object, resources []*unstructured.Unstructured) error {
for _, resource := range resources {
lbls := resource.GetLabels()
if lbls == nil {
lbls = make(map[string]string)
}
// legacy managed by value
lbls[shared.ManagedBy] = ManagedByLabelValue
resource.SetLabels(lbls)
}
return nil
}
func watchedByOwnedBy(_ context.Context, obj Object, resources []*unstructured.Unstructured) error {
for _, resource := range resources {
lbls := resource.GetLabels()
if lbls == nil {
lbls = make(map[string]string)
}
// legacy managed by value
lbls[shared.WatchedByLabel] = OperatorName
annotations := resource.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations[shared.OwnedByAnnotation] = fmt.Sprintf(OwnedByFormat, obj.GetNamespace(), obj.GetName())
resource.SetLabels(lbls)
}
return nil
}