From 91d160c6e28e53acdfae679687c50f22d98c4fb1 Mon Sep 17 00:00:00 2001 From: bfjelds Date: Tue, 24 Nov 2020 12:46:20 -0800 Subject: [PATCH] Enable PRs to test changes to helm charts [SAME VERSION] (#146) * enable PRs to test changes to helm charts * handle manual job, fix push and release conditional * trigger e2e for helm changes --- .github/workflows/run-test-cases.yml | 33 ++++++++++++++++++++-------- test/run-end-to-end.py | 7 +++--- test/shared_test_code.py | 10 ++++----- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/run-test-cases.yml b/.github/workflows/run-test-cases.yml index c37edd901..13bdf6e5f 100644 --- a/.github/workflows/run-test-cases.yml +++ b/.github/workflows/run-test-cases.yml @@ -12,6 +12,7 @@ on: - .github/workflows/run-test-cases.yml - build/containers/Dockerfile.agent - build/containers/Dockerfile.controller + - deployment/helm/** - agent/** - controller/** - shared/** @@ -29,6 +30,7 @@ on: - .github/workflows/run-test-cases.yml - build/containers/Dockerfile.agent - build/containers/Dockerfile.controller + - deployment/helm/** - agent/** - controller/** - shared/** @@ -46,6 +48,7 @@ on: - .github/workflows/run-test-cases.yml - build/containers/Dockerfile.agent - build/containers/Dockerfile.controller + - deployment/helm/** - agent/** - controller/** - shared/** @@ -200,15 +203,6 @@ jobs: - name: Add Akri Helm Chart run: helm repo add akri-helm-charts https://deislabs.github.io/akri/ - # When event_name==release, the Helm chart is named 'akri' - - if: github.event_name == 'release' - name: Pull akri helm chart when event_name == release - run: echo akri > /tmp/chart_name.txt - # When event_name!=release, the Helm chart is named 'akri-dev' - - if: github.event_name != 'release' - name: Pull akri-dev helm chart when event_name != release - run: echo akri-dev > /tmp/chart_name.txt - # For push and release, we need to wait for the Helm chart and # associated containers to build. - if: github.event_name == 'push' || github.event_name == 'release' @@ -229,6 +223,27 @@ jobs: name: Use current version for push run: cat version.txt > /tmp/version_to_test.txt + # For workflow_dispatch, pull_request and pull_request_target, use the files + # in deployment/helm as basis for helm install ... this enables us to test + # any changes made to the helm chart files in a PR (where no helm chart is + # published) + - if: github.event_name != 'push' && github.event_name != 'release' + name: Tell Helm to use the files in deployment/helm to build chart + run: | + echo './deployment/helm' > /tmp/helm_chart_location.txt + # For push, use a specific version of the `akri-dev` charts that are built and + # published by the helm workflow. + - if: github.event_name == 'push' + name: Tell Helm to use the `akri-dev` published charts + run: | + echo "akri-helm-charts/akri-dev --version $(cat /tmp/version_to_test.txt)" > /tmp/helm_chart_location.txt + # For release, use a specific version of the `akri` charts that are built and + # published by the helm workflow. + - if: github.event_name == 'release' + name: Tell Helm to use the `akri` published charts + run: | + echo "akri-helm-charts/akri --version $(cat /tmp/version_to_test.txt)" > /tmp/helm_chart_location.txt + - name: Execute test script ${{ matrix.test-file }} run: python ${{ matrix.test-file }} - name: Upload Agent log as artifact diff --git a/test/run-end-to-end.py b/test/run-end-to-end.py index 9ecdd58f2..a77c2413c 100644 --- a/test/run-end-to-end.py +++ b/test/run-end-to-end.py @@ -25,14 +25,13 @@ def main(): shared_test_code.major_version = "v" + test_version.split(".")[0] print("Testing major version: {}".format(shared_test_code.major_version)) - print("Installing Akri Helm chart: {}".format(test_version)) - helm_chart_name = shared_test_code.get_helm_chart_name() - print("Get Akri Helm chart: {}".format(helm_chart_name)) + helm_chart_location = shared_test_code.get_helm_chart_location() + print("Get Akri Helm chart: {}".format(helm_chart_location)) cri_args = shared_test_code.get_cri_args() print("Providing Akri Helm chart with CRI args: {}".format(cri_args)) extra_helm_args = shared_test_code.get_extra_helm_args() print("Providing Akri Helm chart with extra helm args: {}".format(extra_helm_args)) - helm_install_command = "helm install akri akri-helm-charts/{} --debug --version {} --set debugEcho.enabled=true --set debugEcho.name={} --set debugEcho.shared=false --set agent.allowDebugEcho=true {} {}".format(helm_chart_name, test_version, shared_test_code.DEBUG_ECHO_NAME, cri_args, extra_helm_args) + helm_install_command = "helm install akri {} --set debugEcho.enabled=true --set debugEcho.name={} --set debugEcho.shared=false --set agent.allowDebugEcho=true {} {} --debug ".format(helm_chart_location, shared_test_code.DEBUG_ECHO_NAME, cri_args, extra_helm_args) print("Helm command: {}".format(helm_install_command)) os.system(helm_install_command) diff --git a/test/shared_test_code.py b/test/shared_test_code.py index 9dfd967a5..d8eaa1d3f 100644 --- a/test/shared_test_code.py +++ b/test/shared_test_code.py @@ -16,9 +16,9 @@ RUNTIME_COMMAND_FILE = "/tmp/runtime_cmd_to_test.txt" HELM_CRI_ARGS_FILE = "/tmp/cri_args_to_test.txt" VERSION_FILE = "/tmp/version_to_test.txt" -HELM_CHART_NAME_FILE = "/tmp/chart_name.txt" SLEEP_DURATION_FILE = "/tmp/sleep_duration.txt" EXTRA_HELM_ARGS_FILE = "/tmp/extra_helm_args.txt" +HELM_CHART_LOCATION = "/tmp/helm_chart_location.txt" SLEEP_INTERVAL = 20 CONTROLLER_POD_LABEL_SELECTOR = "app=" + CONTROLLER_POD_NAME @@ -32,6 +32,10 @@ agent_pod_name = "" controller_pod_name = "" +def get_helm_chart_location(): + # Get helm chart location passed in helm install command (i.e. `repo/chart --version X.Y.Z` or `./deployment/helm`) + return open(HELM_CHART_LOCATION, "r").readline().rstrip() + def get_extra_helm_args(): # Get any extra helm args passed from workflow if os.path.exists(EXTRA_HELM_ARGS_FILE): @@ -62,10 +66,6 @@ def get_cri_args(): # Get CRI args for Akri Helm return open(HELM_CRI_ARGS_FILE, "r").readline().rstrip() -def get_helm_chart_name(): - # Get Helm chart name (akri, akri-dev) - return open(HELM_CHART_NAME_FILE, "r").readline().rstrip() - def get_test_version(): # Get version of akri to test if os.path.exists(VERSION_FILE):