Skip to content

Commit

Permalink
Only set licenseSpecification and Placement when values present
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Cole committed Jun 5, 2023
1 parent b856490 commit a665d72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pkg/providers/amifamily/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,19 @@ 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()
}
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)
}
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/providers/launchtemplate/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -277,13 +275,25 @@ 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)})
}
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.
Expand Down

0 comments on commit a665d72

Please sign in to comment.