Skip to content

Commit

Permalink
CI: Add k8s 1.30 version compatibility test
Browse files Browse the repository at this point in the history
Signed-off-by: tao.yang <tao.yang@daocloud.io>
Signed-off-by: ty-dc <tao.yang@daocloud.io>
  • Loading branch information
ty-dc committed May 26, 2024
1 parent 0d8872c commit b12f9ad
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
63 changes: 62 additions & 1 deletion .github/workflows/auto-diff-k8s-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ permissions: write-all
env:
CLUSTER_NAME: spider
E2E_TIME_OUT: 60m
PR_LABEL: pr/dependabot/github-actions, release/none
PR_REVIWER: weizhoublue
# The range of K8s versions that matrix tests expect to run. All distributions larger than it will be picked to run.
MINIMUM_K8S_VERSION: v1.21
K8S_MATRIX_FILE_PATH: .github/workflows/auto-diff-k8s-ci.yaml

on:
schedule:
Expand Down Expand Up @@ -72,6 +77,7 @@ jobs:
echo "INPUTS_K8S_VERSION=false" >> $GITHUB_ENV
echo "DEFAULT_K8S_VERSION=true" >> $GITHUB_ENV
fi
# some event, the tag is not sha, so checkout it and get sha
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -107,14 +113,69 @@ jobs:
ref: ${{ needs.get_ref.outputs.ref }}
submit: false
secrets: inherit

# update k8s matrix in step "call_k8s_matrix"
update_k8s_matrix:
needs: [get_ref]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.get_ref.outputs.ref }}

- name: get latest kind node version
run: |
bash ./test/scripts/update-kindnode-version.sh ${{ env.MINIMUM_K8S_VERSION }} ${{ env.K8S_MATRIX_FILE }}
if [ $? -eq 0 ]; then
echo "./test/scripts/update-kindnode-version.sh script failed"
echo "SKIP_CREATE_PR=true" >> $GITHUB_ENV
exit 0
fi
git_status=$(git status --porcelain)
if [[ -n "$git_status" ]]; then
echo "SKIP_CREATE_PR=false" >> $GITHUB_ENV
echo "The .github/workflows/auto-diff-k8s-ci.yaml of Spiderpool has changed."
else
echo "The .github/workflows/auto-diff-k8s-ci.yaml of Spiderpool has not changed."
echo "SKIP_CREATE_PR=true" >> $GITHUB_ENV
fi
- uses: crazy-max/ghaction-import-gpg@v6
if: ${{ env.SKIP_CREATE_PR != 'true' }}
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# Allow auto-merge on general
- name: Create Pull Request
if: ${{ env.SKIP_CREATE_PR != 'true' }}
id: create_pr
uses: peter-evans/create-pull-request@v5.0.2
with:
title: "robot updates kind node version in k8s matrix test"
commit-message: "robot updates kind node version in k8s matrix test"
branch-suffix: timestamp
committer: ty-dc <tao.yang@daocloud.io>
branch: robot/update_doc
delete-branch: true
signoff: true
base: main
token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}

call_k8s_matrix:
# k8s versions
strategy:
fail-fast: false
matrix:
# Synchronise with the latest releases of each version
version: [v1.22.7, v1.23.5, v1.24.4, v1.25.3, v1.26.2, v1.27.1, v1.28.0]
# If a new version of kind/node is released, it will be updated automatically.
version: [v1.25.16, v1.26.15, v1.27.13, v1.28.9, v1.29.4, v1.30.0, v1.23.17, v1.24.17, v1.22.17]
needs: [call_build_ci_image, get_ref, call_release_chart]
uses: ./.github/workflows/e2e-init.yaml
with:
Expand Down
65 changes: 65 additions & 0 deletions test/scripts/update-kindnode-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# Copyright 2024 Authors of spidernet-io
# SPDX-License-Identifier: Apache-2.0

# There are many versions of k8S that have been released. We focus on some specific versions,
# which are also the versions that we all adapt to.
# But as new K8S versions are released, we need to be compatible with more K8S versions.
# This script will detect whether there is a new version released, and then update the K8S matrix file

set -x
set -o errexit
set -o nounset
set -o pipefail

# MINIMUM_K8S_VERSION represents that k8s matrix tests should run on all distributions greater than this version.
MINIMUM_K8S_VERSION="$1"
[ -z "$MINIMUM_K8S_VERSION" ] && echo "error, miss MINIMUM_K8S_VERSION " && exit 1
K8S_Matrix_Test_File="$2"
[ -z "$K8S_MATRIX_FILE_PATH" ] && echo "error, miss K8S_MATRIX_FILE_PATH " && exit 1
[ ! -f "$K8S_MATRIX_FILE_PATH" ] && echo "error, could not find file $K8S_MATRIX_FILE_PATH " && exit 1


echo "Updating K8S matrix run file:$K8S_MATRIX_FILE_PATH..."
KIND_NODE_VERSION=""
function getAllLatestVersion() {
page=1
per_page=100
repo="kindest/node"
while true; do
response=$(curl -s --retry 10 "https://hub.docker.com/v2/repositories/$repo/tags/?page=$page&per_page=$per_page")
tags=$(echo "$response" | jq -r '.results[].name')
for tag in $tags; do
if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ ! $KIND_NODE_VERSION =~ ${tag%.*} && ${tag%.*} > ${MINIMUM_K8S_VERSION} ]]; then
KIND_NODE_VERSION+="$tag, "
fi
fi
done
next=$(echo "$response" | jq -r '.next')
if [[ "$next" == "null" ]]; then
break
fi
page=$((page + 1))
done
KIND_NODE_VERSION=${KIND_NODE_VERSION}
}

getAllLatestVersion

KIND_NODE_VERSION="${KIND_NODE_VERSION%, }"
KIND_NODE_VERSION="[$KIND_NODE_VERSION]"
ORIGIN_K8S_VERSION=$(grep -oP '(?<=version: )\[[^\]]+\]' $K8S_MATRIX_FILE_PATH)
echo "origin version: $ORIGIN_K8S_VERSION"
echo "updated version: $KIND_NODE_VERSION"
if [[ "$ORIGIN_K8S_VERSION" == "$KIND_NODE_VERSION" ]]; then
echo "ORIGIN_K8S_VERSION:$ORIGIN_K8S_VERSION and KIND_NODE_VERSION:$KIND_NODE_VERSION are equal"
exit 0
elif [[ ${#KIND_NODE_VERSION} -gt ${#ORIGIN_K8S_VERSION} ]]; then
echo "kind/node releases a new version, updates it in k8s matrix."
sed -i 's/\'"${ORIGIN_K8S_VERSION}"/"${KIND_NODE_VERSION}"'/' $K8S_MATRIX_FILE_PATH
else
echo "update failed, please check."
exit 1
fi

0 comments on commit b12f9ad

Please sign in to comment.