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

ci: tf module to find common latest k8s version across 3 regions #214

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions ci/k8s-upgrade/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
data "google_container_engine_versions" "central1b" {
provider = google-beta
location = "europe-west6"
locals {
version_prefix = "1.28."
project = "galoy-infra-testflight"
}

data "google_container_engine_versions" "euwest6" {
provider = google-beta
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a for-each work with a list of locations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - I didn't think about that
wanted to keep it simple

location = "europe-west6"
version_prefix = local.version_prefix
project = local.project
}

data "google_container_engine_versions" "uscentral1" {
provider = google-beta
location = "us-central1"
version_prefix = local.version_prefix
project = local.project
}

data "google_container_engine_versions" "useast1" {
provider = google-beta
location = "us-east1"
version_prefix = local.version_prefix
project = local.project
}

locals {
# Convert outputs to sets
euwest6_versions = toset(data.google_container_engine_versions.euwest6.valid_master_versions)
uscentral1_versions = toset(data.google_container_engine_versions.uscentral1.valid_master_versions)
useast1_versions = toset(data.google_container_engine_versions.useast1.valid_master_versions)

# Find the intersection of all sets, i.e., common versions
common_versions = setintersection(local.euwest6_versions, local.uscentral1_versions, local.useast1_versions)
}

output "latest_version" {
value = data.google_container_engine_versions.central1b.latest_node_version
# Convert the set back to a list, sort it, and get the last element which is the highest version
value = length(local.common_versions) > 0 ? sort(tolist(local.common_versions))[length(local.common_versions) - 1] : ""
}
6 changes: 5 additions & 1 deletion ci/tasks/check-and-upgrade-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
set -eu

source pipeline-tasks/ci/tasks/helpers.sh

pushd pipeline-tasks/ci/k8s-upgrade

terraform init && terraform apply -auto-approve
LATEST_VERSION="$(terraform output -json | jq -r .latest_version.value)"

if [[ $LATEST_VERSION == "" ]]; then
echo "Failed to get latest version"
exit 1
fi

popd

pushd repo
Expand Down
Loading