Setup and run load test #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Setup and run load test | |
on: | |
workflow_dispatch: | |
inputs: | |
scenario: | |
description: The desired scenario of the load test run | |
required: true | |
type: choice | |
options: | |
- scenario-user-flow | |
env: | |
K8S_NAMESPACE: k6-load-test | |
JOB_NAME: k6 | |
jobs: | |
setup-and-run-load-test: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Google auth | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: ${{ secrets.AUTOMATION_SA_KEY_JSON }} | |
- name: Get GKE creds | |
id: get_gke_creds | |
uses: 'google-github-actions/get-gke-credentials@v2' | |
with: | |
cluster_name: 'simple-autopilot-private-cluster' | |
location: 'europe-west1' | |
credentials: ${{ secrets.AUTOMATION_SA_KEY_JSON }} | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: | | |
${{ secrets.LPT_SSH_PRIVATE_KEY }} | |
- name: Setup load test | |
env: | |
BASTION_IP: ${{ secrets.SSH_BASTION_HOST_IP }} | |
API_URL: ${{ vars.KUBE_INTERNAL_API_URL }} | |
CLUSTER_NAME: ${{ vars.KUBE_CLUSTER_NAME }} | |
KUBE_FLAGS: ${{ vars.KUBE_FLAGS }} | |
CONFIG_PATH: ${{ steps.get_gke_creds.outputs.kubeconfig_path }} | |
run: | | |
ssh -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -L 6443:$API_URL -i lpt lpt@$BASTION_IP -fN | |
# use config from gke init action: | |
export KUBECONFIG=$CONFIG_PATH | |
kubectl config set-cluster $CLUSTER_NAME --server=https://127.0.0.1:6443 | |
kubectl apply -f load-test/base/namespace.yaml $KUBE_FLAGS | |
sleep 5 | |
kubectl apply -k load-test/${{ inputs.scenario }} $KUBE_FLAGS | |
- name: Run scenario and get logs | |
env: | |
BASTION_IP: ${{ secrets.SSH_BASTION_HOST_IP }} | |
API_URL: ${{ vars.KUBE_INTERNAL_API_URL }} | |
CLUSTER_NAME: ${{ vars.KUBE_CLUSTER_NAME }} | |
KUBE_FLAGS: ${{ vars.KUBE_FLAGS }} | |
CONFIG_PATH: ${{ steps.get_gke_creds.outputs.kubeconfig_path }} | |
run: | | |
export KUBECONFIG=$CONFIG_PATH | |
kubectl $KUBE_FLAGS --namespace $K8S_NAMESPACE wait --for=condition=Ready pod --selector "app.kubernetes.io/job=$JOB_NAME" --timeout=180s | |
kubectl $KUBE_FLAGS --namespace $K8S_NAMESPACE logs "job/$JOB_NAME" --follow | |
kubectl $KUBE_FLAGS --namespace $K8S_NAMESPACE wait --for=condition=complete --timeout=180s "job/$JOB_NAME" | |
- name: Cleanup | |
if: ${{ always() }} | |
env: | |
BASTION_IP: ${{ secrets.SSH_BASTION_HOST_IP }} | |
API_URL: ${{ vars.KUBE_INTERNAL_API_URL }} | |
CLUSTER_NAME: ${{ vars.KUBE_CLUSTER_NAME }} | |
KUBE_FLAGS: ${{ vars.KUBE_FLAGS }} | |
CONFIG_PATH: ${{ steps.get_gke_creds.outputs.kubeconfig_path }} | |
run: | | |
export KUBECONFIG=$CONFIG_PATH | |
kubectl delete namespace $K8S_NAMESPACE $KUBE_FLAGS |