Skip to content

Commit 14aebce

Browse files
eks-charts to ECR Public migration (#803)
* eks-charts to ECR Public migration * Removed makefile errors * Reverted release-prep make targets * Changes made as per PR comments * Removed io/ioutil package as it is deprecated and used io and os package (#804) * eks-charts to ECR Public migration * Removed makefile errors * Reverted release-prep make targets * Changes made as per PR comments * Made changes to match with script name
1 parent 6e56019 commit 14aebce

File tree

13 files changed

+164
-275
lines changed

13 files changed

+164
-275
lines changed

.github/workflows/release.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,19 @@ jobs:
6666
- name: Check out code into the Go module directory
6767
uses: actions/checkout@v2
6868

69-
- name: Create eks-charts PR
70-
run: make ekscharts-sync-release
69+
- name: Sync Helm Chart Catalog information
70+
run: make sync-catalog-information-for-helm-chart
71+
env:
72+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
73+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
74+
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
75+
76+
- name: Sync Helm Chart to ECR Public
77+
run: make push-helm-chart
78+
env:
79+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
80+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
81+
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
7182

7283
- name: Sync Readme to ECR Public
7384
run: make sync-readme-to-ecr-public

Makefile

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
VERSION = $(shell git describe --tags --always --dirty)
22
LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0)
3+
LATEST_COMMIT_HASH=$(shell git rev-parse HEAD)
4+
LATEST_COMMIT_CHART_VERSION=$(shell git --no-pager show ${LATEST_COMMIT_HASH}:config/helm/aws-node-termination-handler/Chart.yaml | grep 'version:' | cut -d' ' -f2 | tr -d '[:space:]')
35
PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
46
REPO_FULL_NAME=aws/aws-node-termination-handler
57
ECR_REGISTRY ?= public.ecr.aws/aws-ec2
68
ECR_REPO ?= ${ECR_REGISTRY}/aws-node-termination-handler
9+
ECR_REPO_CHART ?= aws-node-termination-handler
710
IMG ?= amazon/aws-node-termination-handler
811
IMG_TAG ?= ${VERSION}
912
IMG_W_TAG = ${IMG}:${IMG_TAG}
@@ -57,9 +60,16 @@ push-docker-images-windows:
5760
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
5861
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m
5962

63+
push-helm-chart:
64+
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login
65+
${MAKEFILE_PATH}/scripts/push-helm-chart -r ${ECR_REPO_CHART} -v ${LATEST_COMMIT_CHART_VERSION} -h ${ECR_REGISTRY}
66+
6067
version:
6168
@echo ${VERSION}
6269

70+
chart-version:
71+
@echo ${LATEST_COMMIT_CHART_VERSION}
72+
6373
latest-release-tag:
6474
@echo ${LATEST_RELEASE_TAG}
6575

@@ -99,16 +109,13 @@ license-test: $(GOLICENSES)
99109
go-linter:
100110
golangci-lint run
101111

102-
helm-sync-test:
103-
${MAKEFILE_PATH}/test/helm-sync-test/run-helm-sync-test
104-
105112
helm-version-sync-test:
106113
${MAKEFILE_PATH}/test/helm-sync-test/run-helm-version-sync-test
107114

108115
helm-lint:
109116
${MAKEFILE_PATH}/test/helm/helm-lint
110117

111-
helm-validate-eks-versions:
118+
helm-validate-chart-versions:
112119
${MAKEFILE_PATH}/test/helm/validate-chart-versions
113120

114121
build-binaries:
@@ -132,11 +139,9 @@ sync-readme-to-ecr-public:
132139
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
133140
${MAKEFILE_PATH}/scripts/sync-readme-to-ecr-public
134141

135-
ekscharts-sync:
136-
${MAKEFILE_PATH}/scripts/sync-to-aws-eks-charts -b ${BINARY_NAME} -r ${REPO_FULL_NAME}
137-
138-
ekscharts-sync-release:
139-
${MAKEFILE_PATH}/scripts/sync-to-aws-eks-charts -b ${BINARY_NAME} -r ${REPO_FULL_NAME} -n
142+
sync-catalog-information-for-helm-chart:
143+
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login
144+
${MAKEFILE_PATH}/scripts/sync-catalog-information-for-helm-chart
140145

141146
unit-test:
142147
go test -bench=. ${MAKEFILE_PATH}/... -v -coverprofile=coverage.txt -covermode=atomic -outputdir=${BUILD_DIR_PATH}
@@ -152,7 +157,7 @@ spellcheck:
152157

153158
build: compile
154159

155-
helm-tests: helm-version-sync-test helm-lint helm-validate-eks-versions
160+
helm-tests: helm-version-sync-test helm-lint helm-validate-chart-versions
156161

157162
eks-cluster-test:
158163
${MAKEFILE_PATH}/test/eks-cluster-test/run-test
@@ -161,7 +166,7 @@ release: build-binaries build-docker-images push-docker-images generate-k8s-yaml
161166

162167
release-windows: build-binaries-windows build-docker-images-windows push-docker-images-windows upload-resources-to-github-windows
163168

164-
test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test go-linter helm-sync-test helm-version-sync-test helm-lint
169+
test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test go-linter helm-version-sync-test helm-lint
165170

166171
help:
167172
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort
@@ -176,19 +181,19 @@ create-local-release-tag-minor:
176181
create-local-release-tag-patch:
177182
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -p
178183

179-
create-release-prep-pr:
184+
create-release-pr:
180185
${MAKEFILE_PATH}/scripts/prepare-for-release
181186

182-
create-release-prep-pr-draft:
187+
create-release-pr-draft:
183188
${MAKEFILE_PATH}/scripts/prepare-for-release -d
184189

185-
release-prep-major: create-local-release-tag-major create-release-prep-pr
190+
release-prep-major: create-local-release-tag-major create-release-pr
186191

187-
release-prep-minor: create-local-release-tag-minor create-release-prep-pr
192+
release-prep-minor: create-local-release-tag-minor create-release-pr
188193

189-
release-prep-patch: create-local-release-tag-patch create-release-prep-pr
194+
release-prep-patch: create-local-release-tag-patch create-release-pr
190195

191196
release-prep-custom: # Run make NEW_VERSION=v1.2.3 release-prep-custom to prep for a custom release version
192197
ifdef NEW_VERSION
193-
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-prep-pr")
198+
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-pr")
194199
endif

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,25 @@ For a full list of releases and associated artifacts see our [releases page](htt
123123

124124
#### Helm
125125

126-
The easiest way to configure the various options of the termination handler is via [helm](https://helm.sh/). The chart for this project is hosted in the [eks-charts](https://github.com/aws/eks-charts) repository.
126+
The easiest way to configure the various options of the termination handler is via [helm](https://helm.sh/). The chart for this project is hosted in [helm/aws-node-termination-handler](https://gallery.ecr.aws/aws-ec2/helm/aws-node-termination-handler)
127127

128-
To get started you need to add the eks-charts repo to helm
128+
To get started you need to authenticate your helm client
129129

130130
```
131-
helm repo add eks https://aws.github.io/eks-charts
131+
aws ecr-public get-login-password \
132+
--region us-east-1 | helm registry login \
133+
--username AWS \
134+
--password-stdin public.ecr.aws
132135
```
133136

134-
Once that is complete you can install the termination handler. We've provided some sample setup options below.
137+
Once that is complete you can install the termination handler. We've provided some sample setup options below. Make sure to replace CHART_VERSION with the version you want to install.
135138

136139
Zero Config:
137140

138141
```sh
139142
helm upgrade --install aws-node-termination-handler \
140143
--namespace kube-system \
141-
eks/aws-node-termination-handler
144+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
142145
```
143146

144147
Enabling Features:
@@ -149,7 +152,7 @@ helm upgrade --install aws-node-termination-handler \
149152
--set enableSpotInterruptionDraining="true" \
150153
--set enableRebalanceMonitoring="true" \
151154
--set enableScheduledEventDraining="false" \
152-
eks/aws-node-termination-handler
155+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
153156
```
154157

155158
The `enable*` configuration flags above enable or disable IMDS monitoring paths.
@@ -160,7 +163,7 @@ Running Only On Specific Nodes:
160163
helm upgrade --install aws-node-termination-handler \
161164
--namespace kube-system \
162165
--set nodeSelector.lifecycle=spot \
163-
eks/aws-node-termination-handler
166+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
164167
```
165168

166169
Webhook Configuration:
@@ -169,7 +172,7 @@ Webhook Configuration:
169172
helm upgrade --install aws-node-termination-handler \
170173
--namespace kube-system \
171174
--set webhookURL=https://hooks.slack.com/services/YOUR/SLACK/URL \
172-
eks/aws-node-termination-handler
175+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
173176
```
174177

175178
Alternatively, pass Webhook URL as a Secret:
@@ -183,10 +186,10 @@ kubectl create secret -n kube-system generic webhooksecret --from-literal=$WEBHO
183186
helm upgrade --install aws-node-termination-handler \
184187
--namespace kube-system \
185188
--set webhookURLSecretName=webhooksecret \
186-
eks/aws-node-termination-handler
189+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
187190
```
188191

189-
For a full list of configuration options see our [Helm readme](https://github.com/aws/eks-charts/tree/master/stable/aws-node-termination-handler).
192+
For a full list of configuration options see our [Helm readme](https://github.com/aws/aws-node-termination-handler/blob/v1.19.0/config/helm/aws-node-termination-handler#readme).
190193

191194
</details>
192195

@@ -391,15 +394,18 @@ When using Kubernetes [Pod Security Admission](https://kubernetes.io/docs/concep
391394

392395
#### Helm
393396

394-
The easiest and most commonly used method to configure the termination handler is via [helm](https://helm.sh/). The chart for this project is hosted in the [eks-charts](https://github.com/aws/eks-charts) repository.
397+
The easiest way to configure the various options of the termination handler is via [helm](https://helm.sh/). The chart for this project is hosted in [helm/aws-node-termination-handler](https://gallery.ecr.aws/aws-ec2/helm/aws-node-termination-handler)
395398

396-
To get started you need to add the eks-charts repo to helm
399+
To get started you need to authenticate your helm client
397400

398401
```
399-
helm repo add eks https://aws.github.io/eks-charts
402+
aws ecr-public get-login-password \
403+
--region us-east-1 | helm registry login \
404+
--username AWS \
405+
--password-stdin public.ecr.aws
400406
```
401407

402-
Once that is complete you can install the termination handler. We've provided some sample setup options below.
408+
Once that is complete you can install the termination handler. We've provided some sample setup options below. Make sure to replace CHART_VERSION with the version you want to install.
403409

404410
Minimal Config:
405411

@@ -408,7 +414,7 @@ helm upgrade --install aws-node-termination-handler \
408414
--namespace kube-system \
409415
--set enableSqsTerminationDraining=true \
410416
--set queueURL=https://sqs.us-east-1.amazonaws.com/0123456789/my-term-queue \
411-
eks/aws-node-termination-handler
417+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
412418
```
413419

414420
Webhook Configuration:
@@ -419,7 +425,7 @@ helm upgrade --install aws-node-termination-handler \
419425
--set enableSqsTerminationDraining=true \
420426
--set queueURL=https://sqs.us-east-1.amazonaws.com/0123456789/my-term-queue \
421427
--set webhookURL=https://hooks.slack.com/services/YOUR/SLACK/URL \
422-
eks/aws-node-termination-handler
428+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
423429
```
424430

425431
Alternatively, pass Webhook URL as a Secret:
@@ -435,10 +441,10 @@ helm upgrade --install aws-node-termination-handler \
435441
--set enableSqsTerminationDraining=true \
436442
--set queueURL=https://sqs.us-east-1.amazonaws.com/0123456789/my-term-queue \
437443
--set webhookURLSecretName=webhooksecret \
438-
eks/aws-node-termination-handler
444+
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
439445
```
440446

441-
For a full list of configuration options see our [Helm readme](https://github.com/aws/eks-charts/tree/master/stable/aws-node-termination-handler).
447+
For a full list of configuration options see our [Helm readme](https://github.com/aws/aws-node-termination-handler/blob/v1.19.0/config/helm/aws-node-termination-handler#readme).
442448

443449
#### Kubectl Apply
444450

config/helm/aws-node-termination-handler/Chart.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ keywords:
1111
- ec2
1212
- node-termination
1313
- spot
14-
home: https://github.com/aws/eks-charts
14+
home: https://github.com/aws/aws-node-termination-handler/
1515
icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png
1616
sources:
1717
- https://github.com/aws/aws-node-termination-handler/
18-
- https://github.com/aws/eks-charts/
1918
maintainers:
2019
- name: Brandon Wagner
2120
url: https://github.com/bwagner5

config/helm/aws-node-termination-handler/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ AWS Node Termination Handler Helm chart for Kubernetes. For more information on
88

99
## Installing the Chart
1010

11-
Before you can install the chart you will need to add the `aws` repo to [Helm](https://helm.sh/).
12-
11+
Before you can install the chart you will need to authenticate your Helm client.
1312
```shell
14-
helm repo add eks https://aws.github.io/eks-charts/
13+
aws ecr-public get-login-password \
14+
--region us-east-1 | helm registry login \
15+
--username AWS \
16+
--password-stdin public.ecr.aws
1517
```
1618

17-
After you've installed the repo you can install the chart, the following command will install the chart with the release name `aws-node-termination-handler` and the default configuration to the `kube-system` namespace.
19+
Once the helm registry login succeeds, use the following command to install the chart with the release name `aws-node-termination-handler` and the default configuration to the `kube-system` namespace. In the below command, add the CHART_VERSION that you want to install.
1820

1921
```shell
20-
helm upgrade --install --namespace kube-system aws-node-termination-handler eks/aws-node-termination-handler
22+
helm upgrade --install --namespace kube-system aws-node-termination-handler oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
2123
```
2224

2325
To install the chart on an EKS cluster where the AWS Node Termination Handler is already installed, you can run the following command.
2426

2527
```shell
26-
helm upgrade --install --namespace kube-system aws-node-termination-handler eks/aws-node-termination-handler --recreate-pods --force
28+
helm upgrade --install --namespace kube-system aws-node-termination-handler oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION --recreate-pods --force
2729
```
2830

2931
If you receive an error similar to the one below simply rerun the above command.
@@ -33,7 +35,7 @@ If you receive an error similar to the one below simply rerun the above command.
3335
To uninstall the `aws-node-termination-handler` chart installation from the `kube-system` namespace run the following command.
3436

3537
```shell
36-
helm delete --namespace kube-system aws-node-termination-handler
38+
helm uninstall --namespace kube-system aws-node-termination-handler
3739
```
3840

3941
## Configuration
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"description": "Helm Charts for AWS Node Termination Handler",
3+
"aboutText": "# Helm Chart for Node Termination Handler\n\n AWS NTH gracefully handles EC2 instance shutdown within Kubernetes.\n\nThis repository contains helm-charts for Node Termination Handler.\n\nFor more information on this project, see the project repo at [AWS Node Termination Handler](https://github.com/aws/aws-node-termination-handler)",
4+
"usageText": "# We can install AWS NTH using the helm chart from this repository.\n\nWe need to authenticate our helm client to ECR registry and install NTH chart using helm chart URI, detailed information on how to install helm chart can be found here [HelmChart ReadMe](https://github.com/aws/aws-node-termination-handler/tree/main/config/helm/aws-node-termination-handler#readme)"
5+
}

scripts/helm-login

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5+
BUILD_DIR=$SCRIPTPATH/../build/
6+
export PATH="${BUILD_DIR}:${PATH}"
7+
8+
if [[ -z "${ECR_REGISTRY}" ]]; then
9+
echo "The env var ECR_REGISTRY must be set"
10+
exit 1
11+
fi
12+
13+
function exit_and_fail() {
14+
echo "❌ Failed to login to ECR Public Repo!"
15+
}
16+
17+
trap exit_and_fail INT TERM ERR
18+
19+
export HELM_EXPERIMENTAL_OCI=1
20+
helm registry login --username AWS --password="$(aws ecr-public get-login-password --region us-east-1)" "${ECR_REGISTRY}"

scripts/prepare-for-release

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ HELP=$(cat << 'EOM'
5555
-d create a draft pr
5656
-r target repo full name for the pr (default: aws/aws-node-termination-handler)
5757
-h help
58-
5958
Examples:
6059
prepare-for-release -d update release version in repo and create a draft pr against aws/aws-node-termination-handler
6160
prepare-for-release -r username/aws-node-termination-handler update release version in repo and create a pr against username/aws-node-termination-handler

scripts/push-helm-chart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPTPATH="$( cd "$(dirname "$0")";pwd -P )"
5+
6+
REPO_ROOT_PATH=$SCRIPTPATH/../
7+
MAKE_FILE_PATH=$REPO_ROOT_PATH/Makefile
8+
CHART_VERSION=$(make -s -f $MAKE_FILE_PATH chart-version)
9+
HELM_CHART_PATH=$REPO_ROOT_PATH/config/helm/aws-node-termination-handler
10+
11+
USAGE=$(cat << 'EOM'
12+
Usage: push-helm-chart
13+
Pushes helm charts
14+
Optional:
15+
-h HELM CHART REGISTRY: set the helm chart registry
16+
-v CHART VERSION: The chart version [DEFAULT: output of `make chart-version`]
17+
-r HELM CHART REPOSITORY: Set the helm chart repository
18+
EOM
19+
)
20+
21+
# Process our input arguments
22+
while getopts "r:v:h:" opt; do
23+
case ${opt} in
24+
r ) # Helm Chart Repository
25+
HELM_CHART_REPOSITORY="$OPTARG"
26+
;;
27+
v ) # Image Version
28+
CHART_VERSION="$OPTARG"
29+
;;
30+
h ) # Helm Chart Registry
31+
ECR_REGISTRY="$OPTARG"
32+
;;
33+
\? )
34+
echo "$USAGE" 1>&2
35+
exit
36+
;;
37+
esac
38+
done
39+
40+
CHART_EXISTS=$(aws ecr-public describe-images --repository-name "helm/$HELM_CHART_REPOSITORY" --region us-east-1 --query "imageDetails[?contains(imageTags, '$CHART_VERSION')].imageTags[]" --output text)
41+
42+
if [[ -n "$CHART_EXISTS" ]]; then
43+
echo "chart with version $CHART_VERSION already exists in the repository, skipping pushing of chart..."
44+
exit 0
45+
fi
46+
47+
echo "chart with version $CHART_VERSION not found in repository, pushing new chart..."
48+
#Package the chart
49+
helm package $HELM_CHART_PATH --destination $REPO_ROOT_PATH/build
50+
#Pushing helm chart
51+
helm push $REPO_ROOT_PATH/build/$HELM_CHART_REPOSITORY-$CHART_VERSION.tgz oci://$ECR_REGISTRY/helm

0 commit comments

Comments
 (0)