From 81c76f5f1a0f118905a9932b596fc1aedf5c3d32 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 26 Feb 2024 18:00:16 +0530 Subject: [PATCH 1/7] [tox] add helm upgrade test --- .github/workflows/pr-tests-helm-upgrade.yml | 32 ++++++++++++++ packages/grid/scripts/helm_upgrade.sh | 48 +++++++++++++++++++++ tox.ini | 12 ++++++ 3 files changed, 92 insertions(+) create mode 100644 .github/workflows/pr-tests-helm-upgrade.yml create mode 100644 packages/grid/scripts/helm_upgrade.sh diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml new file mode 100644 index 00000000000..6a9a85aab20 --- /dev/null +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -0,0 +1,32 @@ +name: PR Tests - Helm Upgrade + +on: + pull_request: + branches: + - dev + paths: + - packages/grid/helm/syft/** + + workflow_dispatch: + inputs: + none: + description: "Run helm upgrade" + required: false + +jobs: + pr-tests-helm-upgrade: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install Dependencies + if: steps.changes.outputs.syft == 'true' + run: | + pip install --upgrade tox + + - name: Upgrade helm on latest beta + run: | + tox -e dev.k8s.start + tox -e syft.test.helm.upgrade + tox -e dev.k8s.destroy diff --git a/packages/grid/scripts/helm_upgrade.sh b/packages/grid/scripts/helm_upgrade.sh new file mode 100644 index 00000000000..fe88815d9d4 --- /dev/null +++ b/packages/grid/scripts/helm_upgrade.sh @@ -0,0 +1,48 @@ +#! /bin/bash + +set -e + +HELM_REPO="openmined/syft" +DOMAIN_NAME="test-domain" +KUBE_NAMESPACE="syft" +KUBE_CONTEXT=${KUBE_CONTEXT:-"k3d-syft-dev"} + +UPGRADE_TYPE=$1 + +PROD="openmined/syft" +BETA="openmined/syft --devel" +DEV="./helm/syft" + +if [ "$UPGRADE_TYPE" == "ProdToDev" ]; then + INSTALL_SOURCE=$PROD # latest published prod + UPGRADE_SOURCE=$BETA # latest published beta + INSTALL_ARGS="" + UPGRADE_ARGS="" +elif [ "$UPGRADE_TYPE" == "BetaToDev" ]; then + INSTALL_SOURCE=$BETA # latest published beta + UPGRADE_SOURCE=$DEV # local chart + INSTALL_ARGS="" + UPGRADE_ARGS="" +else + echo Invalid upgrade type $UPGRADE_TYPE + exit 1 +fi + +kubectl config use-context $KUBE_CONTEXT +kubectl delete namespace syft || true +helm repo add openmined https://openmined.github.io/PySyft/helm +helm repo update openmined + +echo Installing syft... +helm install $DOMAIN_NAME $INSTALL_SOURCE $INSTALL_ARGS --namespace $KUBE_NAMESPACE --create-namespace +helm ls -A + +WAIT_TIME=5 bash ./scripts/wait_for.sh service backend --namespace $KUBE_NAMESPACE +WAIT_TIME=5 bash ./scripts/wait_for.sh pod default-pool-0 --namespace $KUBE_NAMESPACE + +echo Upgrading syft... +helm upgrade $DOMAIN_NAME $UPGRADE_SOURCE $UPGRADE_ARGS --namespace $KUBE_NAMESPACE +helm ls -A + +echo "Post-upgrade sleep" && sleep 5 +WAIT_TIME=5 bash ./scripts/wait_for.sh service backend --namespace $KUBE_NAMESPACE diff --git a/tox.ini b/tox.ini index 0a368808cac..743f05e84f0 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ envlist = syft.build.helm syft.package.helm syft.test.helm + syft.test.helm.upgrade syft.protocol.check syftcli.test.unit syftcli.publish @@ -916,6 +917,17 @@ commands = bash -c "k3d cluster delete syft || true" bash -c "docker volume rm k3d-syft-images --force || true" +[testenv:syft.test.helm.upgrade] +description = Test helm upgrade +changedir = {toxinidir}/packages/grid/ +passenv=HOME,USER,KUBE_CONTEXT +setenv = + UPGRADE_TYPE = {env:UPGRADE_PATH:ProdToDev} +allowlist_externals = + bash +commands = + bash ./scripts/helm_upgrade.sh {env:UPGRADE_TYPE} + [testenv:syftcli.test.unit] description = Syft CLI Unit Tests deps = From b92453ef8e5f704f617a5f59d65dcaf6e4dc18ca Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 26 Feb 2024 20:30:01 +0530 Subject: [PATCH 2/7] [ci] upgrade from beta to dev --- .github/workflows/pr-tests-helm-upgrade.yml | 2 +- packages/grid/scripts/helm_upgrade.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml index 6a9a85aab20..7dc98e7fe56 100644 --- a/.github/workflows/pr-tests-helm-upgrade.yml +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -28,5 +28,5 @@ jobs: - name: Upgrade helm on latest beta run: | tox -e dev.k8s.start - tox -e syft.test.helm.upgrade + UPGRADE_TYPE=BetaToDev tox -e syft.test.helm.upgrade tox -e dev.k8s.destroy diff --git a/packages/grid/scripts/helm_upgrade.sh b/packages/grid/scripts/helm_upgrade.sh index fe88815d9d4..4b1831690de 100644 --- a/packages/grid/scripts/helm_upgrade.sh +++ b/packages/grid/scripts/helm_upgrade.sh @@ -20,7 +20,7 @@ if [ "$UPGRADE_TYPE" == "ProdToDev" ]; then UPGRADE_ARGS="" elif [ "$UPGRADE_TYPE" == "BetaToDev" ]; then INSTALL_SOURCE=$BETA # latest published beta - UPGRADE_SOURCE=$DEV # local chart + UPGRADE_SOURCE=$DEV # local chart INSTALL_ARGS="" UPGRADE_ARGS="" else From 68086f81fd9b3748fe89ffe2b4a196da93084f85 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 26 Feb 2024 20:36:34 +0530 Subject: [PATCH 3/7] [ci] fix dep install --- .github/workflows/pr-tests-helm-upgrade.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml index 7dc98e7fe56..194787bac19 100644 --- a/.github/workflows/pr-tests-helm-upgrade.yml +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -21,7 +21,6 @@ jobs: - uses: actions/checkout@v4 - name: Install Dependencies - if: steps.changes.outputs.syft == 'true' run: | pip install --upgrade tox From 15002fdef1875b6053ed77168b07bfb7bffefab5 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 26 Feb 2024 21:37:15 +0530 Subject: [PATCH 4/7] [ci] fix action --- .github/workflows/pr-tests-helm-upgrade.yml | 39 ++++++++++++++++++--- tox.ini | 7 ++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml index 194787bac19..54909f4796d 100644 --- a/.github/workflows/pr-tests-helm-upgrade.yml +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -1,6 +1,12 @@ name: PR Tests - Helm Upgrade on: + push: + paths: + - .github/workflows/pr-tests-helm-upgrade.yml + - tox.ini + - packages/grid/helm/syft/** + pull_request: branches: - dev @@ -13,6 +19,10 @@ on: description: "Run helm upgrade" required: false +concurrency: + group: pr-tests-helm-upgrade + cancel-in-progress: true + jobs: pr-tests-helm-upgrade: runs-on: ubuntu-latest @@ -20,12 +30,33 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install Dependencies + - name: Install dependencies run: | - pip install --upgrade tox + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + brew update - - name: Upgrade helm on latest beta + # Install python deps + pip install --upgrade pip + pip install tox + + # Install kubernetes + brew install helm k3d devspace kubectl + + - name: Setup cluster run: | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + tox -e dev.k8s.start + + - name: Upgrade helm chart + run: | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + UPGRADE_TYPE=BetaToDev tox -e syft.test.helm.upgrade - tox -e dev.k8s.destroy + + - name: Destroy cluster + if: always() + run: | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + + tox -e dev.k8s.destroyall diff --git a/tox.ini b/tox.ini index 743f05e84f0..c7989f8aa6a 100644 --- a/tox.ini +++ b/tox.ini @@ -922,7 +922,7 @@ description = Test helm upgrade changedir = {toxinidir}/packages/grid/ passenv=HOME,USER,KUBE_CONTEXT setenv = - UPGRADE_TYPE = {env:UPGRADE_PATH:ProdToDev} + UPGRADE_TYPE = {env:UPGRADE_TYPE:ProdToDev} allowlist_externals = bash commands = @@ -945,6 +945,9 @@ allowlist_externals = bash sudo commands = + ; check k3d version + bash -c 'k3d --version' + ; create registry bash -c 'k3d registry create registry.localhost --port 5800 -v $HOME/.k3d-registry:/var/lib/registry || true' @@ -952,7 +955,7 @@ commands = bash -c 'if ! grep -q k3d-registry.localhost /etc/hosts; then sudo {envpython} scripts/patch_hosts.py --add-k3d-registry --fix-docker-hosts; fi' ; Fail this command if registry is not working - bash -c 'URL=http://k3d-registry.localhost:5800/v2/_catalog; curl -X GET $URL' + bash -c 'curl --retry 5 --retry-all-errors http://k3d-registry.localhost:5800/v2/_catalog' [testenv:dev.k8s.patch.coredns] description = Patch CoreDNS to resolve k3d-registry.localhost From bb301860e1dd3d09cd9cbaff13608b40c52966b8 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 26 Feb 2024 21:43:14 +0530 Subject: [PATCH 5/7] [ci] add Prod to Dev + fixes --- .github/workflows/pr-tests-helm-upgrade.yml | 13 ++++++++++--- packages/grid/scripts/helm_upgrade.sh | 7 ++++++- tox.ini | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml index 54909f4796d..648613e29a3 100644 --- a/.github/workflows/pr-tests-helm-upgrade.yml +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -15,9 +15,15 @@ on: workflow_dispatch: inputs: - none: - description: "Run helm upgrade" + upgrade_type: + description: "Select upgrade path type" required: false + default: "BetaToDev" + type: choice + options: + - BetaToDev + - ProdToBeta + - ProdToDev concurrency: group: pr-tests-helm-upgrade @@ -52,7 +58,8 @@ jobs: run: | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - UPGRADE_TYPE=BetaToDev tox -e syft.test.helm.upgrade + # default upgrade is beta to dev + UPGRADE_TYPE=${{ github.event.inputs.upgrade_type }} tox -e syft.test.helm.upgrade - name: Destroy cluster if: always() diff --git a/packages/grid/scripts/helm_upgrade.sh b/packages/grid/scripts/helm_upgrade.sh index 4b1831690de..82418eaa99a 100644 --- a/packages/grid/scripts/helm_upgrade.sh +++ b/packages/grid/scripts/helm_upgrade.sh @@ -13,7 +13,7 @@ PROD="openmined/syft" BETA="openmined/syft --devel" DEV="./helm/syft" -if [ "$UPGRADE_TYPE" == "ProdToDev" ]; then +if [ "$UPGRADE_TYPE" == "ProdToBeta" ]; then INSTALL_SOURCE=$PROD # latest published prod UPGRADE_SOURCE=$BETA # latest published beta INSTALL_ARGS="" @@ -23,6 +23,11 @@ elif [ "$UPGRADE_TYPE" == "BetaToDev" ]; then UPGRADE_SOURCE=$DEV # local chart INSTALL_ARGS="" UPGRADE_ARGS="" +elif [ "$UPGRADE_TYPE" == "ProdToDev" ]; then + INSTALL_SOURCE=$PROD # latest published prod + UPGRADE_SOURCE=$DEV # local chart + INSTALL_ARGS="" + UPGRADE_ARGS="" else echo Invalid upgrade type $UPGRADE_TYPE exit 1 diff --git a/tox.ini b/tox.ini index c7989f8aa6a..6577929ee25 100644 --- a/tox.ini +++ b/tox.ini @@ -922,7 +922,7 @@ description = Test helm upgrade changedir = {toxinidir}/packages/grid/ passenv=HOME,USER,KUBE_CONTEXT setenv = - UPGRADE_TYPE = {env:UPGRADE_TYPE:ProdToDev} + UPGRADE_TYPE = {env:UPGRADE_TYPE:ProdToBeta} allowlist_externals = bash commands = From d98b7309499c4f5cf5b4058a49e0ac08cb8db147 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 26 Feb 2024 21:46:32 +0530 Subject: [PATCH 6/7] [ci] action fixes --- .github/workflows/pr-tests-helm-upgrade.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml index 648613e29a3..313c3717d21 100644 --- a/.github/workflows/pr-tests-helm-upgrade.yml +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -58,8 +58,10 @@ jobs: run: | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - # default upgrade is beta to dev - UPGRADE_TYPE=${{ github.event.inputs.upgrade_type }} tox -e syft.test.helm.upgrade + # default upgrade is beta to dev, but override with input if provided + UPGRADE_TYPE_INPUT=${{ github.event.inputs.upgrade_type }} + export UPGRADE_TYPE=${UPGRADE_TYPE_INPUT:-BetaToDev} + tox -e syft.test.helm.upgrade - name: Destroy cluster if: always() From a942cc04af5e030ae77d3c6a1dd423cf2090a2e6 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Fri, 1 Mar 2024 21:09:31 +0530 Subject: [PATCH 7/7] [ci] run action manually --- .github/workflows/pr-tests-helm-upgrade.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-tests-helm-upgrade.yml b/.github/workflows/pr-tests-helm-upgrade.yml index 313c3717d21..be8bbc21996 100644 --- a/.github/workflows/pr-tests-helm-upgrade.yml +++ b/.github/workflows/pr-tests-helm-upgrade.yml @@ -1,17 +1,12 @@ name: PR Tests - Helm Upgrade on: - push: - paths: - - .github/workflows/pr-tests-helm-upgrade.yml - - tox.ini - - packages/grid/helm/syft/** - - pull_request: - branches: - - dev - paths: - - packages/grid/helm/syft/** + # Re-enable when we have a stable helm chart + # pull_request: + # branches: + # - dev + # paths: + # - packages/grid/helm/syft/** workflow_dispatch: inputs: