Skip to content

Commit f122d7c

Browse files
committed
Fix constant re-applying of tags if .metadata.annotations is nil (#645)
1 parent cf0fed0 commit f122d7c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

controllers/awsmachine_annotations.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"encoding/json"
21+
"maps"
2122

2223
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2324
)
@@ -40,13 +41,14 @@ func (r *AWSMachineReconciler) updateMachineAnnotationJSON(machine *infrav1.AWSM
4041
// `content`.
4142
func (r *AWSMachineReconciler) updateMachineAnnotation(machine *infrav1.AWSMachine, annotation, content string) {
4243
// Get the annotations
43-
annotations := machine.GetAnnotations()
44+
annotations := maps.Clone(machine.GetAnnotations())
4445

45-
// Set our annotation to the given content.
46-
if annotations != nil {
47-
annotations[annotation] = content
46+
if annotations == nil {
47+
annotations = map[string]string{}
4848
}
4949

50+
annotations[annotation] = content
51+
5052
// Update the machine object with these annotations
5153
machine.SetAnnotations(annotations)
5254
}

0 commit comments

Comments
 (0)