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

feat(ecs): container dependencies #3032

Merged
merged 6 commits into from
Aug 5, 2019
Merged

feat(ecs): container dependencies #3032

merged 6 commits into from
Aug 5, 2019

Conversation

Don-CA
Copy link
Contributor

@Don-CA Don-CA commented Jun 24, 2019

Add new addContainerDependencies method to allow for container dependencies
Fixes #2490


  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
  • Docs
    • jsdocs: All public APIs documented
  • Title and Description
    • Change type: title prefixed with fix, feat and module name in parens, which will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"

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


@Don-CA Don-CA requested review from SoManyHs and a team as code owners June 24, 2019 12:32
@cohalz
Copy link
Contributor

cohalz commented Jul 9, 2019

👍

Copy link
Contributor

@piradeepk piradeepk left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to make these changes and I'm sorry for the delay in reviewing the change. Overall everything looks great, just had a couple comments!

@Don-CA Don-CA requested a review from a team as a code owner July 17, 2019 12:39
Copy link
Contributor

@piradeepk piradeepk left a comment

Choose a reason for hiding this comment

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

@Don-CA, Thanks for the hard work and for addressing this issue, it's really appreciated!

LGTM! @rix0rrr please review and merge

/**
* This method adds one or more container dependencies to the container.
*/
public addContainerDependencies(...containerDependencies: ContainerDependency[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add an optional array property to the Props object to initialize these.

Copy link
Contributor Author

@Don-CA Don-CA Jul 18, 2019

Choose a reason for hiding this comment

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

See my comment below, I'm keeping it consistent with similar properties but open to refactoring all the properties to output cleaner cloudformation.

@@ -418,6 +430,7 @@ export class ContainerDefinition extends cdk.Construct {
command: this.props.command,
cpu: this.props.cpu,
disableNetworking: this.props.disableNetworking,
dependsOn: this.containerDependencies.map(renderContainerDependency),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't render the property at all if the list is empty.

Copy link
Contributor Author

@Don-CA Don-CA Jul 18, 2019

Choose a reason for hiding this comment

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

I was unsure about this. Rendering an empty list keeps in consistent with Links, MountPoints and VolumesFrom however it results in a noisy change to the tests.
I'm happy to make it different to the other three and then do further PR to make the other three not output if their list is empty, would you be open to that?

Copy link
Contributor Author

@Don-CA Don-CA Jul 18, 2019

Choose a reason for hiding this comment

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

Or, leave it as is, and refactor all four as a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer not to render empty arrays/objects. Would be great to fix the others as well...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, cool. I can fix the others as well as part of this PR.

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

A few notes

@@ -230,6 +230,7 @@
"Properties": {
"ContainerDefinitions": [
{
"DependsOn": [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Preferably don't render if the array is empty

/**
* An array dependencies defined for container startup and shutdown.
*/
public readonly containerDependencies = Array<ContainerDependency>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I am only now realizing that all of these are exposing mutable arrays to users... Not ideal. @rix0rrr what do you think?

@@ -418,6 +430,7 @@ export class ContainerDefinition extends cdk.Construct {
command: this.props.command,
cpu: this.props.cpu,
disableNetworking: this.props.disableNetworking,
dependsOn: this.containerDependencies.map(renderContainerDependency),
Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer not to render empty arrays/objects. Would be great to fix the others as well...

/**
* The container to depend on.
*/
readonly container: ContainerDefinition,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ; for EOL

* The dependency condition of the container. Valid values are ContainerDependencyCondition.START, ContainerDependencyCondition.COMPLETE,
* ContainerDependencyCondition.SUCCESS and ContainerDependencyCondition.HEALTHY.
*
* @default - ContainerDependencyCondition.HEALTHY
Copy link
Contributor

Choose a reason for hiding this comment

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

We only use - when it's not a "real" value. In your case you are actually providing a value...

*/
readonly container: ContainerDefinition,
/**
* The dependency condition of the container. Valid values are ContainerDependencyCondition.START, ContainerDependencyCondition.COMPLETE,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the dependency condition? Can you copy & paste from AWS docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a copy & paste from the docs :) Added some more of my own context.

@eladb
Copy link
Contributor

eladb commented Jul 23, 2019

See some review comments

Copy link
Contributor

@piradeepk piradeepk left a comment

Choose a reason for hiding this comment

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

Can you add tests to ensure that MountPoints, Links, etc still continue to render correctly if populated?

@Don-CA
Copy link
Contributor Author

Don-CA commented Jul 30, 2019

Can you add tests to ensure that MountPoints, Links, etc still continue to render correctly if populated?

Added tests for VolumesFrom and Links.
There are already existing tests for the rest:

MountPoints

Volumes

PortMappings

Ulimits

Copy link
Contributor

@piradeepk piradeepk left a comment

Choose a reason for hiding this comment

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

Thanks for adding the tests! @eladb please review

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

I really don’t like it that we expose all these public arrays. That’s an anti pattern because it exposes an internal mutable structure

@@ -469,15 +482,15 @@ export class ContainerDefinition extends cdk.Construct {
image: this.imageConfig.imageName,
memory: this.props.memoryLimitMiB,
memoryReservation: this.props.memoryReservationMiB,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn’t these be Lazy? What happens if you add something to the array after initialization?


function renderContainerDependency(containerDependency: ContainerDependency): CfnTaskDefinition.ContainerDependencyProperty {
return {
containerName: containerDependency.container.node.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

If the name of the container is similar to the node ID that’s a detail that needs to be encapsulated behind a container.containerName property

Copy link
Contributor Author

@Don-CA Don-CA Jul 31, 2019

Choose a reason for hiding this comment

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

Would this also apply to the reference to container.node.id in addLink and in validate() in TaskDefinition?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please!

@Don-CA
Copy link
Contributor Author

Don-CA commented Jul 31, 2019

I really don’t like it that we expose all these public arrays. That’s an anti pattern because it exposes an internal mutable structure

I took all those arrays private and all the tests still ran, what do you think of doing that? It would create some breaking changes, would that be acceptable?

@eladb
Copy link
Contributor

eladb commented Aug 1, 2019

I don't think it will be acceptable to break this public API sadly. What we can do is mark them as @deprecated so people don't rely on them and we will get rid of it in v2.0 sometime in the future.

@eladb
Copy link
Contributor

eladb commented Aug 1, 2019

Apologies for the confusion... I was just venting ;-)

@NGL321 NGL321 added the pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason. label Aug 1, 2019
@Don-CA
Copy link
Contributor Author

Don-CA commented Aug 3, 2019

Apologies for the confusion... I was just venting ;-)

No worries, reverted those changes :)

@eladb eladb changed the title feat(ecs): add support for container dependencies feat(ecs): container dependencies Aug 5, 2019
@eladb eladb merged commit 56656e0 into aws:master Aug 5, 2019
eladb pushed a commit that referenced this pull request Aug 6, 2019
Add new addContainerDependencies method to allow for container dependencies
Fixes #2490
mergify bot pushed a commit that referenced this pull request Aug 7, 2019
* chore: update package-lock.json

* feat(eks): define kubernetes resources

This change allows defining arbitrary Kubernetes resources within an EKS cluster.

* nice!

* update readme

* Update README.md

* feat(events): ability to add cross-account targets (#3323)

This adds the capability of adding a target to an event rule
that belongs to a different account than the rule itself.
Required for things like cross-account CodePipelines with source actions triggered by events.

* chore(ci): add mergify config file (#3502)

* chore: update jsii to 0.14.3 (#3513)

* fix(iam): correctly limit the default PolicyName to 128 characters (#3487)

Our logic for trimming the length of the default IAM policy name was not working,
as it wasn't updated when logicalId became a Token rather than a literate string,
and so it was never actually triggered
(it just checked that the display name of the Token was less than 128 characters,
which it always is).
The fix is to resolve the logical ID Token before applying the trimming logic.

Fixes #3402

* v1.3.0 (#3516)

See CHANGELOG

* fix: typo in restapi.ts (#3530)

* feat(ecs): container dependencies (#3032)

Add new addContainerDependencies method to allow for container dependencies
Fixes #2490

* feat(s3-deployment): CloudFront invalidation (#3213)

see #3106

* docs(core): findChild gets direct child only (#3512)

* doc(iam): update references to addManagedPolicy (#3511)

* fix(sqs): do not emit grants to the AWS-managed encryption key (#3169)

Grants on the `alias/aws/sqs` KMS key alias are not necessary since the
key will implicitly allow for it's intended usage to be fulfilled (as
opposed to how you have to manage grants yourself when using a
user-managed key instead).

This removes the statement that was generated using an invalid resource
entry.

Fixes #2794

* fix(lambda): allow ArnPrincipal in grantInvoke (#3501)

Fixes #3264 

I'm trying to allow a lambda function in another account to be able to invoke my CDK generated lambda function. This works through the CLI like so:

    aws lambda add-permission --function-name=myFunction --statement-id=ABoldStatement --action=lambda:InvokeFunction --principal=arn:aws:iam::{account_id}:role/a_lambda_execution_role

But CDK doesn't seem to allow me to add an ArnPrincipal doing something like this:

    myFunction.grantInvoke(new iam.ArnPrincipal(props.myARN))

With the error:

    Invalid principal type for Lambda permission statement: ArnPrincipal. Supported: AccountPrincipal, ServicePrincipal

This PR allows ArnPrincipal to be passed to lambda.grantInvoke.

There might be some additional validation required on the exact ARN as I believe only some ARNs are supported by lambda add-permission

* chore(contrib): remove API stabilization disclaimer

* fix(ssm): add GetParameters action to grantRead() (#3546)

* misc

* rename `KubernetesManifest` to `KubernetesResource` and `addResource`
* move AWS Auth APIs to `cluster.awsAuth` and expose `AwsAuth`
* remove the yaml library (we can just use a JSON stream)
* add support for adding accounts to aws-auth
* fix cluster deletion bug
* move kubctl app info to constants

* addManifest => addResource

* update test expectations

* add unit test for customresrouce.ref

* fix sample link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to add dependsOn to container definitoin
7 participants