From d2ba3203a32604b7a82fd74fdb0a45e943f6e23c Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Thu, 2 Feb 2023 22:38:04 +0000 Subject: [PATCH] cherry-pick #2251, #2226, #2187, #2201, #1794 --- .github/workflows/release.yaml | 11 +- Makefile | 15 ++- charts/aws-vpc-cni/README.md | 1 - charts/aws-vpc-cni/templates/daemonset.yaml | 4 +- charts/cni-metrics-helper/Chart.yaml | 34 +++--- charts/cni-metrics-helper/README.md | 81 ++++++++++++ charts/cni-metrics-helper/values.yaml | 3 + scripts/generate-cni-yaml.sh | 41 +------ scripts/sync-to-config-folder.sh | 58 ++------- scripts/sync-to-eks-charts.sh | 18 ++- scripts/upload-resources-to-github.sh | 129 -------------------- 11 files changed, 142 insertions(+), 253 deletions(-) create mode 100644 charts/cni-metrics-helper/README.md delete mode 100755 scripts/upload-resources-to-github.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4d01c487191..7f3cd73b35f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,6 +1,8 @@ name: VPC CNI Release -on: [push, workflow_dispatch] +on: + release: + types: [published] permissions: contents: read @@ -11,17 +13,18 @@ env: jobs: release: - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: - name: Checkout latest commit in the PR uses: actions/checkout@v3 + with: + ref: "refs/tags/{{ github.event.release.tag_name }}" - name: Set up Go uses: actions/setup-go@v3 with: go-version: "1.19" - - name: Attach release artifacts - run: make release + - name: Generate CNI YAML + run: make generate-cni-yaml - name: Create eks-charts PR run: make ekscharts-sync-release - name: Create sample manifests PR diff --git a/Makefile b/Makefile index 6609ee1d929..2bce3f01c32 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ METRICS_IMAGE = amazon/cni-metrics-helper METRICS_IMAGE_NAME = $(METRICS_IMAGE)$(IMAGE_ARCH_SUFFIX):$(VERSION) METRICS_IMAGE_DIST = $(DESTDIR)/$(subst /,_,$(METRICS_IMAGE_NAME)).tar.gz REPO_FULL_NAME=aws/amazon-vpc-cni-k8s -HELM_CHART_NAME ?= "aws-vpc-cni" +HELM_CHART_NAMES ?= "aws-vpc-cni" "cni-metrics-helper" # TEST_IMAGE is the testing environment container image. TEST_IMAGE = amazon-k8s-cni-test TEST_IMAGE_NAME = $(TEST_IMAGE)$(IMAGE_ARCH_SUFFIX):$(VERSION) @@ -341,19 +341,18 @@ generate-limits: ## Generate limit file go code go run $(VENDOR_OVERRIDE_FLAG) scripts/gen_vpc_ip_limits.go ekscharts-sync: - ${MAKEFILE_PATH}/scripts/sync-to-eks-charts.sh -b ${HELM_CHART_NAME} -r ${REPO_FULL_NAME} + for HELM_CHART_NAME in $(HELM_CHART_NAMES) ; do \ + ${MAKEFILE_PATH}/scripts/sync-to-eks-charts.sh -b $$HELM_CHART_NAME -r ${REPO_FULL_NAME} ; \ + done ekscharts-sync-release: - ${MAKEFILE_PATH}/scripts/sync-to-eks-charts.sh -b ${HELM_CHART_NAME} -r ${REPO_FULL_NAME} -n -y - -upload-resources-to-github: - ${MAKEFILE_PATH}/scripts/upload-resources-to-github.sh + for HELM_CHART_NAME in $(HELM_CHART_NAMES) ; do \ + ${MAKEFILE_PATH}/scripts/sync-to-eks-charts.sh -b $$HELM_CHART_NAME -r ${REPO_FULL_NAME} -n -y ; \ + done generate-cni-yaml: ${MAKEFILE_PATH}/scripts/generate-cni-yaml.sh -release: generate-cni-yaml upload-resources-to-github - config-folder-sync: ${MAKEFILE_PATH}/scripts/sync-to-config-folder.sh diff --git a/charts/aws-vpc-cni/README.md b/charts/aws-vpc-cni/README.md index a7bb122b9d1..cd22b159998 100644 --- a/charts/aws-vpc-cni/README.md +++ b/charts/aws-vpc-cni/README.md @@ -91,7 +91,6 @@ WARNING: Substitute YOUR_HELM_RELEASE_NAME_HERE with the name of your helm relea set -euo pipefail -# don't import the crd. Helm cant manage the lifecycle of it anyway. for kind in daemonSet clusterRole clusterRoleBinding serviceAccount; do echo "setting annotations and labels on $kind/aws-node" kubectl -n kube-system annotate --overwrite $kind aws-node meta.helm.sh/release-name=YOUR_HELM_RELEASE_NAME_HERE diff --git a/charts/aws-vpc-cni/templates/daemonset.yaml b/charts/aws-vpc-cni/templates/daemonset.yaml index 261480ad5c1..a78fdad5005 100644 --- a/charts/aws-vpc-cni/templates/daemonset.yaml +++ b/charts/aws-vpc-cni/templates/daemonset.yaml @@ -91,8 +91,8 @@ spec: - mountPath: /host/etc/cni/net.d name: cni-net-dir {{- if .Values.cniConfig.enabled }} - # the dockerfile copies the baked in config to this location, lets overwrite it with ours - # the entrypoint.sh script will then copy our config to /host/etc/cni/net.d on boot + # The dockerfile copies the baked in config to this location, so overwrite it with ours. + # The entrypoint process will then copy our config to /host/etc/cni/net.d on boot. - name: cni-config mountPath: /app/10-aws.conflist subPath: 10-aws.conflist diff --git a/charts/cni-metrics-helper/Chart.yaml b/charts/cni-metrics-helper/Chart.yaml index 81393fbbead..b3cf0693a3b 100644 --- a/charts/cni-metrics-helper/Chart.yaml +++ b/charts/cni-metrics-helper/Chart.yaml @@ -1,23 +1,19 @@ apiVersion: v2 name: cni-metrics-helper -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) version: 0.1.16 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. appVersion: v1.12.2 +description: A Helm chart for the AWS VPC CNI Metrics Helper +icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png +home: https://github.com/aws/amazon-vpc-cni-k8s +sources: + - https://github.com/aws/amazon-vpc-cni-k8s +keywords: + - eks + - cni + - networking + - vpc +maintainers: + - name: Jayanth Varavani + url: https://github.com/jayanthvn + email: jayanthvn@users.noreply.github.com +engine: gotpl diff --git a/charts/cni-metrics-helper/README.md b/charts/cni-metrics-helper/README.md new file mode 100644 index 00000000000..eb5a1bf0817 --- /dev/null +++ b/charts/cni-metrics-helper/README.md @@ -0,0 +1,81 @@ +# CNI METRICS HELPER + +This chart provides a Kubernetes deployment for the Amazon VPC CNI Metrics Helper, which is used to collect metrics for the Amazon VPC CNI plugin for Kubernetes. + +## Prerequisites + +- Kubernetes 1.11+ running on AWS +- Helm 3.0+ + +## Installing the Chart + +First add the EKS repository to Helm: + +```shell +helm repo add eks https://aws.github.io/eks-charts +``` + +To install the chart with the release name `cni-metrics-helper` and default configuration: + +```shell +$ helm install cni-metrics-helper --namespace kube-system eks/cni-metrics-helper +``` + +To install manually, clone the Amazon VPC CNI for Kubernetes repository to your local machine: + +```shell +$ git clone https://github.com/aws/amazon-vpc-cni-k8s.git +``` + +Use the helm install command to install the chart into your Kubernetes cluster: + +```shell +$ helm install cni-metrics-helper --namespace kube-system ./charts/cni-metrics-helper +``` + +To uninstall: + +```shell +$ helm uninstall cni-metrics-helper --namespace kube-system +``` + +## Configuration + +The following table lists the configurable parameters for this chart and their default values. + +| Parameter | Description | Default | +|------------------------------|---------------------------------------------------------------|--------------------| +| fullnameOverride | Override the fullname of the chart | cni-metrics-helper | +| image.region | ECR repository region to use. Should match your cluster | us-west-2 | +| image.tag | Image tag | v1.12.2 | +| image.account | ECR repository account number | 602401143452 | +| image.domain | ECR repository domain | amazonaws.com | +| env.USE_CLOUDWATCH | Whether to export CNI metrics to CloudWatch | true | +| env.AWS_CLUSTER_ID | ID of the cluster to use when exporting metrics to CloudWatch | default | +| env.AWS_VPC_K8S_CNI_LOGLEVEL | Log verbosity level (ie. FATAL, ERROR, WARN, INFO, DEBUG) | INFO | +| serviceAccount.name | The name of the ServiceAccount to use | nil | +| serviceAccount.create | Specifies whether a ServiceAccount should be created | true | +| serviceAccount.annotations | Specifies the annotations for ServiceAccount | {} | + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install` or provide a YAML file containing the values for the above parameters: + +```shell +$ helm install cni-metrics-handler --namespace kube-system eks/cni-metrics-handler --values values.yaml +``` + +Manual install: +```shell +$ helm install cni-metrics-helper --namespace kube-system ./charts/cni-metrics-helper --values values.yaml +``` + +## Resources + +| Parameter | Description | Default | +|---------------------------|------------------------------------------------|---------| +| resources | Resources for the pods. | `{}` | + +For example, to set a CPU limit of 200m and a memory limit of 256Mi for the cni-metrics-helper pods, you can use the following command: + +```shell +$ helm install cni-metrics-helper ./charts/cni-metrics-helper --namespace kube-system --set resources.limits.cpu=200m,resources.limits.memory=256Mi +``` diff --git a/charts/cni-metrics-helper/values.yaml b/charts/cni-metrics-helper/values.yaml index 5c7ee72d770..af3f6cd6054 100644 --- a/charts/cni-metrics-helper/values.yaml +++ b/charts/cni-metrics-helper/values.yaml @@ -13,6 +13,7 @@ image: env: USE_CLOUDWATCH: "true" AWS_CLUSTER_ID: "" + AWS_VPC_K8S_CNI_LOGLEVEL: "INFO" fullnameOverride: "cni-metrics-helper" @@ -24,3 +25,5 @@ serviceAccount: name: annotations: {} # eks.amazonaws.com/role-arn: arn:aws:iam::AWS_ACCOUNT_ID:role/IAM_ROLE_NAME + +resources: {} diff --git a/scripts/generate-cni-yaml.sh b/scripts/generate-cni-yaml.sh index 5ee261a01cc..148b57e81b6 100755 --- a/scripts/generate-cni-yaml.sh +++ b/scripts/generate-cni-yaml.sh @@ -4,7 +4,7 @@ set -euo pipefail SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" PLATFORM=$(uname | tr '[:upper:]' '[:lower:]') -HELM_VERSION="3.6.3" +HELM_VERSION="3.11.0" NAMESPACE="kube-system" MAKEFILEPATH=$SCRIPTPATH/../Makefile @@ -12,14 +12,10 @@ VERSION=$(make -s -f $MAKEFILEPATH version) BUILD_DIR=$SCRIPTPATH/../build/cni-rel-yamls/$VERSION REGIONS_FILE=$SCRIPTPATH/../charts/regions.json -INDV_RESOURCES_DIR=$BUILD_DIR/individual-resources -CNI_TAR_RESOURCES_FILE=$BUILD_DIR/cni_individual-resources.tar -METRICS_TAR_RESOURCES_FILE=$BUILD_DIR/cni_metrics_individual-resources.tar CNI_RESOURCES_YAML=$BUILD_DIR/aws-k8s-cni METRICS_RESOURCES_YAML=$BUILD_DIR/cni-metrics-helper -mkdir -p $INDV_RESOURCES_DIR - +mkdir -p $BUILD_DIR USAGE=$(cat << 'EOM' Usage: generate-cni-yaml [-n ] @@ -80,8 +76,8 @@ jq -c '.[]' $REGIONS_FILE | while read i; do --set image.domain=$ecrDomain \ --namespace $NAMESPACE \ $SCRIPTPATH/../charts/aws-vpc-cni > $NEW_CNI_RESOURCES_YAML - cat $NEW_CNI_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml - mv $BUILD_DIR/helm_annotations_removed.yaml $NEW_CNI_RESOURCES_YAML + # Remove 'managed-by: Helm' annotation + sed -i '/helm.sh\|app.kubernetes.io\/managed-by: Helm/d' $NEW_CNI_RESOURCES_YAML $BUILD_DIR/helm template cni-metrics-helper \ --set image.region=$ecrRegion,\ @@ -90,37 +86,12 @@ jq -c '.[]' $REGIONS_FILE | while read i; do --set image.tag=$VERSION,\ --namespace $NAMESPACE \ $SCRIPTPATH/../charts/cni-metrics-helper > $NEW_METRICS_RESOURCES_YAML - cat $NEW_METRICS_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml - mv $BUILD_DIR/helm_annotations_removed.yaml $NEW_METRICS_RESOURCES_YAML + # Remove 'managed-by: Helm' annotation + sed -i '/helm.sh\|app.kubernetes.io\/managed-by: Helm/d' $NEW_METRICS_RESOURCES_YAML done -$BUILD_DIR/helm template --include-crds \ - --namespace $NAMESPACE \ - --output-dir $INDV_RESOURCES_DIR/ \ - $SCRIPTPATH/../charts/aws-vpc-cni/ - -for i in $INDV_RESOURCES_DIR/aws-vpc-cni/templates/*; do - cat $i | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml - mv $BUILD_DIR/helm_annotations_removed.yaml $i -done - -$BUILD_DIR/helm template \ - --namespace $NAMESPACE \ - --output-dir $INDV_RESOURCES_DIR/ \ - $SCRIPTPATH/../charts/cni-metrics-helper/ - -for i in $INDV_RESOURCES_DIR/cni-metrics-helper/templates/*; do - cat $i | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml - mv $BUILD_DIR/helm_annotations_removed.yaml $i -done - - -cd $INDV_RESOURCES_DIR/aws-vpc-cni/ && tar cvf $CNI_TAR_RESOURCES_FILE templates/* -cd $INDV_RESOURCES_DIR/cni-metrics-helper/ && tar cvf $METRICS_TAR_RESOURCES_FILE templates/* cd $SCRIPTPATH echo "Generated aws-vpc-cni and cni-metrics-helper manifest resources files in:" echo " - $CNI_RESOURCES_YAML" echo " - $METRICS_RESOURCES_YAML" -echo " - $CNI_TAR_RESOURCES_FILE" -echo " - $METRICS_TAR_RESOURCES_FILE" diff --git a/scripts/sync-to-config-folder.sh b/scripts/sync-to-config-folder.sh index 06368c0568a..970dc7203da 100755 --- a/scripts/sync-to-config-folder.sh +++ b/scripts/sync-to-config-folder.sh @@ -2,7 +2,6 @@ set -euo pipefail set +x - SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" BUILD_DIR="${SCRIPTPATH}/../build" @@ -13,11 +12,11 @@ PR_ID=$(uuidgen | cut -d '-' -f1) SYNC_DIR="${BUILD_DIR}/config-sync" -BINARY_BASE="" +BINARY_BASE="aws-vpc-cni" INCLUDE_NOTES=0 MANUAL_VERIFY=1 -GH_CLI_VERSION="0.10.1" +GH_CLI_VERSION="2.22.1" GH_CLI_CONFIG_PATH="${HOME}/.config/gh/config.yml" KERNEL=$(uname -s | tr '[:upper:]' '[:lower:]') OS="${KERNEL}" @@ -25,11 +24,9 @@ if [[ "${KERNEL}" == "darwin" ]]; then OS="macOS" fi -VERSION=$(make -s -f "${SCRIPTPATH}/../Makefile" version) - USAGE=$(cat << EOM Usage: sync-to-config-folder -r - Updates config folder in master and release branch + Updates config folder in master branch Example: sync-to-config-folder -r "${REPO}" Optional: -r Github repo to sync to in the form of "org/name" (i.e. -r "${REPO}") @@ -63,6 +60,7 @@ fi echo $REPO +# Install GitHub CLI if [[ -z $(command -v gh) ]] || [[ ! $(gh --version) =~ $GH_CLI_VERSION ]]; then mkdir -p "${BUILD_DIR}"/gh curl -Lo "${BUILD_DIR}"/gh/gh.tar.gz "https://github.com/cli/cli/releases/download/v${GH_CLI_VERSION}/gh_${GH_CLI_VERSION}_${OS}_amd64.tar.gz" @@ -78,6 +76,7 @@ function restore_gh_config() { mv -f "${GH_CLI_CONFIG_PATH}.bkup" "${GH_CLI_CONFIG_PATH}" || : } +# Set auth tokens for GitHub CLI if [[ -n $(env | grep GITHUB_TOKEN) ]] && [[ -n "${GITHUB_TOKEN}" ]]; then trap restore_gh_config EXIT INT TERM ERR mkdir -p "${HOME}/.config/gh" @@ -105,6 +104,7 @@ rm -rf "${SYNC_DIR}" mkdir -p "${SYNC_DIR}" cd "${SYNC_DIR}" +# Clone upstream repo and setup git parameters gh repo clone aws/amazon-vpc-cni-k8s DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr -d '\n') @@ -116,6 +116,7 @@ git remote set-url origin https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@github. git config user.name "eks-networking-bot" git config user.email "eks-networking-bot@users.noreply.github.com" +# Fork master branch and create sync PR FORK_RELEASE_BRANCH="${BINARY_BASE}-${VERSION}-${PR_ID}" git checkout -b "${FORK_RELEASE_BRANCH}" origin/master @@ -136,48 +137,7 @@ EOM ) git push -u origin "${FORK_RELEASE_BRANCH}" -gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated manifest sync! 🥑" \ +gh pr create --title "${BINARY_BASE} ${VERSION} Automated manifest sync! 🥑" \ --body "${PR_BODY}" --repo ${REPO} -echo "✅ Manifest folder PR created for master" - -CLONE_DIR="${BUILD_DIR}/config-sync-release" -SYNC_DIR="$CLONE_DIR" -echo $SYNC_DIR -rm -rf "${SYNC_DIR}" -mkdir -p "${SYNC_DIR}" -cd "${SYNC_DIR}" -gh repo clone aws/amazon-vpc-cni-k8s -echo "Release branch $RELEASE_BRANCH" -CONFIG_DIR=amazon-vpc-cni-k8s/config/master -cd $CONFIG_DIR -REPO_NAME=$(echo ${REPO} | cut -d'/' -f2) -git remote set-url origin https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@github.com/"${GITHUB_USERNAME}"/"${REPO_NAME}".git - -git config user.name "eks-networking-bot" -git config user.email "eks-networking-bot@users.noreply.github.com" - -FORK_RELEASE_BRANCH="${BINARY_BASE}-${VERSION}-${PR_ID}" -git checkout -b "${FORK_RELEASE_BRANCH}" origin/$RELEASE_BRANCH - -cp $SCRIPTPATH/../build/cni-rel-yamls/${VERSION}/aws-k8s-cni*.yaml . -cp $SCRIPTPATH/../build/cni-rel-yamls/${VERSION}/cni-metrics-helper*.yaml . - -git add --all -git commit -m "${BINARY_BASE}: ${VERSION}" - -PR_BODY=$(cat << EOM -## ${BINARY_BASE} ${VERSION} Automated manifest folder Sync! 🤖🤖 - -### Description 📝 - -Updating all the generated release artifacts in master/config for $RELEASE_BRANCH branch. - -EOM -) - -git push -u origin "${FORK_RELEASE_BRANCH}":$RELEASE_BRANCH -gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated manifest sync! 🥑" \ - --body "${PR_BODY}" --repo ${REPO} --base ${RELEASE_BRANCH} - -echo "✅ Manifest folder PR created for $RELEASE_BRANCH" +echo "Manifest folder PR created for master" diff --git a/scripts/sync-to-eks-charts.sh b/scripts/sync-to-eks-charts.sh index 3d86dfa6761..8580c363e0b 100755 --- a/scripts/sync-to-eks-charts.sh +++ b/scripts/sync-to-eks-charts.sh @@ -6,13 +6,12 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" BUILD_DIR="${SCRIPTPATH}/../build" REPO="aws/amazon-vpc-cni-k8s" -HELM_CHART_NAME="aws-vpc-cni" +HELM_CHART_NAME=${HELM_CHART_NAME:-'aws-vpc-cni'} HELM_CHART_BASE_BIR="${SCRIPTPATH}/../charts" CHARTS_REPO="aws/eks-charts" CHARTS_REPO_NAME=$(echo ${CHARTS_REPO} | cut -d'/' -f2) -HELM_CHART_DIR="${HELM_CHART_BASE_BIR}/${HELM_CHART_NAME}" PR_ID=$(uuidgen | cut -d '-' -f1) SYNC_DIR="${BUILD_DIR}/eks-charts-sync" @@ -22,7 +21,7 @@ BINARY_BASE="" INCLUDE_NOTES=0 MANUAL_VERIFY=1 -GH_CLI_VERSION="0.10.1" +GH_CLI_VERSION="2.22.1" GH_CLI_CONFIG_PATH="${HOME}/.config/gh/config.yml" KERNEL=$(uname -s | tr '[:upper:]' '[:lower:]') OS="${KERNEL}" @@ -30,7 +29,7 @@ if [[ "${KERNEL}" == "darwin" ]]; then OS="macOS" fi -VERSION=$(make -s -f "${SCRIPTPATH}/../Makefile" version) +VERSION=$(echo $(make -s -f "${SCRIPTPATH}/../Makefile" version) | cut -d'-' -f1) USAGE=$(cat << EOM Usage: sync-to-eks-charts -r @@ -54,6 +53,7 @@ while getopts b:r:ny opt; do REPO="$OPTARG" ;; b ) # binary basename + HELM_CHART_NAME="$OPTARG" BINARY_BASE="$OPTARG" ;; n ) # Include release notes @@ -74,6 +74,13 @@ if [[ -n "${BINARY_BASE}" ]]; then HELM_CHART_NAME=${BINARY_BASE} fi +if [[ "$HELM_CHART_NAME" =~ ^(aws-vpc-cni|cni-metrics-helper)$ ]]; then + echo "starting to sync chart $HELM_CHART_NAME" +else + echo "invalid chart name, quit the script" + exit 0 +fi + if [[ -z "${REPO}" ]]; then echo "Repo (-r) must be specified if no \"make repo-full-name\" target exists" fi @@ -123,7 +130,6 @@ cd "${FORK_DIR}" git remote set-url origin https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@github.com/"${GITHUB_USERNAME}"/"${CHARTS_REPO_NAME}".git DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr -d '\n') - if diff -x ".*" -r "$HELM_CHART_DIR/" "${FORK_DIR}/stable/${HELM_CHART_NAME}/" &> /dev/null ; then echo " ✅ Charts already in sync; no updates needed" exit @@ -187,4 +193,4 @@ fi gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated Release! 🥑" \ --body "${PR_BODY}" --repo ${CHARTS_REPO} -echo "✅ EKS charts sync complete" +echo "EKS charts sync complete!" diff --git a/scripts/upload-resources-to-github.sh b/scripts/upload-resources-to-github.sh deleted file mode 100755 index 4ed62bc0a99..00000000000 --- a/scripts/upload-resources-to-github.sh +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# Script to upload release assets to Github. -# This script cleans up after itself in cases of parital failures. i.e. either all assets are uploaded or none -SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" -VERSION=$(make -s -f $SCRIPTPATH/../Makefile version) -BUILD_DIR=$SCRIPTPATH/../build/cni-rel-yamls/$VERSION -BINARY_DIR=$SCRIPTPATH/../build/bin - -CNI_TAR_RESOURCES_FILE=$BUILD_DIR/cni_individual-resources.tar -METRICS_TAR_RESOURCES_FILE=$BUILD_DIR/cni_metrics_individual-resources.tar -CNI_RESOURCES_YAML=$BUILD_DIR/aws-k8s-cni -METRICS_RESOURCES_YAML=$BUILD_DIR/cni-metrics-helper -REGIONS_FILE=$SCRIPTPATH/../charts/regions.json - -BINARIES_ONLY="false" - -USAGE=$(cat << 'EOM' - Usage: upload-resources-to-github [-b] - Upload release assets to GitHub - - Example: upload-resources-to-github -b - Optional: - -b Upload binaries only [DEFAULT: upload all the assets] -EOM -) - -# Process our input arguments -while getopts "b" opt; do - case ${opt} in - b ) # Binaries only - BINARIES_ONLY="true" - ;; - \? ) - echo "$USAGE" 1>&2 - exit - ;; - esac -done - -RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ - https://api.github.com/repos/aws/amazon-vpc-cni-k8s/releases | \ - jq --arg VERSION "$VERSION" '.[] | select(.tag_name==$VERSION) | .id') - -ASSET_IDS_UPLOADED=() - -trap 'handle_errors_and_cleanup $?' EXIT - -handle_errors_and_cleanup() { - if [ $1 -eq 0 ]; then - exit 0 - fi - - if [[ ${#ASSET_IDS_UPLOADED[@]} -ne 0 ]]; then - echo -e "\nCleaning up assets uploaded in the current execution of the script" - for asset_id in "${ASSET_IDS_UPLOADED[@]}"; do - echo "Deleting asset $asset_id" - curl -X DELETE \ - -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/aws/amazon-vpc-cni-k8s/releases/assets/$asset_id" - done - exit $1 - fi -} - -# $1: absolute path to asset -upload_asset() { - resp=$(curl --write-out '%{http_code}' --silent \ - -H "Authorization: token $GITHUB_TOKEN" \ - -H "Content-Type: $(file -b --mime-type $1)" \ - --data-binary @$1 \ - "https://uploads.github.com/repos/aws/amazon-vpc-cni-k8s/releases/$RELEASE_ID/assets?name=$(basename $1)") - - response_code=$(echo $resp | sed 's/\(.*\)}//') - response_content=$(echo $resp | sed "s/$response_code//") - - # HTTP success code expected - 201 Created - if [[ $response_code -eq 201 ]]; then - asset_id=$(echo $response_content | jq '.id') - ASSET_IDS_UPLOADED+=("$asset_id") - echo "✅ Created asset ID $asset_id successfully" - else - echo -e "❌ Upload failed with response code $response_code and message \n$response_content ❌" - exit 1 - fi -} - -RESOURCES_TO_UPLOAD=("$CNI_TAR_RESOURCES_FILE" "$METRICS_TAR_RESOURCES_FILE") -RESOURCES_TO_COPY=() - -COUNT=1 -echo -e "\nUploading release assets for release id '$RELEASE_ID' to Github" -for asset in ${RESOURCES_TO_UPLOAD[@]}; do - name=$(echo $asset | tr '/' '\n' | tail -1) - echo -e "\n $((COUNT++)). $name" - upload_asset $asset -done - -while read i; do - ecrRegion=`echo $i | jq '.ecrRegion' -r` - ecrAccount=`echo $i | jq '.ecrAccount' -r` - ecrDomain=`echo $i | jq '.ecrDomain' -r` - - if [ "$ecrRegion" = "us-west-2" ]; then - NEW_CNI_RESOURCES_YAML="${CNI_RESOURCES_YAML}.yaml" - NEW_METRICS_RESOURCES_YAML="${METRICS_RESOURCES_YAML}.yaml" - elif [ "$ecrRegion" = "cn-northwest-1" ]; then - NEW_CNI_RESOURCES_YAML="${CNI_RESOURCES_YAML}-cn.yaml" - NEW_METRICS_RESOURCES_YAML="${METRICS_RESOURCES_YAML}-cn.yaml" - else - NEW_CNI_RESOURCES_YAML="${CNI_RESOURCES_YAML}-${ecrRegion}.yaml" - NEW_METRICS_RESOURCES_YAML="${METRICS_RESOURCES_YAML}-${ecrRegion}.yaml" - fi - - RESOURCES_TO_UPLOAD=("$NEW_CNI_RESOURCES_YAML" "$NEW_METRICS_RESOURCES_YAML") - RESOURCES_TO_COPY+=("$NEW_CNI_RESOURCES_YAML") - RESOURCES_TO_COPY+=("$NEW_METRICS_RESOURCES_YAML") - - COUNT=1 - echo -e "\nUploading release assets for release id '$RELEASE_ID' to Github" - for asset in ${RESOURCES_TO_UPLOAD[@]}; do - name=$(echo $asset | tr '/' '\n' | tail -1) - echo -e "\n $((COUNT++)). $name" - upload_asset $asset - done -done < <(jq -c '.[]' $REGIONS_FILE) - -echo "✅ Attach artifacts to release page done"