From cd897b40cc6c33c3af98bb29af55b51edb12c359 Mon Sep 17 00:00:00 2001 From: lixiaoyuner <35456895+lixiaoyuner@users.noreply.github.com> Date: Sun, 10 Mar 2024 23:45:18 -0700 Subject: [PATCH] [ci] Fix and improve k8s master image build process (#18157) Why I did it When we change k8s script file to trigger k8s master image build, there's error reported. /agent/_work/_temp/433f6aca-4fd0-4a79-898e-49d7d0fc7465.sh: line 19: unexpected EOF while looking for matching `'' The main reason is something wrong with passing k8s_options variable(in file template-skipvstest.yml) to build pipeline. Need to fix and improve the passing variable process. Work item tracking Microsoft ADO (number only): 25063800 How I did it Separate the job of checking if k8s image build is needed from skipvstest checking job Build a VHDX k8s master image for convenient How to verify it No error found when k8s master image build is triggered We have a VHDX k8s master image in the build result. --- .azure-pipelines/azure-pipelines-build.yml | 10 +++++++--- .azure-pipelines/template-skipvstest.yml | 13 +++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.azure-pipelines/azure-pipelines-build.yml b/.azure-pipelines/azure-pipelines-build.yml index d7f87456f891..b5e5c732286a 100644 --- a/.azure-pipelines/azure-pipelines-build.yml +++ b/.azure-pipelines/azure-pipelines-build.yml @@ -135,9 +135,13 @@ jobs: make $BUILD_OPTIONS ENABLE_ASAN=y target/docker-sonic-vs.gz mv target/docker-sonic-vs.gz target/docker-sonic-vs-asan.gz fi - if [ "$(K8S_OPTIONS)" == 'INCLUDE_KUBERNETES_MASTER=y' ]; then - make $BUILD_OPTIONS $(K8S_OPTIONS) target/sonic-vs.img.gz - mv target/sonic-vs.img.gz target/sonic-vs-k8s.img.gz + if [ "$(K8S_MASTER_CHANGED)" == 'YES' ]; then + make $BUILD_OPTIONS INCLUDE_KUBERNETES_MASTER=y target/sonic-vs.img.gz + gzip -d target/sonic-vs.img.gz + SONIC_RUN_CMDS="qemu-img convert target/sonic-vs.img -O vhdx -o subformat=dynamic target/sonic-vs.vhdx" make $BUILD_OPTIONS sonic-slave-run + gzip target/sonic-vs.vhdx + mv target/sonic-vs.vhdx.gz target/sonic-vs-k8s.vhdx.gz + rm target/sonic-vs.img fi make $BUILD_OPTIONS target/docker-sonic-vs.gz target/sonic-vs.img.gz target/docker-ptf.gz make $BUILD_OPTIONS target/docker-ptf-sai.gz diff --git a/.azure-pipelines/template-skipvstest.yml b/.azure-pipelines/template-skipvstest.yml index ca968d009c94..86a2abd1f6fb 100644 --- a/.azure-pipelines/template-skipvstest.yml +++ b/.azure-pipelines/template-skipvstest.yml @@ -4,11 +4,16 @@ steps: set -ex tar_branch=origin/$(System.PullRequest.TargetBranchName) # Check if k8s master entrance script is changed - if ! git diff $tar_branch..HEAD --name-only | grep -F files/image_config/kubernetes/kubernetes_master_entrance.sh; then - echo "##vso[task.setvariable variable=K8S_OPTIONS;]INCLUDE_KUBERNETES_MASTER=n" - else - echo "##vso[task.setvariable variable=K8S_OPTIONS;]INCLUDE_KUBERNETES_MASTER=y" + K8S_MASTER_CHANGED=NO + if git diff $tar_branch..HEAD --name-only | grep -F files/image_config/kubernetes/kubernetes_master_entrance.sh; then + K8S_MASTER_CHANGED=YES fi + set +x + echo "##vso[task.setvariable variable=K8S_MASTER_CHANGED;]$K8S_MASTER_CHANGED" + displayName: "Check if k8s master image build is needed." + - script: | + set -ex + tar_branch=origin/$(System.PullRequest.TargetBranchName) git diff $tar_branch..HEAD --name-only | grep -v -f .azure-pipelines/vstest-exclude && exit 0 git diff $tar_branch..HEAD --name-only | grep -f .azure-pipelines/vstest-include && exit 0 set +x