diff --git a/pkg/providers/amifamily/resolver.go b/pkg/providers/amifamily/resolver.go index cf41e7afa4c1..87b14da0e77e 100644 --- a/pkg/providers/amifamily/resolver.go +++ b/pkg/providers/amifamily/resolver.go @@ -165,8 +165,6 @@ func (r Resolver) Resolve(ctx context.Context, nodeTemplate *v1alpha1.AWSNodeTem DetailedMonitoring: aws.BoolValue(nodeTemplate.Spec.DetailedMonitoring), AMIID: amiID, InstanceTypes: instanceTypes, - LicenseSpecifications: nodeTemplate.Spec.LicenseSpecifications, - Placement: Placement{HostResourceGroupArn: nodeTemplate.Spec.Placement.HostResourceGroupArn}, } if resolved.BlockDeviceMappings == nil { resolved.BlockDeviceMappings = amiFamily.DefaultBlockDeviceMappings() @@ -174,6 +172,12 @@ func (r Resolver) Resolve(ctx context.Context, nodeTemplate *v1alpha1.AWSNodeTem if resolved.MetadataOptions == nil { resolved.MetadataOptions = amiFamily.DefaultMetadataOptions() } + if len(nodeTemplate.Spec.LicenseSpecifications) > 0 { + resolved.LicenseSpecifications = nodeTemplate.Spec.LicenseSpecifications + } + if nodeTemplate.Spec.Placement.HostResourceGroupArn != "" { + resolved.Placement = Placement{HostResourceGroupArn: nodeTemplate.Spec.Placement.HostResourceGroupArn} + } resolvedTemplates = append(resolvedTemplates, resolved) } } diff --git a/pkg/providers/launchtemplate/launchtemplate.go b/pkg/providers/launchtemplate/launchtemplate.go index 5dd5c839c625..3a639f99797c 100644 --- a/pkg/providers/launchtemplate/launchtemplate.go +++ b/pkg/providers/launchtemplate/launchtemplate.go @@ -240,9 +240,7 @@ func (p *Provider) createLaunchTemplate(ctx context.Context, options *amifamily. {ResourceType: aws.String(ec2.ResourceTypeNetworkInterface), Tags: utils.MergeTags(options.Tags)}, }, LicenseSpecifications: createLicenseSpecifications(options.LicenseSpecifications), - Placement: &ec2.LaunchTemplatePlacementRequest{ - HostResourceGroupArn: aws.String(options.Placement.HostResourceGroupArn), - }, + Placement: createPlacement(&options.Placement), }, TagSpecifications: []*ec2.TagSpecification{ { @@ -277,6 +275,9 @@ func (p *Provider) generateNetworkInterface(options *amifamily.LaunchTemplate) [ } func createLicenseSpecifications(licenseSpecifications []string) []*ec2.LaunchTemplateLicenseConfigurationRequest { + if len(licenseSpecifications) == 0 { + return nil + } output := []*ec2.LaunchTemplateLicenseConfigurationRequest{} for _, s := range licenseSpecifications { output = append(output, &ec2.LaunchTemplateLicenseConfigurationRequest{LicenseConfigurationArn: aws.String(s)}) @@ -284,6 +285,15 @@ func createLicenseSpecifications(licenseSpecifications []string) []*ec2.LaunchTe return output } +func createPlacement(placement *amifamily.Placement) *ec2.LaunchTemplatePlacementRequest { + if placement == nil || placement.HostResourceGroupArn == "" { + return nil + } + return &ec2.LaunchTemplatePlacementRequest{ + HostResourceGroupArn: aws.String(placement.HostResourceGroupArn), + } +} + func (p *Provider) blockDeviceMappings(blockDeviceMappings []*v1alpha1.BlockDeviceMapping) []*ec2.LaunchTemplateBlockDeviceMappingRequest { if len(blockDeviceMappings) == 0 { // The EC2 API fails with empty slices and expects nil.