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

eks-charts to ECR Public migration #803

Merged
merged 11 commits into from
Apr 14, 2023
15 changes: 13 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Create eks-charts PR
run: make ekscharts-sync-release
- name: Sync Helm Chart Catalog information
run: make sync-catalog-information-for-helm-chart
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}

- name: Sync Helm Chart to ECR Public
run: make push-helm-chart
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}

- name: Sync Readme to ECR Public
run: make sync-readme-to-ecr-public
Expand Down
39 changes: 22 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
VERSION = $(shell git describe --tags --always --dirty)
LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0)
LATEST_COMMIT_HASH=$(shell git rev-parse HEAD)
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:]')
PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
REPO_FULL_NAME=aws/aws-node-termination-handler
ECR_REGISTRY ?= public.ecr.aws/aws-ec2
ECR_REPO ?= ${ECR_REGISTRY}/aws-node-termination-handler
ECR_REPO_CHART ?= aws-node-termination-handler
IMG ?= amazon/aws-node-termination-handler
IMG_TAG ?= ${VERSION}
IMG_W_TAG = ${IMG}:${IMG_TAG}
Expand Down Expand Up @@ -56,9 +59,16 @@ push-docker-images-windows:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m

push-helm-chart:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login
${MAKEFILE_PATH}/scripts/push-helm-chart -r ${ECR_REPO_CHART} -v ${LATEST_COMMIT_CHART_VERSION} -h ${ECR_REGISTRY}

version:
@echo ${VERSION}

chart-version:
@echo ${LATEST_COMMIT_CHART_VERSION}

latest-release-tag:
@echo ${LATEST_RELEASE_TAG}

Expand Down Expand Up @@ -98,16 +108,13 @@ license-test: $(GOLICENSES)
go-linter:
golangci-lint run

helm-sync-test:
${MAKEFILE_PATH}/test/helm-sync-test/run-helm-sync-test

helm-version-sync-test:
${MAKEFILE_PATH}/test/helm-sync-test/run-helm-version-sync-test

helm-lint:
${MAKEFILE_PATH}/test/helm/helm-lint

helm-validate-eks-versions:
helm-validate-chart-versions:
${MAKEFILE_PATH}/test/helm/validate-chart-versions

build-binaries:
Expand All @@ -129,11 +136,9 @@ sync-readme-to-ecr-public:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
${MAKEFILE_PATH}/scripts/sync-readme-to-ecr-public

ekscharts-sync:
${MAKEFILE_PATH}/scripts/sync-to-aws-eks-charts -b ${BINARY_NAME} -r ${REPO_FULL_NAME}

ekscharts-sync-release:
${MAKEFILE_PATH}/scripts/sync-to-aws-eks-charts -b ${BINARY_NAME} -r ${REPO_FULL_NAME} -n
sync-catalog-information-for-helm-chart:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login
${MAKEFILE_PATH}/scripts/sync-catalog-information-for-helm-chart

unit-test:
go test -bench=. ${MAKEFILE_PATH}/... -v -coverprofile=coverage.txt -covermode=atomic -outputdir=${BUILD_DIR_PATH}
Expand All @@ -149,7 +154,7 @@ spellcheck:

build: compile

helm-tests: helm-version-sync-test helm-lint helm-validate-eks-versions
helm-tests: helm-version-sync-test helm-lint helm-validate-chart-versions

eks-cluster-test:
${MAKEFILE_PATH}/test/eks-cluster-test/run-test
Expand All @@ -158,7 +163,7 @@ release: build-binaries build-docker-images push-docker-images generate-k8s-yaml

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

test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test go-linter helm-sync-test helm-version-sync-test helm-lint
test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test go-linter helm-version-sync-test helm-lint

help:
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort
Expand All @@ -173,19 +178,19 @@ create-local-release-tag-minor:
create-local-release-tag-patch:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -p

create-release-prep-pr:
create-release-pr:
${MAKEFILE_PATH}/scripts/prepare-for-release

create-release-prep-pr-draft:
create-release-pr-draft:
${MAKEFILE_PATH}/scripts/prepare-for-release -d

release-prep-major: create-local-release-tag-major create-release-prep-pr
release-prep-major: create-local-release-tag-major create-release-pr

release-prep-minor: create-local-release-tag-minor create-release-prep-pr
release-prep-minor: create-local-release-tag-minor create-release-pr

release-prep-patch: create-local-release-tag-patch create-release-prep-pr
release-prep-patch: create-local-release-tag-patch create-release-pr

