-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(eks): missing VPC permissions for fargate profiles #6074
fix(eks): missing VPC permissions for fargate profiles #6074
Conversation
Title does not follow the guidelines of Conventional Commits. Please adjust title before merge. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I am wondering if this actually solves the root cause. It sounds like addFargateProfile cannot be used more than once against a cluster because CFN will always try to create all the profiles at once.
So, either we simply remove this capability (and perhaps allow people to specific an array of profile options) or we somehow discover all the profiles associated with a cluster a serialize their creation by adding explicit dependencies between them. I prefer the latter option.
// WHEN | ||
new eks.FargateCluster(stack, 'FargateCluster', { | ||
fargateProfile: { | ||
fargateProfileName: 'custom', selectors: [{namespace: 'foo'}, {namespace: 'bar'}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a unit test that covers the case where fargateProfileName is not specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eladb Sure. Should I drop the fargate
prefix as well given this comment?
edit: Oops, disregard. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
* @default - A profile called "default" with 'default' and 'kube-system' | ||
* selectors will be created if this is left undefined. | ||
*/ | ||
readonly fargateProfile?: FargateProfileOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be called “defaultProfile” instead (since this is a fargate cluster the “fargate” prefix is not needed and we usually reserve it to resource attributes (like the physical name))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eladb A case could probably be made for simply calling it profile
too, I think. If leaving the value empty results in the same thing being created every time and having the name default
, then what you'd be passing as options isn't really the default. That's why I went with fargateProfile
instead of defaultProfile
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the PR to use defaultProfile
instead of fargateProfile
.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Occurs when passing `vpc` to create Fargate Profile w/o providing subnets
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
I created #6084 to track the comprehensive root cause fix.I'm leaving my original response below for posterity, but let's keep any further discussion in #6084. :)
|
@michaelmoussa wrote:
Yes, totally fine. Could you just raise a bug titled “can’t define a fargate cluster with more than one profile” and I’ll take it from there. |
Thank you for contributing! Your pull request is now being automatically merged. |
This pull request addresses a couple of issues affecting the
FargateCluster
andFargateProfile
constructs. This excerpt will reproduce the problems:The expected outcome is:
default
profile created byFargateCluster
my-app
associated to the new cluster.Instead, there's a race to see which error will occur first:
default
Fargate profile fails to be created because themy-app
Fargate profile creation is already in progress (or vice-versa, depending on which one ended up starting first)default
Fargate profile fails to be created due to aMissing permissions for "ec2:DescribeSubnets"
(or vice-versa, depending on which one ended up starting first and whether or not it manages to get to that step before the "profile creation already in progress" error pops up).The first error occurs because you cannot create multiple Fargate profiles at the same time, and the 2nd profile doesn't want for the 1st to finish being created before starting. This isn't a problem if the
default
profile thatFargateCluster
creates for you satisfies all your needs; however, if it doesn't, there doesn't appear to be a way to customize it, making theFargateCluster
construct unusable here. The second error occurs because theFargateProfile
constructor usesprops.vpc.selectSubnets(...)
to determine which subnets to use for placement of the pods, and the IAM Role being used doesn't include theec2:DescribeSubnets
permission.This PR addresses both of these issues by adding the missing
ec2:DescribeSubnets
permission, as well as allowing you to define how you'd like the default profile to be created (e.g. specifying themy-app
namespace, some subnets, etc).NOTE: If you've stumbled upon this PR after encountering the same issue and it has not yet been merged, you can work around the issue by using the
Cluster
construct instead ofFargateCluster
, setting{coreDnsComputeType: CoreDnsComputeType.FARGATE, defaultCapacity: 0, kubectlEnabled: true}
in theClusterProps
, and then creating theFargateProfile
yourself with{subnetSelection: {subnets: vpc.privateSubnets}}
in theFargateProfileOptions
. Be sure to also include{namespace: 'default'}
and{namespace: 'kube-system'}
in the profile's selectors, as theCluster
construct does not automatically create a Fargate profile for you!By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license