Skip to content

Tests Action

Tests Action #9

Workflow file for this run

name: Tests
on:
workflow_dispatch:
inputs:
cloud:
description: 'Choose Cloud Provider'
required: true
type: choice
default: Azure
options:
- Azure
- AWS
- GCP
action:
description: 'Action'
required: false
default: 'apply'
type: choice
options:
- apply
- destroy
tests_timestamp_enabled:
description: 'Enabled Timestamp Test'
required: false
default: true
type: boolean
tests_httpbin_enabled:
description: 'Enabled Httpbin Test'
required: false
default: false
type: boolean
tests_duration:
description: 'Duration of Tests in Minutes'
required: false
default: 15
type: number
tests_virtual_users:
description: 'Virtual Users for Test'
required: false
default: 50
type: number
custom_tests_descriptor:
description: 'Custom Tests Descriptor'
required: true
type: string
default: 'tests/main.tfvars.example'
env:
provider: ${{ inputs.cloud == 'Azure' && 'aks' || (inputs.cloud == 'AWS' && 'eks' || 'gke') }}
concurrency:
group: ${{ inputs.cloud }}
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Configure AKS credentials
if: ${{ inputs.cloud == 'Azure' }}
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Configure AWS credentials
if: ${{ inputs.cloud == 'AWS' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_CLUSTER_LOCATION }}
- name: Authenticate into gcloud
if: ${{ inputs.cloud == 'GCP' }}
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Install gcloud CLI
if: ${{ inputs.cloud == 'GCP' }}
uses: google-github-actions/[email protected]
- name: Install gcloud k8s auth component
if: ${{ inputs.cloud == 'GCP' }}
run: gcloud components install gke-gcloud-auth-plugin
- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Connect to AKS cluster
if: ${{ inputs.cloud == 'Azure' }}
run: |
az aks get-credentials \
--resource-group "pt-${{ vars.AZURE_CLUSTER_MACHINE_TYPE }}" \
--name "pt-${{ vars.AZURE_CLUSTER_MACHINE_TYPE }}"
kubectl config rename-context $(kubectl config current-context) performance-testing
- name: Connect to EKS cluster
if: ${{ inputs.cloud == 'AWS' }}
run: |
aws eks --region "${{ vars.AWS_CLUSTER_LOCATION }}" update-kubeconfig --name "pt-${{ vars.AWS_CLUSTER_MACHINE_TYPE }}"
kubectl config rename-context $(kubectl config current-context) performance-testing
- name: Connect to GKE cluster
if: ${{ inputs.cloud == 'GCP' }}
run: |
gcloud container clusters get-credentials "pt-${{ vars.GCP_CLUSTER_MACHINE_TYPE }}" \
--region "${{ vars.GCP_CLUSTER_LOCATION }}" \
--project "${{ secrets.GCP_PROJECT }}"
kubectl config rename-context $(kubectl config current-context) performance-testing
- name: Create Terraform Cloud descriptor
run: cp .github/${{ env.provider }}/tests.tf tests/terraform.cloud.tf
- name: Copy Terraform descriptor
run: cp ${{ inputs.custom_tests_descriptor }} tests/main.tfvars
- name: Run Terraform action on tests
run: |
cd tests
terraform init
terraform ${{ inputs.action }} \
--var-file=main.tfvars \
--var="kubernetes_config_context=performance-testing" \
--var="tests_timestamp_enabled=${{ inputs.tests_timestamp_enabled }}" \
--var="tests_httpbin_enabled=${{ inputs.tests_httpbin_enabled }}" \
--var="tests_duration=${{ inputs.tests_duration }}" \
--var="tests_virtual_users=${{ inputs.tests_virtual_users }}" \
--auto-approve
- name: Access to Grafana Dashboard
if: ${{ inputs.action == 'apply' }}
run: |
echo "###################################################################
echo "#
echo "# http://$(kubectl get svc -n dependencies grafana -ojsonpath='{.status.loadBalancer.ingress[0].ip}')"
echo "# Username: admin"
echo "# Password: topsecretpassword"
echo "#
echo "###################################################################
- name: Grafana timestamp test snapshot
if: ${{ inputs.tests_timestamp_enabled == true }}
run: |
kubectl logs -n dependencies $(kubectl get pods -n dependencies --selector=job-name=snapshot-job-timestamp -o jsonpath='{.items[-1].metadata.name}') --tail=1
- name: Grafana httpbin test snapshot
if: ${{ inputs.tests_httpbin_enabled == true }}
run: |
kubectl logs -n dependencies $(kubectl get pods -n dependencies --selector=job-name=snapshot-job-httpbin -o jsonpath='{.items[-1].metadata.name}') --tail=1