release-prep-custom: # Run make NEW_VERSION=v1.2.3 release-prep-custom to prep for a custom release version
ifdef NEW_VERSION
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-prep-pr")
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-pr")
endif
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,25 @@ For a full list of releases and associated artifacts see our [releases page](htt

#### Helm

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

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

```
helm repo add eks https://aws.github.io/eks-charts
aws ecr-public get-login-password \
--region us-east-1 | helm registry login \
--username AWS \
--password-stdin public.ecr.aws
```

Once that is complete you can install the termination handler. We've provided some sample setup options below.
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.

Zero Config:

```sh
helm upgrade --install aws-node-termination-handler \
--namespace kube-system \
eks/aws-node-termination-handler
oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler --version $CHART_VERSION
```

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

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

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

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

For a full list of configuration options see our [Helm readme](https://github.com/aws/eks-charts/tree/master/stable/aws-node-termination-handler).
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).

</details>

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

#### Helm

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

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

```
helm repo add eks https://aws.github.io/eks-charts
aws ecr-public get-login-password \
--region us-east-1 | helm registry login \
--username AWS \
--password-stdin public.ecr.aws
```

Once that is complete you can install the termination handler. We've provided some sample setup options below.
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.

Minimal Config:

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

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

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

For a full list of configuration options see our [Helm readme](https://github.com/aws/eks-charts/tree/master/stable/aws-node-termination-handler).
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).

#### Kubectl Apply

Expand Down
3 changes: 1 addition & 2 deletions config/helm/aws-node-termination-handler/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ keywords:
- ec2
- node-termination
- spot
home: https://github.com/aws/eks-charts
home: https://github.com/aws/aws-node-termination-handler/
icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png
sources:
- https://github.com/aws/aws-node-termination-handler/
- https://github.com/aws/eks-charts/
maintainers:
- name: Brandon Wagner
url: https://github.com/bwagner5
Expand Down
16 changes: 9 additions & 7 deletions config/helm/aws-node-termination-handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ AWS Node Termination Handler Helm chart for Kubernetes. For more information on

## Installing the Chart

Before you can install the chart you will need to add the `aws` repo to [Helm](https://helm.sh/).

Before you can install the chart you will need to authenticate your Helm client.
```shell
helm repo add eks https://aws.github.io/eks-charts/
aws ecr-public get-login-password \
--region us-east-1 | helm registry login \
--username AWS \
--password-stdin public.ecr.aws
```

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

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

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

```shell
helm upgrade --install --namespace kube-system aws-node-termination-handler eks/aws-node-termination-handler --recreate-pods --force
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
```

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

```shell
helm delete --namespace kube-system aws-node-termination-handler
helm uninstall --namespace kube-system aws-node-termination-handler
```

## Configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/ec2metadata/ec2metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package ec2metadata
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math/rand"
"net/http"
"strconv"
Expand Down Expand Up @@ -202,7 +202,7 @@ func (e *Service) GetMetadataInfo(path string) (info string, err error) {
}
if resp != nil {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ func (e *Service) getV2Token() (string, int, error) {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return "", -1, fmt.Errorf("Received an http status code %d", resp.StatusCode)
}
token, err := ioutil.ReadAll(resp.Body)
token, err := io.ReadAll(resp.Body)
if err != nil {
return "", -1, fmt.Errorf("Unable to read token response from IMDSv2: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ec2metadata/ec2metadata_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package ec2metadata
import (
"bytes"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strconv"
Expand All @@ -35,7 +35,7 @@ func TestRetry(t *testing.T) {
requestCount++
return &http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)),
Body: io.NopCloser(bytes.NewBufferString(`OK`)),
Header: make(http.Header),
}, errors.New(errorMsg)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/ec2metadata/ec2metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package ec2metadata_test

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestRequestV1(t *testing.T) {
defer resp.Body.Close()
h.Equals(t, http.StatusOK, resp.StatusCode)

responseData, err := ioutil.ReadAll(resp.Body)
responseData, err := io.ReadAll(resp.Body)
if err != nil {
t.Error("Unable to parse response.")
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestRequestV2(t *testing.T) {
defer resp.Body.Close()
h.Equals(t, http.StatusOK, resp.StatusCode)

responseData, err := ioutil.ReadAll(resp.Body)
responseData, err := io.ReadAll(resp.Body)
if err != nil {
t.Error("Unable to parse response.")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/uptime/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package uptime

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)
Expand All @@ -26,7 +26,7 @@ type UptimeFuncType func() (int64, error)
// UptimeFromFile reads system uptime information from filepath and returns
// the number of seconds since last system boot.
func UptimeFromFile(filepath string) (int64, error) {
data, err := ioutil.ReadFile(filepath)
data, err := os.ReadFile(filepath)
if err != nil {
return 0, fmt.Errorf("Not able to read %s: %w", filepath, err)
}
Expand Down
Loading