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(eks): make kubectlLayer property required from optional #32930

Merged
merged 22 commits into from
Feb 13, 2025

Conversation

xazhao
Copy link
Contributor

@xazhao xazhao commented Jan 15, 2025

Issue

#33261

Reason for this change

aws-cdk-lib has a very outdated version of kubectl layer as dependency https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/package.json#L123. It uses an outdated helm version which is involved in a CVE.

The dependency was added because if users do not provide a kubectl layer version for EKS cluster, it will use v20 as the default. CDK itself shouldn't use a specific version of kubectl layer as dependency.

To remove the dependency, kubectlLayer will become a required property instead of optional. The default version v20 is too old to work with current EKS supported version v24+. However, if you're not using the property, you will see an error saying it's a required property. Please uses a kubectl layer version that's compatible with your cluster.

Description of changes

  • Make the property required from options
  • Update unit tests and integration tests
  • Remove the dependency of "@aws-cdk/asset-kubectl-v20": "^2.1.3"

Describe any new or updated permissions being added

Description of how you validated changes

unit tests/integration tests

Checklist

BREAKING CHANGE: kubectlLayer property is now required in EKS Cluster and FargateCluster constructs. The default value for kubectlLayer is outdated and hence being removed. You can specify your own kubectlLayer version based on your Kubernetes version.


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

@aws-cdk-automation aws-cdk-automation requested a review from a team January 15, 2025 01:22
@github-actions github-actions bot added the p2 label Jan 15, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 15, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.40%. Comparing base (3fbc785) to head (4275cea).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32930   +/-   ##
=======================================
  Coverage   81.40%   81.40%           
=======================================
  Files         223      223           
  Lines       13727    13727           
  Branches     2411     2411           
=======================================
  Hits        11175    11175           
  Misses       2274     2274           
  Partials      278      278           
Flag Coverage Δ
suite.unit 81.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.74% <ø> (ø)
packages/aws-cdk-lib/core 82.10% <ø> (ø)

@aws aws deleted a comment from aws-cdk-automation Jan 15, 2025
@xazhao xazhao added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Jan 15, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 15, 2025 22:54

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@xazhao xazhao closed this Jan 15, 2025
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2025
@xazhao xazhao reopened this Jan 23, 2025
@xazhao xazhao force-pushed the remove-default-kubectlLayer branch from dc8d9d0 to 6f15da8 Compare January 31, 2025 01:04
@xazhao xazhao marked this pull request as ready for review January 31, 2025 01:04
@mrgrain mrgrain changed the title feat(eks): make kubectlLayer property required from optional feat(eks)!: make kubectlLayer property required from optional Feb 4, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

@mrgrain mrgrain changed the title feat(eks)!: make kubectlLayer property required from optional feat(eks): make kubectlLayer property required from optional Feb 4, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 4, 2025 12:53

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 11, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 11, 2025
@xazhao xazhao added pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version. pr-linter/exempt-breaking-change The PR linter will not require stability in stable modules and removed pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version. labels Feb 11, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 11, 2025 23:00

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 11, 2025
@GavinZZ GavinZZ self-assigned this Feb 12, 2025
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

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

Left some comments to help me understand.


/**
* Test verifies that kubectl and helm are invoked successfully inside Lambda runtime.
*/

const app = new cdk.App();
const stack = new cdk.Stack(app, 'lambda-layer-kubectl-integ-stack');
const layer = new KubectlLayer(stack, 'KubectlLayer');
const layer = new KubectlV31Layer(stack, 'KubectlLayer');
Copy link
Contributor

@GavinZZ GavinZZ Feb 12, 2025

Choose a reason for hiding this comment

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

For my understanding, why do we need to change this test file? Does it not work with KubectlLayer?
edit: nvm, the old layer version is outdated and have securtity concerns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

KubectlLayer construct is being removed completely from aws-cdk-lib repo. We should import it from @aws-cdk if required.

@@ -144,7 +144,6 @@ export interface ICluster extends IResource, ec2.IConnectable {
/**
* An AWS Lambda layer that includes `kubectl` and `helm`
*
* If not defined, a default layer will be used containing Kubectl 1.20 and Helm 3.8
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we choose to make this resource requried instead of coming up with a feature flag and change the default layer to a valid layer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The motivation is that old version has some security risks and should be removed from CDK dependency. So adding a feature flag doesn't solve this issue.

Changing the default layer is also a breaking change. After discussion, an error during synth is better than deploying a new version and then find something is wrong. See cdklabs/awscdk-asset-kubectl#1534 (comment)

@@ -150,7 +149,9 @@ export class KubectlProvider extends NestedStack implements IKubectlProvider {

// allow user to customize the layers with the tools we need
handler.addLayers(props.cluster.awscliLayer ?? new AwsCliLayer(this, 'AwsCliLayer'));
handler.addLayers(props.cluster.kubectlLayer ?? new KubectlLayer(this, 'KubectlLayer'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar question to above: Why don't we keep doing this but use a newer version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment above.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 13, 2025
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

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

Based on offline discussion yesterday, I think this change looks good to me.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 366d088
  • 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 b11f663 into aws:main Feb 13, 2025
20 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-breaking-change The PR linter will not require stability in stable modules pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants