Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWSCluster AdditionalTags are not propagated to AWSMachine storage volumes #4511

Closed
philjb opened this issue Sep 21, 2023 · 1 comment · Fixed by #4512
Closed

AWSCluster AdditionalTags are not propagated to AWSMachine storage volumes #4511

philjb opened this issue Sep 21, 2023 · 1 comment · Fixed by #4512
Labels
needs-priority triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@philjb
Copy link
Contributor

philjb commented Sep 21, 2023

Bug Description

The AWSCluster resources has a spec.AdditionalTags k-v map that is a place end users (aka me!) can place kvs that I want to use as resource tags in AWS (mostly for cost tracking).

The idea is that these tags are propagated to all resources descendent from the AWSCluster, such as ec2 instances and their root storage volumes.

Today, these tags make it to ec2 instances but not the root storage volumes. Only the awsmachine.spec.AdditionalTags make it to the root storage volumes. The layering of AdditionalTags is great for providing overrides (or additions) at various levels but the AdditionalTags from the AWSCluster should propagate to all resources.

I believe this is a bug; but I could imagine someone arguing that it is a design choice - it would be a surprising one and one that creates more work for the end user (as the user would need to explicitly also set AdditionalTags on the AWSMachine manifest).

Fix

This is an easy fix. See PR shortly.

Here's the ensureStorageTags method which only pulls tags from the machine L1121.

func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, instance *infrav1.Instance, machine *infrav1.AWSMachine) {
annotations, err := r.machineAnnotationJSON(machine, VolumeTagsLastAppliedAnnotation)
if err != nil {
r.Log.Error(err, "Failed to fetch the annotations for volume tags")
}
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)
if err != nil {
r.Log.Error(err, "Failed to fetch the changed volume tags in EC2 instance")
}
annotations[volumeID] = newAnnotation
} else {
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), make(map[string]interface{}), machine.Spec.AdditionalTags)
if err != nil {
r.Log.Error(err, "Failed to fetch the changed volume tags in EC2 instance")
}
annotations[volumeID] = newAnnotation
}
// We also need to update the annotation if anything changed.
err = r.updateMachineAnnotationJSON(machine, VolumeTagsLastAppliedAnnotation, annotations)
if err != nil {
r.Log.Error(err, "Failed to fetch the changed volume tags in EC2 instance")
}
}
}

Just above its callsite, you can see that for ec2 instances the ensureTags method merges tags from the machine with those from the cluster through machineScope.AdditionalTags().

_, err = r.ensureTags(ec2svc, machineScope.AWSMachine, machineScope.GetInstanceID(), machineScope.AdditionalTags())
if err != nil {
machineScope.Error(err, "failed to ensure tags")
return ctrl.Result{}, err
}
if instance != nil {
r.ensureStorageTags(ec2svc, instance, machineScope.AWSMachine)
}

Prior work

The ensureStorageTags method was introduced in this PR: #2463

@k8s-ci-robot k8s-ci-robot added needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 21, 2023
philjb added a commit to philjb/cluster-api-provider-aws that referenced this issue Sep 21, 2023
@Skarlso
Copy link
Contributor

Skarlso commented Sep 22, 2023

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-priority triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants