Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions controllers/awsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
ignTypes "github.com/flatcar/ignition/config/v2_3/types"
"github.com/go-logr/logr"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -589,7 +590,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
}

if instance != nil {
r.ensureStorageTags(ec2svc, instance, machineScope.AWSMachine)
r.ensureStorageTags(ec2svc, instance, machineScope.AWSMachine, machineScope.AdditionalTags())
}

if err := r.reconcileLBAttachment(machineScope, elbScope, instance); err != nil {
Expand Down Expand Up @@ -802,7 +803,7 @@ func (r *AWSMachineReconciler) deleteIgnitionBootstrapDataFromS3(machineScope *s
return nil
}

// If bootstrap data has not been populated yet, we cannot determine it's format, so there is probably nothing to do.
// If bootstrap data has not been populated yet, we cannot determine its format, so there is probably nothing to do.
if machineScope.Machine.Spec.Bootstrap.DataSecretName == nil {
return nil
}
Expand Down Expand Up @@ -1111,14 +1112,15 @@ func (r *AWSMachineReconciler) indexAWSMachineByInstanceID(o client.Object) []st
return nil
}

func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, instance *infrav1.Instance, machine *infrav1.AWSMachine) {
annotations, err := r.machineAnnotationJSON(machine, VolumeTagsLastAppliedAnnotation)
func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, instance *infrav1.Instance, machine *infrav1.AWSMachine, additionalTags map[string]string) {
prevAnnotations, err := r.machineAnnotationJSON(machine, VolumeTagsLastAppliedAnnotation)
if err != nil {
r.Log.Error(err, "Failed to fetch the annotations for volume tags")
}
annotations := make(map[string]interface{}, len(instance.VolumeIDs))
for _, volumeID := range instance.VolumeIDs {
if subAnnotation, ok := annotations[volumeID].(map[string]interface{}); ok {
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), subAnnotation, machine.Spec.AdditionalTags)
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), subAnnotation, additionalTags)
Copy link
Contributor

@philjb philjb Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other side of this else was also supposed to be changed if #4512 was pulled in fully (that line and the test from that pr were not pulled in). This means release 2.2.4 contains some unapproved combination of code.

see https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/4512/files#r1369368660

if err != nil {
r.Log.Error(err, "Failed to fetch the changed volume tags in EC2 instance")
}
Expand All @@ -1130,7 +1132,9 @@ func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, i
}
annotations[volumeID] = newAnnotation
}
}

if !cmp.Equal(prevAnnotations, annotations, cmpopts.EquateEmpty()) {
// We also need to update the annotation if anything changed.
err = r.updateMachineAnnotationJSON(machine, VolumeTagsLastAppliedAnnotation, annotations)
if err != nil {
Expand Down