Skip to content

Commit

Permalink
Automatically upgrade Go version in Jenkins CI (#5388) (#5448)
Browse files Browse the repository at this point in the history
Everytime the Jenkins jobs are triggered, the jobs will check the golang
version on the testbed and compare with golang version in go.mod. If the
golang version is different, the jobs will automatically download and
install newer golang. If a new patch version is available, it will also
install it.

Signed-off-by: hjiajing <[email protected]>
  • Loading branch information
hjiajing authored Nov 29, 2023
1 parent 4634956 commit edac36c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 18 deletions.
9 changes: 6 additions & 3 deletions ci/jenkins/test-mc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CODECOV_TOKEN=""
COVERAGE=false
KIND=false
DEBUG=false
GOLANG_RELEASE_DIR=${WORKDIR}/golang-releases

multicluster_kubeconfigs=($EAST_CLUSTER_CONFIG $LEADER_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG)
membercluster_kubeconfigs=($EAST_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG)
Expand Down Expand Up @@ -284,7 +285,7 @@ function deliver_antrea_multicluster {
echo "====== Building Antrea for the Following Commit ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export PATH=${GOROOT}/bin:$PATH

git show --numstat
Expand Down Expand Up @@ -323,7 +324,7 @@ function deliver_multicluster_controller {
echo "====== Build Antrea Multiple Cluster Controller and YAMLs ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export PATH=${GOROOT}/bin:$PATH

DEFAULT_IMAGE=antrea/antrea-mc-controller:latest
Expand Down Expand Up @@ -387,7 +388,7 @@ function run_multicluster_e2e {
echo "====== Running Multicluster e2e Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -468,6 +469,8 @@ function collect_coverage {
}

trap clean_multicluster EXIT
source $WORKSPACE/ci/jenkins/utils.sh
check_and_upgrade_golang
clean_tmp
clean_images

Expand Down
9 changes: 6 additions & 3 deletions ci/jenkins/test-rancher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MODE="report"
DOCKER_REGISTRY=$(head -n1 "${WORKSPACE}/ci/docker-registry")
GO_VERSION=$(head -n1 "${WORKSPACE}/build/images/deps/go-version")
IMAGE_PULL_POLICY="Always"
GOLANG_RELEASE_DIR=${WORKDIR}/golang-releases

CLUSTER_NAME=""

Expand Down Expand Up @@ -130,7 +131,7 @@ function deliver_antrea {
echo "====== Building Antrea for the Following Commit ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE="${WORKSPACE}/../gocache"
export PATH=${GOROOT}/bin:$PATH

Expand Down Expand Up @@ -187,7 +188,7 @@ function run_e2e {
echo "====== Running Antrea E2E Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -222,7 +223,7 @@ function run_conformance {
echo "====== Running Antrea Conformance Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -263,6 +264,8 @@ function clean_tmp() {

rancher_login

source $WORKSPACE/ci/jenkins/utils.sh
check_and_upgrade_golang
clean_tmp
trap clean_vm_agent EXIT
deliver_antrea
Expand Down
7 changes: 5 additions & 2 deletions ci/jenkins/test-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DEFAULT_KUBECONFIG_PATH=$DEFAULT_WORKDIR/kube.conf
WORKDIR=$DEFAULT_WORKDIR
KUBECONFIG_PATH=$DEFAULT_KUBECONFIG_PATH
TEST_FAILURE=false
GOLANG_RELEASE_DIR=${WORKDIR}/golang-releases

# Cluster configuration
CLUSTER_NAME="kubernetes"
Expand Down Expand Up @@ -280,7 +281,7 @@ function install_on_windows {
function run_e2e_vms {
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand All @@ -304,7 +305,7 @@ function build_antrea_binary {
echo "====== Building Antrea binaries for the Following Commit ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKSPACE}/../gocache
export PATH=${GOROOT}/bin:$PATH

Expand All @@ -315,6 +316,8 @@ function build_antrea_binary {
}

trap clean_antrea EXIT
source $WORKSPACE/ci/jenkins/utils.sh
check_and_upgrade_golang
fetch_vm_ip
apply_antrea
build_antrea_binary
Expand Down
9 changes: 6 additions & 3 deletions ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TEST_FAILURE=false
CLUSTER_READY=false
DOCKER_REGISTRY=""
CONTROL_PLANE_NODE_ROLE="master|control-plane"
GOLANG_RELEASE_DIR=${WORKDIR}/golang-releases

_usage="Usage: $0 [--cluster-name <VMCClusterNameToUse>] [--kubeconfig <KubeconfigSavePath>] [--workdir <HomePath>]
[--log-mode <SonobuoyResultLogLevel>] [--testcase <e2e|conformance|all-features-conformance|whole-conformance|networkpolicy>]
Expand Down Expand Up @@ -341,7 +342,7 @@ function deliver_antrea {

export GO111MODULE=on
export GOPATH=$WORKDIR/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${GIT_CHECKOUT_DIR}/../gocache
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -476,7 +477,7 @@ function run_e2e {

export GO111MODULE=on
export GOPATH=$WORKDIR/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=$WORKDIR/.cache/go-build
export PATH=$GOROOT/bin:$PATH
export KUBECONFIG=$GIT_CHECKOUT_DIR/jenkins/out/kubeconfig
Expand Down Expand Up @@ -538,7 +539,7 @@ function run_conformance {

export GO111MODULE=on
export GOPATH=$WORKDIR/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=$WORKDIR/.cache/go-build
export PATH=$GOROOT/bin:$PATH
export KUBECONFIG=$GIT_CHECKOUT_DIR/jenkins/out/kubeconfig
Expand Down Expand Up @@ -680,6 +681,8 @@ SSH_WITH_ANTREA_CI_KEY="ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyC
SSH_WITH_UTILS_KEY="ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${WORKDIR}/utils/key"
SCP_WITH_UTILS_KEY="scp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${WORKDIR}/utils/key"

source $WORKSPACE/ci/jenkins/utils.sh
check_and_upgrade_golang
clean_tmp
if [[ "$RUN_GARBAGE_COLLECTION" == true ]]; then
garbage_collection
Expand Down
17 changes: 10 additions & 7 deletions ci/jenkins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ IP_MODE=""
K8S_VERSION="1.28.2-00"
WINDOWS_YAML_SUFFIX="windows"
WIN_IMAGE_NODE=""
GOLANG_RELEASE_DIR=${WORKDIR}/golang-releases

WINDOWS_CONFORMANCE_FOCUS="\[sig-network\].+\[Conformance\]|\[sig-windows\]"
WINDOWS_CONFORMANCE_SKIP="\[LinuxOnly\]|\[Slow\]|\[Serial\]|\[Disruptive\]|\[Flaky\]|\[Feature:.+\]|\[sig-cli\]|\[sig-storage\]|\[sig-auth\]|\[sig-api-machinery\]|\[sig-apps\]|\[sig-node\]|\[Privileged\]|should be able to change the type from|\[sig-network\] Services should be able to create a functioning NodePort service \[Conformance\]|Service endpoints latency should not be very high|should be able to create a functioning NodePort service for Windows"
Expand Down Expand Up @@ -316,7 +317,7 @@ function prepare_env {
echo "====== Building Antrea for the Following Commit ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKSPACE}/../gocache
export PATH=${GOROOT}/bin:$PATH

Expand Down Expand Up @@ -660,7 +661,7 @@ function deliver_antrea {
echo "====== Building Antrea for the Following Commit ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE="${WORKSPACE}/../gocache"
export PATH=${GOROOT}/bin:$PATH

Expand Down Expand Up @@ -768,7 +769,7 @@ function run_e2e {
echo "====== Running Antrea E2E Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -798,7 +799,7 @@ function run_conformance {
echo "====== Running Antrea Conformance Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -829,7 +830,7 @@ function run_e2e_windows {
echo "====== Running Antrea e2e Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -858,7 +859,7 @@ function run_conformance_windows {
echo "====== Running Antrea Conformance Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -893,7 +894,7 @@ function run_conformance_windows_containerd {
echo "====== Running Antrea Conformance Tests ======"
export GO111MODULE=on
export GOPATH=${WORKDIR}/go
export GOROOT=/usr/local/go
export GOROOT=${GOLANG_RELEASE_DIR}/go
export GOCACHE=${WORKDIR}/.cache/go-build
export PATH=$GOROOT/bin:$PATH

Expand Down Expand Up @@ -1143,6 +1144,8 @@ if [[ $TESTCASE =~ "multicast" ]]; then
./hack/generate-manifest.sh --encap-mode noEncap --multicast --multicast-interfaces "ens224" --verbose-log > build/yamls/antrea.yml
fi

source $WORKSPACE/ci/jenkins/utils.sh
check_and_upgrade_golang
clean_tmp
if [[ ${TESTCASE} == "windows-install-ovs" ]]; then
run_install_windows_ovs
Expand Down
63 changes: 63 additions & 0 deletions ci/jenkins/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# Copyright 2023 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function check_and_upgrade_golang() {
if [ -z "${GOLANG_RELEASE_DIR}" ]; then
GOLANG_RELEASE_DIR="/var/lib/jenkins/golang-releases"
fi
if [ ! -d ${GOLANG_RELEASE_DIR} ]; then
mkdir -p ${GOLANG_RELEASE_DIR}
fi
echo "====== Checking installed Golang version ======"
antrea_golang_version="go$(grep -E "^go\ " ${WORKSPACE}/go.mod | awk '{print $2}' | cut -d. -f1-2)"

while read -r i; do
version=$(echo ${i} | jq .version | tr -d '"')
if [[ "${version}" =~ "${antrea_golang_version}" ]]; then
if [ -d "${GOLANG_RELEASE_DIR}/${antrea_golang_version}" ]; then
current_version=$(${GOLANG_RELEASE_DIR}/${antrea_golang_version}/bin/go version | awk '{print $3}')
if [[ "${version}" == "${current_version}" ]]; then
echo "====== Golang ${version} is installed on the testbed, no need to download ======"
switch_golang "${version}"
break
fi
fi
echo "====== Installing Golang version "${version}" ======"
install_golang "${version}"
switch_golang "${version}"
break
fi
done < <(curl -s "https://go.dev/dl/?mode=json&include=all" | jq -c -r '.[]')
}

function install_golang() {
golang_version=$1
echo "====== Downloading Golang ${golang_version} ======"
curl https://dl.google.com/go/${golang_version}.linux-amd64.tar.gz -o /tmp/${golang_version}.linux-amd64.tar.gz
rm -rf /tmp/go || true
tar xf /tmp/${golang_version}.linux-amd64.tar.gz -C /tmp/
golang_version=$(echo ${golang_version} | cut -d. -f1-2)
rm -rf ${GOLANG_RELEASE_DIR}/${golang_version} || true
mv /tmp/go ${GOLANG_RELEASE_DIR}/${golang_version}
}

function switch_golang() {
golang_version=$1
golang_version=$(echo ${golang_version} | cut -d. -f1-2)
rm -rf ${GOLANG_RELEASE_DIR}/go
echo "====== Switching to Golang ${golang_version} ======"
ln -s ${GOLANG_RELEASE_DIR}/${golang_version} ${GOLANG_RELEASE_DIR}/go
}

0 comments on commit edac36c

Please sign in to comment.