Skip to content

Commit

Permalink
Merge pull request #4859 from ministryofjustice/add-eks-script
Browse files Browse the repository at this point in the history
Add script to create GitHub issues for EKS upgrades
  • Loading branch information
jakemulley authored Oct 10, 2023
2 parents 3358323 + 80beb3c commit 2bdda65
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Creating issues for EKS upgrades

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. |
42 changes: 42 additions & 0 deletions scripts/eks-updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# get supported versions
VERSIONS=($(aws eks describe-addon-versions | jq -r ".addons[] | .addonVersions[] | .compatibilities[] | .clusterVersion" | sort | uniq))

# 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')

for VERSION in "${VERSIONS[@]}";
do
if [[ "$CLUSTER_VERSION" != "$VERSION" ]]; then
if (( $(echo "$CLUSTER_VERSION < $VERSION" | bc -l) )); then # check if newer version is supported
TITLE="EKS: Upgrade $CLUSTER to Kubernetes v$VERSION";
BODY=$(cat << END
## Background
EKS supports Kubernetes $VERSION. The $CLUSTER cluster needs upgrading to Kubernetes $VERSION.
See [Amazon EKS Kubernetes versions](https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html) for more details.
END
)

# get github issues and check if one already exists
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" --label EPIC --repo ministryofjustice/cloud-platform
else
echo "Issue already exists for $TITLE, skipping..."
fi
fi
fi
done
done

0 comments on commit 2bdda65

Please sign in to comment.