@@ -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"
@@ -589,7 +590,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
589
590
}
590
591
591
592
if instance != nil {
592
- r .ensureStorageTags (ec2svc , instance , machineScope .AWSMachine )
593
+ r .ensureStorageTags (ec2svc , instance , machineScope .AWSMachine , machineScope . AdditionalTags () )
593
594
}
594
595
595
596
if err := r .reconcileLBAttachment (machineScope , elbScope , instance ); err != nil {
@@ -802,7 +803,7 @@ func (r *AWSMachineReconciler) deleteIgnitionBootstrapDataFromS3(machineScope *s
802
803
return nil
803
804
}
804
805
805
- // If bootstrap data has not been populated yet, we cannot determine it's format, so there is probably nothing to do.
806
+ // If bootstrap data has not been populated yet, we cannot determine its format, so there is probably nothing to do.
806
807
if machineScope .Machine .Spec .Bootstrap .DataSecretName == nil {
807
808
return nil
808
809
}
@@ -1111,14 +1112,15 @@ func (r *AWSMachineReconciler) indexAWSMachineByInstanceID(o client.Object) []st
1111
1112
return nil
1112
1113
}
1113
1114
1114
- func (r * AWSMachineReconciler ) ensureStorageTags (ec2svc services.EC2Interface , instance * infrav1.Instance , machine * infrav1.AWSMachine ) {
1115
- annotations , err := r .machineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation )
1115
+ func (r * AWSMachineReconciler ) ensureStorageTags (ec2svc services.EC2Interface , instance * infrav1.Instance , machine * infrav1.AWSMachine , additionalTags map [ string ] string ) {
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
1122
if subAnnotation , ok := annotations [volumeID ].(map [string ]interface {}); ok {
1121
- newAnnotation , err := r .ensureVolumeTags (ec2svc , aws .String (volumeID ), subAnnotation , machine . Spec . AdditionalTags )
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" )
1124
1126
}
@@ -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