@@ -26,25 +26,24 @@ const (
26
26
LastAppliedMongoDBVersion = "mongodb.com/v1.lastAppliedMongoDBVersion"
27
27
)
28
28
29
- func GetAnnotation (object Versioned , key string ) string {
29
+ func GetAnnotation (object client. Object , key string ) string {
30
30
value , ok := object .GetAnnotations ()[key ]
31
31
if ! ok {
32
32
return ""
33
33
}
34
-
35
34
return value
36
35
}
37
36
38
- func SetAnnotations (spec Versioned , annotations map [string ]string , kubeClient client.Client ) error {
39
- currentObject := spec
40
- err := kubeClient .Get (context .TODO (), spec .NamespacedName () , currentObject )
37
+ func SetAnnotations (object client. Object , annotations map [string ]string , kubeClient client.Client ) error {
38
+ currentObject := object
39
+ err := kubeClient .Get (context .TODO (), types .NamespacedName { Name : object . GetName (), Namespace : object . GetNamespace ()} , currentObject )
41
40
if err != nil {
42
41
return err
43
42
}
44
43
45
44
// If the object has no annotations, we first need to create an empty entry in
46
45
// metadata.annotations, otherwise the server will reject our request
47
- payload := []patchValue {}
46
+ var payload []patchValue
48
47
if currentObject .GetAnnotations () == nil || len (currentObject .GetAnnotations ()) == 0 {
49
48
payload = append (payload , patchValue {
50
49
Op : "replace" ,
@@ -68,7 +67,7 @@ func SetAnnotations(spec Versioned, annotations map[string]string, kubeClient cl
68
67
}
69
68
70
69
patch := client .RawPatch (types .JSONPatchType , data )
71
- return kubeClient .Patch (context .TODO (), spec , patch )
70
+ return kubeClient .Patch (context .TODO (), object , patch )
72
71
}
73
72
74
73
func UpdateLastAppliedMongoDBVersion (mdb Versioned , kubeClient client.Client ) error {
@@ -78,3 +77,4 @@ func UpdateLastAppliedMongoDBVersion(mdb Versioned, kubeClient client.Client) er
78
77
79
78
return SetAnnotations (mdb , annotations , kubeClient )
80
79
}
80
+
0 commit comments