From 72a4fab98bd10709a282c2a9d1c38eef48907ac7 Mon Sep 17 00:00:00 2001 From: jakemulley Date: Tue, 10 Oct 2023 17:19:37 +0100 Subject: [PATCH 1/3] Add script to create GitHub issues for EKS add-on upgrades --- scripts/README.md | 1 + scripts/eks-addon-updates.sh | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 scripts/eks-addon-updates.sh diff --git a/scripts/README.md b/scripts/README.md index 02ed28ca..cd556a74 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -5,3 +5,4 @@ This directory contains scripts to automatically create GitHub issues based on E | Script | Description | | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [eks-updates.sh](./eks-updates.sh) | Fetches current cluster versions and compares them against supported Kubernetes versions in EKS. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4857] to track upgrade progress. | +| [eks-addon-updates.sh](./eks-addon-updates.sh) | Fetches cluster add-on versions and compares them against the latest supported add-on version for the Kubernetes version a cluster is running. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4867] to track upgrade progress. diff --git a/scripts/eks-addon-updates.sh b/scripts/eks-addon-updates.sh new file mode 100644 index 00000000..ec1aee8d --- /dev/null +++ b/scripts/eks-addon-updates.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# list clusters +CLUSTERS=(live live-2 manager) + +for CLUSTER in "${CLUSTERS[@]}"; +do + # get cluster versions + CLUSTER_VERSION=$(aws eks describe-cluster --name "$CLUSTER" | jq -r '.cluster.version') + + # get addons + CLUSTER_ADDONS=($(aws eks list-addons --cluster-name "$CLUSTER" | jq -r '.addons[] | .')) + + for CLUSTER_ADDON in "${CLUSTER_ADDONS[@]}"; + do + # get addon version for cluster + CLUSTER_ADDON_VERSION=$(aws eks describe-addon --cluster-name "$CLUSTER" --addon-name "$CLUSTER_ADDON" | jq -r '.addon.addonVersion') + + # get latest supported addon version for the cluster/k8s version + LATEST_SUPPORTED_ADDON_VERSION_FOR_KUBERNETES_VERSION=$(aws eks describe-addon-versions --addon-name "$CLUSTER_ADDON" --kubernetes-version "$CLUSTER_VERSION" | jq -r '.addons[0].addonVersions[0].addonVersion') + + TITLE="EKS addon ($CLUSTER): Update $CLUSTER_ADDON from $CLUSTER_ADDON_VERSION to the latest version" + + if [[ "$LATEST_SUPPORTED_ADDON_VERSION_FOR_KUBERNETES_VERSION" != "$CLUSTER_ADDON_VERSION" ]]; then # check if newer version is supported + BODY=$(cat << END +## Background + +There is a new version of the EKS add-on $CLUSTER_ADDON. $CLUSTER_ADDON needs updating on the $CLUSTER cluster. When this issue was created, the latest supported add-on version for Kubernetes $CLUSTER_VERSION was $LATEST_SUPPORTED_ADDON_VERSION_FOR_KUBERNETES_VERSION. + +See the [Amazon EKS add-ons](https://docs.aws.amazon.com/eks/latest/userguide/eks-add-ons.html) documentation for more information about addons, or find the latest versions for these EKS add-ons directly: + +- [coredns](https://docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html) +- [kube-proxy](https://docs.aws.amazon.com/eks/latest/userguide/managing-kube-proxy.html) +- [vpc-cni](https://docs.aws.amazon.com/eks/latest/userguide/managing-vpc-cni.html) +END +) + + GITHUB_ISSUES=$(gh issue list --repo ministryofjustice/cloud-platform --state all --search "in:title \"$TITLE\"" --limit 50 --json title | jq -r "[ .[] | select(.title == \"$TITLE\") ] | length") + + # if no issues yet, create one + if (( $(echo "0 == $GITHUB_ISSUES" | bc -l) )); then + echo "No issue found for $TITLE, creating one..." + gh issue create --title "$TITLE" --body "$BODY" --repo ministryofjustice/cloud-platform + else + echo "Issue already exists for $TITLE, skipping..." + fi + else + echo "Up to date, skipping issue creation for $TITLE" + fi + + done +done From 97e99880b9639c4512238f10c1007c89e60238f4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 10 Oct 2023 16:20:50 +0000 Subject: [PATCH 2/3] Commit changes made by code formatters --- scripts/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index cd556a74..6e1772bd 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -2,7 +2,7 @@ This directory contains scripts to automatically create GitHub issues based on EKS upgrades. -| Script | Description | -| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [eks-updates.sh](./eks-updates.sh) | Fetches current cluster versions and compares them against supported Kubernetes versions in EKS. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4857] to track upgrade progress. | -| [eks-addon-updates.sh](./eks-addon-updates.sh) | Fetches cluster add-on versions and compares them against the latest supported add-on version for the Kubernetes version a cluster is running. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4867] to track upgrade progress. +| Script | Description | +| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [eks-updates.sh](./eks-updates.sh) | Fetches current cluster versions and compares them against supported Kubernetes versions in EKS. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4857] to track upgrade progress. | +| [eks-addon-updates.sh](./eks-addon-updates.sh) | Fetches cluster add-on versions and compares them against the latest supported add-on version for the Kubernetes version a cluster is running. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4867] to track upgrade progress. | From ad6ea77e82c90ac0de5faefe53320bb8df3f4cc4 Mon Sep 17 00:00:00 2001 From: jakemulley Date: Tue, 10 Oct 2023 17:22:42 +0100 Subject: [PATCH 3/3] Fix links --- scripts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 6e1772bd..4647c4ac 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -4,5 +4,5 @@ This directory contains scripts to automatically create GitHub issues based on E | Script | Description | | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| [eks-updates.sh](./eks-updates.sh) | Fetches current cluster versions and compares them against supported Kubernetes versions in EKS. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4857] to track upgrade progress. | -| [eks-addon-updates.sh](./eks-addon-updates.sh) | Fetches cluster add-on versions and compares them against the latest supported add-on version for the Kubernetes version a cluster is running. It creates a GitHub issue (example)[https://github.com/ministryofjustice/cloud-platform/issues/4867] to track upgrade progress. | +| [eks-updates.sh](./eks-updates.sh) | Fetches current cluster versions and compares them against supported Kubernetes versions in EKS. It creates a GitHub issue [example](https://github.com/ministryofjustice/cloud-platform/issues/4857) to track upgrade progress. | +| [eks-addon-updates.sh](./eks-addon-updates.sh) | Fetches cluster add-on versions and compares them against the latest supported add-on version for the Kubernetes version a cluster is running. It creates a GitHub issue [example](https://github.com/ministryofjustice/cloud-platform/issues/4867) to track upgrade progress. |