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): Allow helm pull from OCI repositories #18547

Merged
merged 13 commits into from Feb 24, 2022
Merged

feat(eks): Allow helm pull from OCI repositories #18547

merged 13 commits into from Feb 24, 2022

Conversation

harshadbhatia
Copy link
Contributor

@harshadbhatia harshadbhatia commented Jan 20, 2022

The feature allows lambda to install charts from OCI repositories. This also adds login capabilities when the AWS registry is used.

Fixes - #18001


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

@gitpod-io
Copy link

gitpod-io bot commented Jan 20, 2022

@harshadbhatia
Copy link
Contributor Author

@otaviomacedo , Any updates on this ?

@@ -1144,6 +1144,24 @@ cluster.addHelmChart('test-chart', {
});
```

### OCI Charts

OCI charts are also supported. Before executing ensure the handler lambda has the required ECR IAM permissions.
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the required permissions? Can we automate that for the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They would be ecr repository permissions to be able to log in. Ideally, it
should be present on the lambda.

Copy link
Contributor

Choose a reason for hiding this comment

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

The handler role is this one:

this.handlerRole = handler.role!;

You will need to add the ecr:GetAuthorizationToken permission to it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@otaviomacedo , Done. please review

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. But the tests have to be updated now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@otaviomacedo , When I am trying to run tests from aws-eks directory. It appears to be not picking up tests at all or giving other errors. Could you advise me on the correct steps to execute tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

yarn build && yarn test should be the only thing you need. Another thing you can try is to build the whole transitive closure before running the test:

 aws-eks $ ../../../scripts/buildup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@otaviomacedo , the tests are now complete. Could we please merge this ?

Copy link

Choose a reason for hiding this comment

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

@otaviomacedo , Could you please review?. Thanks

otaviomacedo
otaviomacedo previously approved these changes Jan 31, 2022
@mergify mergify bot dismissed otaviomacedo’s stale review January 31, 2022 10:02

Pull request has been modified.

@otaviomacedo otaviomacedo added the pr/do-not-merge This PR should not be merged at this time. label Jan 31, 2022
@otaviomacedo otaviomacedo removed the pr/do-not-merge This PR should not be merged at this time. label Feb 23, 2022
otaviomacedo
otaviomacedo previously approved these changes Feb 23, 2022
@mergify
Copy link
Contributor

mergify bot commented Feb 23, 2022

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).

@mergify mergify bot dismissed otaviomacedo’s stale review February 24, 2022 11:25

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2022

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: 8980950
  • 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 7e624d9 into aws:master Feb 24, 2022
@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2022

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).

@harshadbhatia
Copy link
Contributor Author

@otaviomacedo , thanks a lot for your help !

@tsahiduek
Copy link
Contributor

tsahiduek commented Apr 4, 2022

Hi there,
Is this available at CDK V2 2.19.0?
How should I use it?
I've tried the following but it fails:

    cluster.addHelmChart(
      'AckS3', {
      chart: 'ack-s3',
      repository: 'oci://public.ecr.aws/aws-controllers-k8s/s3-chart',
      version: 'v0.0.19',
      namespace: 'ack-system',
      createNamespace: true,
    });

TIA

@tsahiduek
Copy link
Contributor

tsahiduek commented Apr 5, 2022

Did someone tested this feature?
I've copied the python code locally to understand why it's not working, and it seems that the helm pull command is executed inside the subprocess, but it isn't really working. When tested locally the output directory is empty (I've modified the tempfile.TemporaryDirectory() creation to tempfile.mkdtemp() in order to persist the directory after the program finished to run

Any help here will be much appreciated

@tsahiduek
Copy link
Contributor

tsahiduek commented Apr 5, 2022

I think I've understood why:
The check_output uses shell=True. That means that all arguments of the commands being passed to the check_output are basically been passed to the shell and not to the helm pull command. Using shell is also discouraged from security perspective
References:
https://docs.python.org/3/library/subprocess.html
https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess

I'll open a PR to fix that (tested locally for now)

mergify bot pushed a commit that referenced this pull request Apr 7, 2022
…act (#19778)

When using helm to pull OCI artifacts, the helm pull command doesn't works well.

The [check_output](https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess) uses shell=True. That means that all arguments of the commands being passed to the check_output are basically been passed to the shell and not to the helm pull command. Using shell is also discouraged from [security perspective](https://docs.python.org/3/library/subprocess.html#security-considerations)
References:
https://docs.python.org/3/library/subprocess.html

> On POSIX with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes, for example, quoting or backslash escaping filenames with spaces in them. If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional arguments to the shell itself. 

https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess

The previous change that used the `Shell=True` was introduced in commit - #18547 (comment)

EDIT:
Adding commit for the following items:
- Adding integration test for helm OCI support in aws-eks
- Upgrading helm version to 3.8.1 in `aws-lambda-layer` because of issues with the current version of helm that is been used, for OCI chart supports
- update `integ.eks-helm-asset.expected.json` file

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) - NO new unconventional dependencies 

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? - NO
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? - NO

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
otaviomacedo pushed a commit that referenced this pull request Apr 11, 2022
…act (#19778)

When using helm to pull OCI artifacts, the helm pull command doesn't works well.

The [check_output](https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess) uses shell=True. That means that all arguments of the commands being passed to the check_output are basically been passed to the shell and not to the helm pull command. Using shell is also discouraged from [security perspective](https://docs.python.org/3/library/subprocess.html#security-considerations)
References:
https://docs.python.org/3/library/subprocess.html

> On POSIX with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes, for example, quoting or backslash escaping filenames with spaces in them. If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional arguments to the shell itself. 

https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess

The previous change that used the `Shell=True` was introduced in commit - #18547 (comment)

EDIT:
Adding commit for the following items:
- Adding integration test for helm OCI support in aws-eks
- Upgrading helm version to 3.8.1 in `aws-lambda-layer` because of issues with the current version of helm that is been used, for OCI chart supports
- update `integ.eks-helm-asset.expected.json` file

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) - NO new unconventional dependencies 

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? - NO
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? - NO

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
StevePotter pushed a commit to StevePotter/aws-cdk that referenced this pull request Apr 27, 2022
…act (aws#19778)

When using helm to pull OCI artifacts, the helm pull command doesn't works well.

The [check_output](https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess) uses shell=True. That means that all arguments of the commands being passed to the check_output are basically been passed to the shell and not to the helm pull command. Using shell is also discouraged from [security perspective](https://docs.python.org/3/library/subprocess.html#security-considerations)
References:
https://docs.python.org/3/library/subprocess.html

> On POSIX with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes, for example, quoting or backslash escaping filenames with spaces in them. If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional arguments to the shell itself. 

https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess

The previous change that used the `Shell=True` was introduced in commit - aws#18547 (comment)

EDIT:
Adding commit for the following items:
- Adding integration test for helm OCI support in aws-eks
- Upgrading helm version to 3.8.1 in `aws-lambda-layer` because of issues with the current version of helm that is been used, for OCI chart supports
- update `integ.eks-helm-asset.expected.json` file

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) - NO new unconventional dependencies 

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? - NO
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? - NO

*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
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants