Skip to content

Commit a5c3e0a

Browse files
authored
Merge pull request #5507 from giantswarm/sshkey-change-launchtemplate
🐛 Update launch template if ssh key name changes
2 parents af82f3a + e89509c commit a5c3e0a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/cloud/services/ec2/launchtemplate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,19 @@ func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, inc
793793
if incoming.InstanceType != existing.InstanceType {
794794
return true, nil
795795
}
796+
796797
if !cmp.Equal(incoming.InstanceMetadataOptions, existing.InstanceMetadataOptions) {
797798
return true, nil
798799
}
800+
799801
if !cmp.Equal(incoming.SpotMarketOptions, existing.SpotMarketOptions) {
800802
return true, nil
801803
}
802804

805+
if !cmp.Equal(incoming.SSHKeyName, existing.SSHKeyName) {
806+
return true, nil
807+
}
808+
803809
incomingIDs, err := s.GetAdditionalSecurityGroupsIDs(incoming.AdditionalSecurityGroups)
804810
if err != nil {
805811
return false, err

pkg/cloud/services/ec2/launchtemplate_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,36 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
769769
want: true,
770770
wantErr: false,
771771
},
772+
{
773+
name: "Should return true if SSH key names are different",
774+
incoming: &expinfrav1.AWSLaunchTemplate{
775+
SSHKeyName: aws.String("new-key"),
776+
},
777+
existing: &expinfrav1.AWSLaunchTemplate{
778+
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
779+
{ID: aws.String("sg-111")},
780+
{ID: aws.String("sg-222")},
781+
},
782+
SSHKeyName: aws.String("old-key"),
783+
},
784+
want: true,
785+
wantErr: false,
786+
},
787+
{
788+
name: "Should return true if one has SSH key name and other doesn't",
789+
incoming: &expinfrav1.AWSLaunchTemplate{
790+
SSHKeyName: aws.String("new-key"),
791+
},
792+
existing: &expinfrav1.AWSLaunchTemplate{
793+
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
794+
{ID: aws.String("sg-111")},
795+
{ID: aws.String("sg-222")},
796+
},
797+
SSHKeyName: nil,
798+
},
799+
want: true,
800+
wantErr: false,
801+
},
772802
}
773803
for _, tt := range tests {
774804
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)