Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ecs): allow selecting Bottlerocket via machineImage #16038

Merged
merged 2 commits into from
Aug 13, 2021

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Aug 13, 2021

As introduced in #10097, Bottlerocket had to be explicitly (and only) selected
via setting machineImageType, which would pick an appropriate
machineImage.

Setting machineImage to new BottleRocketImage() would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if machineImageType was set.

This method of configuration does not allow customization of the AMI,
such as introduced in #16021.

Instead, we reverse the logic: machineImageType may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what machineImage is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Previously, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in #16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.
@rix0rrr rix0rrr requested a review from a team August 13, 2021 11:50
@rix0rrr rix0rrr self-assigned this Aug 13, 2021
@gitpod-io
Copy link

gitpod-io bot commented Aug 13, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 13, 2021
// Do 2-way defaulting here: if the machineImageType is BOTTLEROCKET, pick the right AMI.
// Otherwise, determine the machineImageType from the given AMI.
const machineImage = options.machineImage ??
(options.machineImageType === MachineImageType.BOTTLEROCKET ? new BottleRocketImage() : new EcsOptimizedAmi());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens now if both machineImage and machineType are specified but they don't match?

Also, given the type below in line 303, should we use EcsOptimizedImage.amazonLinux2(), instead, to make the connection between the two more explicit?

Copy link
Contributor Author

@rix0rrr rix0rrr Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens now if both machineImage and machineType are specified but they don't match?

User's responsibility. I think we need this flexibility in case people have MyCustomBottleRocketImage for which the instanceof check would fail.

Also, given the type below in line 303, should we use EcsOptimizedImage.amazonLinux2(), instead, to make the connection between the two more explicit?

Maybe. I think the code is the way it is because we're afraid of breaking existing templates. Not inclined to change anything there, honestly.

@rix0rrr rix0rrr requested review from otaviomacedo and a team August 13, 2021 14:06
@mergify
Copy link
Contributor

mergify bot commented Aug 13, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6b2c243
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 9618fd4 into master Aug 13, 2021
@mergify mergify bot deleted the huijbers/bottle-rocket-type branch August 13, 2021 15:26
@mergify
Copy link
Contributor

mergify bot commented Aug 13, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
As introduced in aws#10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in aws#16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Sep 6, 2021
As introduced in aws#10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in aws#16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
david-doyle-as24 pushed a commit to david-doyle-as24/aws-cdk that referenced this pull request Sep 7, 2021
As introduced in aws#10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in aws#16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants