Skip to content

Commit

Permalink
Add support of creating AMI less LaunchTemplate for AWS managed nodeg…
Browse files Browse the repository at this point in the history
…roup
  • Loading branch information
mnmaheshwari committed Apr 21, 2024
1 parent a7673e1 commit b6cf17d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/cloud/services/ec2/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func (s *Service) ReconcileLaunchTemplate(
return err
}

amiChanged := *imageID != *launchTemplate.AMI.ID
// its possible that launchTemplate is created without AMI
amiChanged := false
if imageID != nil && launchTemplate.AMI.ID != nil {
amiChanged = *imageID != *launchTemplate.AMI.ID
}

// `launchTemplateUserDataSecretKey` can be nil since it comes from a tag on the launch template
// which may not exist in older launch templates created by older CAPA versions.
Expand Down Expand Up @@ -522,12 +526,14 @@ func (s *Service) createLaunchTemplateData(scope scope.LaunchTemplateScope, imag

// Set up root volume
if lt.RootVolume != nil {
rootDeviceName, err := s.checkRootVolume(lt.RootVolume, *data.ImageId)
if err != nil {
return nil, err
}
if data.ImageId != nil {
rootDeviceName, err := s.checkRootVolume(lt.RootVolume, *data.ImageId)
if err != nil {
return nil, err
}

lt.RootVolume.DeviceName = aws.StringValue(rootDeviceName)
lt.RootVolume.DeviceName = aws.StringValue(rootDeviceName)
}

req := volumeToLaunchTemplateBlockDeviceMappingRequest(lt.RootVolume)
data.BlockDeviceMappings = []*ec2.LaunchTemplateBlockDeviceMappingRequest{
Expand Down Expand Up @@ -801,6 +807,11 @@ func (s *Service) DiscoverLaunchTemplateAMI(scope scope.LaunchTemplateScope) (*s
return nil, err
}

// launch template without image ID is possible if AMIType is defined in AWSManagedMachinepool
if scope.IsEKSManaged() {
return nil, nil
}

var lookupAMI string
var err error

Expand Down

0 comments on commit b6cf17d

Please sign in to comment.