Merge "aws: Reduce number of launch template variants"
This commit is contained in:
commit
8dce420004
3 files changed
+35
-24
No files matched your search
+1
-1
@@ -49,4 +49,4 @@ rackspaceauth
|
||||
# For openshift driver
|
||||
openshift
|
||||
# For AWS driver
|
||||
boto3>=1.42.48
|
||||
boto3>=1.43.45
|
||||
@@ -349,12 +349,20 @@ class TestAwsDriver(AwsBaseTest):
|
||||
self.assertTrue(pnode.node_properties['instance_id'].startswith('i-'))
|
||||
self.assertTrue(
|
||||
pnode.node_properties['ebs_volume_id'].startswith('vol-'))
|
||||
instance = self.ec2_client.describe_instance_attribute(
|
||||
InstanceId=pnode.aws_instance_id,
|
||||
Attribute='userData',
|
||||
)
|
||||
expected = base64.b64encode(b'testuserdata').decode('utf8')
|
||||
self.assertEqual(expected, instance['UserData']['Value'])
|
||||
# TODO: if this PR is merged:
|
||||
# https://github.com/getmoto/moto/pull/10245
|
||||
# Then remove the following assertion and replace with this:
|
||||
# instance = self.ec2_client.describe_instance_attribute(
|
||||
# InstanceId=pnode.aws_instance_id,
|
||||
# Attribute='userData',
|
||||
# )
|
||||
# self.assertEqual(expected, instance['UserData']['Value'])
|
||||
self.assertEqual(
|
||||
expected,
|
||||
self.create_fleet_calls[0]['LaunchTemplateConfigs'][0][
|
||||
'LaunchTemplateSpecification'][
|
||||
'LaunchTemplateSpecificationUserData'])
|
||||
|
||||
@simple_layout('layouts/aws/fleet.yaml', enable_nodepool=True)
|
||||
@okay_tracebacks('MissingParameter')
|
||||
|
||||
@@ -2069,29 +2069,11 @@ class AwsProviderEndpoint(BaseProviderEndpoint):
|
||||
if label.security_group_ids:
|
||||
template_data['SecurityGroupIds'] = label.security_group_ids
|
||||
|
||||
if label.imds_http_tokens == 'required':
|
||||
template_data['MetadataOptions'] = {
|
||||
'HttpTokens': 'required',
|
||||
'HttpEndpoint': 'enabled',
|
||||
'HttpProtocolIpv6': 'enabled',
|
||||
}
|
||||
elif label.imds_http_tokens == 'optional':
|
||||
template_data['MetadataOptions'] = {
|
||||
'HttpTokens': 'optional',
|
||||
'HttpEndpoint': 'enabled',
|
||||
'HttpProtocolIpv6': 'enabled',
|
||||
}
|
||||
|
||||
if flavor.nested_virtualization:
|
||||
template_data['CpuOptions'] = {
|
||||
'NestedVirtualization': 'enabled'
|
||||
}
|
||||
|
||||
if label.userdata:
|
||||
userdata_base64 = base64.b64encode(
|
||||
label.userdata.encode('utf-8')).decode('utf-8')
|
||||
template_data['UserData'] = userdata_base64
|
||||
|
||||
template_args = dict(
|
||||
LaunchTemplateData=template_data,
|
||||
TagSpecifications=[
|
||||
@@ -2189,6 +2171,19 @@ class AwsProviderEndpoint(BaseProviderEndpoint):
|
||||
override_dict['Priority'] = priority
|
||||
priority += 1
|
||||
|
||||
if label.imds_http_tokens == 'required':
|
||||
override_dict['MetadataOptions'] = {
|
||||
'HttpTokens': 'required',
|
||||
'HttpEndpoint': 'enabled',
|
||||
'HttpProtocolIpv6': 'enabled',
|
||||
}
|
||||
elif label.imds_http_tokens == 'optional':
|
||||
override_dict['MetadataOptions'] = {
|
||||
'HttpTokens': 'optional',
|
||||
'HttpEndpoint': 'enabled',
|
||||
'HttpProtocolIpv6': 'enabled',
|
||||
}
|
||||
|
||||
# Duplicate overrides for each subnet
|
||||
if label.subnet_ids:
|
||||
for subnet_id in label.subnet_ids:
|
||||
@@ -2220,6 +2215,13 @@ class AwsProviderEndpoint(BaseProviderEndpoint):
|
||||
},
|
||||
}
|
||||
|
||||
extra_launch_template_spec = {}
|
||||
if label.userdata:
|
||||
userdata_base64 = base64.b64encode(
|
||||
label.userdata.encode('utf-8')).decode('utf-8')
|
||||
extra_launch_template_spec[
|
||||
"LaunchTemplateSpecificationUserData"] = userdata_base64
|
||||
|
||||
args = {
|
||||
**capacity_type_option,
|
||||
'LaunchTemplateConfigs': [
|
||||
@@ -2227,6 +2229,7 @@ class AwsProviderEndpoint(BaseProviderEndpoint):
|
||||
'LaunchTemplateSpecification': {
|
||||
'LaunchTemplateName': launch_template_name,
|
||||
'Version': '$Latest',
|
||||
**extra_launch_template_spec,
|
||||
},
|
||||
'Overrides': overrides,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user