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

Fix the backport of #4512 into release-2.2 branch #4590

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion controllers/awsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, i
}
annotations[volumeID] = newAnnotation
} else {
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), make(map[string]interface{}), machine.Spec.AdditionalTags)
newAnnotation, err := r.ensureVolumeTags(ec2svc, aws.String(volumeID), make(map[string]interface{}), additionalTags)
if err != nil {
r.Log.Error(err, "Failed to fetch the changed volume tags in EC2 instance")
}
Expand Down
25 changes: 16 additions & 9 deletions controllers/awsmachine_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,34 +481,41 @@ func TestAWSMachineReconciler(t *testing.T) {
}
})

t.Run("should tag instances from machine and cluster tags", func(t *testing.T) {
t.Run("should tag instances and volumes with machine and cluster tags", func(t *testing.T) {
g := NewWithT(t)
awsMachine := getAWSMachine()
setup(t, g, awsMachine)
defer teardown(t, g)
instanceCreate(t, g)
getCoreSecurityGroups(t, g)

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

ec2Svc.EXPECT().GetAdditionalSecurityGroupsIDs(gomock.Any()).Return(nil, nil)

// expect one call first to tag the instance and two calls for tagging each of two volumes
// the volumes get the tags from the AWSCluster _and_ the AWSMachine

ec2Svc.EXPECT().UpdateResourceTags(
gomock.Any(),
PointsTo("myMachine"),
map[string]string{
"kind": "alicorn",
"colour": "pink",
"shape": "round",
"kind": "alicorn",
},
map[string]string{},
).Return(nil).Times(2)
).Return(nil)

ec2Svc.EXPECT().UpdateResourceTags(
PointsTo("myMachine"),
gomock.Any(),
map[string]string{
"colour": "lavender",
"colour": "pink",
"shape": "round",
"kind": "alicorn",
},
map[string]string{},
).Return(nil)
).Return(nil).Times(2)

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