Skip to content

Commit 6f390f2

Browse files
authored
Changed SetAnnotations method signature (#755)
1 parent 5f15071 commit 6f390f2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/kube/annotations/annotations.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,24 @@ const (
2626
LastAppliedMongoDBVersion = "mongodb.com/v1.lastAppliedMongoDBVersion"
2727
)
2828

29-
func GetAnnotation(object Versioned, key string) string {
29+
func GetAnnotation(object client.Object, key string) string {
3030
value, ok := object.GetAnnotations()[key]
3131
if !ok {
3232
return ""
3333
}
34-
3534
return value
3635
}
3736

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)
4140
if err != nil {
4241
return err
4342
}
4443

4544
// If the object has no annotations, we first need to create an empty entry in
4645
// metadata.annotations, otherwise the server will reject our request
47-
payload := []patchValue{}
46+
var payload []patchValue
4847
if currentObject.GetAnnotations() == nil || len(currentObject.GetAnnotations()) == 0 {
4948
payload = append(payload, patchValue{
5049
Op: "replace",
@@ -68,7 +67,7 @@ func SetAnnotations(spec Versioned, annotations map[string]string, kubeClient cl
6867
}
6968

7069
patch := client.RawPatch(types.JSONPatchType, data)
71-
return kubeClient.Patch(context.TODO(), spec, patch)
70+
return kubeClient.Patch(context.TODO(), object, patch)
7271
}
7372

7473
func UpdateLastAppliedMongoDBVersion(mdb Versioned, kubeClient client.Client) error {
@@ -78,3 +77,4 @@ func UpdateLastAppliedMongoDBVersion(mdb Versioned, kubeClient client.Client) er
7877

7978
return SetAnnotations(mdb, annotations, kubeClient)
8079
}
80+

0 commit comments

Comments
 (0)