@@ -26,6 +26,7 @@ import (
26
26
ignTypes "github.com/flatcar/ignition/config/v2_3/types"
27
27
"github.com/go-logr/logr"
28
28
"github.com/google/go-cmp/cmp"
29
+ "github.com/google/go-cmp/cmp/cmpopts"
29
30
"github.com/pkg/errors"
30
31
corev1 "k8s.io/api/core/v1"
31
32
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -1112,12 +1113,13 @@ func (r *AWSMachineReconciler) indexAWSMachineByInstanceID(o client.Object) []st
1112
1113
}
1113
1114
1114
1115
func (r * AWSMachineReconciler ) ensureStorageTags (ec2svc services.EC2Interface , instance * infrav1.Instance , machine * infrav1.AWSMachine , additionalTags map [string ]string ) {
1115
- annotations , err := r .machineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation )
1116
+ prevAnnotations , err := r .machineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation )
1116
1117
if err != nil {
1117
1118
r .Log .Error (err , "Failed to fetch the annotations for volume tags" )
1118
1119
}
1120
+ annotations := make (map [string ]interface {}, len (instance .VolumeIDs ))
1119
1121
for _ , volumeID := range instance .VolumeIDs {
1120
- if subAnnotation , ok := annotations [volumeID ].(map [string ]interface {}); ok {
1122
+ if subAnnotation , ok := prevAnnotations [volumeID ].(map [string ]interface {}); ok {
1121
1123
newAnnotation , err := r .ensureVolumeTags (ec2svc , aws .String (volumeID ), subAnnotation , additionalTags )
1122
1124
if err != nil {
1123
1125
r .Log .Error (err , "Failed to fetch the changed volume tags in EC2 instance" )
@@ -1130,7 +1132,9 @@ func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, i
1130
1132
}
1131
1133
annotations [volumeID ] = newAnnotation
1132
1134
}
1135
+ }
1133
1136
1137
+ if ! cmp .Equal (prevAnnotations , annotations , cmpopts .EquateEmpty ()) {
1134
1138
// We also need to update the annotation if anything changed.
1135
1139
err = r .updateMachineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation , annotations )
1136
1140
if err != nil {
0 commit comments