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 25, 2024
1 parent 0d8872c commit 3037dc8
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
55 changes: 54 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,8 @@ permissions: write-all
env:
CLUSTER_NAME: spider
E2E_TIME_OUT: 60m
PR_LABEL: pr/dependabot/github-actions, release/none
PR_REVIWER: weizhoublue

on:
schedule:
Expand Down Expand Up @@ -42,6 +44,7 @@ jobs:
e2e_enabled: ${{ env.RUN_E2E_ENABLED }}
inputs_k8s_version: ${{ env.INPUTS_K8S_VERSION }}
default_k8s_version: ${{ env.DEFAULT_K8S_VERSION }}
kind_node_version: ${{ env.KIND_NODE_VERSION }}
steps:
- name: Get Ref
id: get_ref
Expand Down Expand Up @@ -72,6 +75,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 @@ -108,13 +112,62 @@ jobs:
submit: false
secrets: inherit

check_kind_node_version:
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
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
48 changes: 48 additions & 0 deletions test/scripts/update-kindnode-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

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

echo "Updating k8s matrix run file..."
KIND_NODE_VERSION=""
function update_kindnode_version() {
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
# Compatibility testing 1.22 to latest version
if [[ ! $KIND_NODE_VERSION =~ ${tag%.*} && ${tag%.*} > "v1.21" ]]; 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}
}

update_kindnode_version

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

0 comments on commit 3037dc8

Please sign in to comment.