Skip to content

Commit c0fdc9a

Browse files
authored
Merge pull request #4590 from cnmcavoy/cmcavoy/fix-cherry-pick-4512
Fix the backport of #4512 into release-2.2 branch
2 parents cbfda4a + b44cfd3 commit c0fdc9a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

controllers/awsmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, i
11261126
}
11271127
annotations[volumeID] = newAnnotation
11281128
} else {
1129-
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), make(map[string]interface{}), machine.Spec.AdditionalTags)
1129+
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), make(map[string]interface{}), additionalTags)
11301130
if err != nil {
11311131
r.Log.Error(err, "Failed to fetch the changed volume tags in EC2 instance")
11321132
}

controllers/awsmachine_controller_unit_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,34 +481,41 @@ func TestAWSMachineReconciler(t *testing.T) {
481481
}
482482
})
483483

484-
t.Run("should tag instances from machine and cluster tags", func(t *testing.T) {
484+
t.Run("should tag instances and volumes with machine and cluster tags", func(t *testing.T) {
485485
g := NewWithT(t)
486486
awsMachine := getAWSMachine()
487487
setup(t, g, awsMachine)
488488
defer teardown(t, g)
489489
instanceCreate(t, g)
490490
getCoreSecurityGroups(t, g)
491491

492-
ms.AWSMachine.Spec.AdditionalTags = infrav1.Tags{"kind": "alicorn"}
493-
cs.AWSCluster.Spec.AdditionalTags = infrav1.Tags{"colour": "lavender"}
492+
ms.AWSMachine.Spec.AdditionalTags = infrav1.Tags{"kind": "alicorn", "colour": "pink"} // takes precedence
493+
cs.AWSCluster.Spec.AdditionalTags = infrav1.Tags{"colour": "lavender", "shape": "round"}
494494

495495
ec2Svc.EXPECT().GetAdditionalSecurityGroupsIDs(gomock.Any()).Return(nil, nil)
496+
497+
// expect one call first to tag the instance and two calls for tagging each of two volumes
498+
// the volumes get the tags from the AWSCluster _and_ the AWSMachine
499+
496500
ec2Svc.EXPECT().UpdateResourceTags(
497-
gomock.Any(),
501+
PointsTo("myMachine"),
498502
map[string]string{
499-
"kind": "alicorn",
503+
"colour": "pink",
504+
"shape": "round",
505+
"kind": "alicorn",
500506
},
501507
map[string]string{},
502-
).Return(nil).Times(2)
508+
).Return(nil)
503509

504510
ec2Svc.EXPECT().UpdateResourceTags(
505-
PointsTo("myMachine"),
511+
gomock.Any(),
506512
map[string]string{
507-
"colour": "lavender",
513+
"colour": "pink",
514+
"shape": "round",
508515
"kind": "alicorn",
509516
},
510517
map[string]string{},
511-
).Return(nil)
518+
).Return(nil).Times(2)
512519

513520
_, err := reconciler.reconcileNormal(context.Background(), ms, cs, cs, cs, cs)
514521
g.Expect(err).To(BeNil())

0 commit comments

Comments
 (0)