Skip to content

Commit

Permalink
Merge pull request #8529 from OpenMined/yash/helm-upgrade
Browse files Browse the repository at this point in the history
Add helm upgrade test
  • Loading branch information
yashgorana authored Mar 2, 2024
2 parents 1ed779a + 4b32423 commit 3036976
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/pr-tests-helm-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: PR Tests - Helm Upgrade

on:
# Re-enable when we have a stable helm chart
# pull_request:
# branches:
# - dev
# paths:
# - packages/grid/helm/syft/**

workflow_dispatch:
inputs:
upgrade_type:
description: "Select upgrade path type"
required: false
default: "BetaToDev"
type: choice
options:
- BetaToDev
- ProdToBeta
- ProdToDev

concurrency:
group: pr-tests-helm-upgrade
cancel-in-progress: true

jobs:
pr-tests-helm-upgrade:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew update
# 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)"
# 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()
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
tox -e dev.k8s.destroyall
53 changes: 53 additions & 0 deletions packages/grid/scripts/helm_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! /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" == "ProdToBeta" ]; 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=""
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
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
17 changes: 16 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_TYPE:ProdToBeta}
allowlist_externals =
bash
commands =
bash ./scripts/helm_upgrade.sh {env:UPGRADE_TYPE}

[testenv:syftcli.test.unit]
description = Syft CLI Unit Tests
deps =
Expand All @@ -933,14 +945,17 @@ 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'

; add patches to host
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
Expand Down

0 comments on commit 3036976

Please sign in to comment.