Skip to content

Integration Tests

Integration Tests #467

name: Integration Tests
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 3 * * 1-5" # run integration tests at 3 AM, monday to friday (1-5)
workflow_dispatch: # run integration tests only when triggered manually
defaults:
run:
shell: bash
jobs:
integration_test:
name: "Integration tests"
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
keptn-version: ["0.14.2", "0.15.1", "0.16.1", "0.17.0"] # https://github.com/keptn/keptn/releases
env:
GO111MODULE: "on"
ENABLE_E2E_TEST: true
BRANCH: ${{ github.head_ref || github.ref_name }}
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
GOPROXY: "https://proxy.golang.org"
GITEA_ADMIN_USERNAME: GiteaAdmin
GITEA_NAMESPACE: gitea
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Install Go
uses: actions/[email protected]
with:
go-version-file: "go.mod"
- name: Install gotestsum
shell: bash
run: go install gotest.tools/gotestsum@latest
- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env
# Download artifacts from last CI run
- name: Download artifacts
uses: dawidd6/[email protected]
id: download_artifacts_push
with:
# Download last successful artifact from a CI build
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: CI.yml
branch: ${{ env.BRANCH }}
path: ./dist
# Prepare K3s
- name: Install and start K3s
run: |
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.21.12+k3s1" INSTALL_K3S_EXEC="--no-deploy traefik" K3S_KUBECONFIG_MODE="644" sh -
- name: Wait for K3s to become ready
timeout-minutes: 1
run: |
# uncomment the line below for debugging
#set -x
k3sReady=$(kubectl get node $(hostname) -ogo-template --template="{{ range .status.conditions }} {{- if eq .type \"Ready\" }}{{ .status }} {{- end }} {{- end }}" || echo "")
while [ "$k3sReady" != "True" ]; do
echo "K3s is not ready yet, sleep awhile to let things settle"
sleep 5
k3sReady=$(kubectl get node $(hostname) -ogo-template --template="{{ range .status.conditions }} {{- if eq .type \"Ready\" }}{{ .status }} {{- end }} {{- end }}" || echo "")
done;
echo "K3s ready!!!"
- name: Generate Gitea credentials
id: gitea_credentials
run: |
password=$(date +%s | sha256sum | base64 | head -c 32)
echo "::add-mask::$password"
echo "::set-output name=GITEA_ADMIN_PASSWORD::$password"
- name: Install Gitea
id: gitea
env:
GITEA_ADMIN_PASSWORD: ${{ steps.gitea_credentials.outputs.GITEA_ADMIN_PASSWORD }}
run: |
export GITEA_ENDPOINT="http://gitea-http.${GITEA_NAMESPACE}:3000"
helm repo add gitea-charts https://dl.gitea.io/charts/
helm repo update
helm install -n ${GITEA_NAMESPACE} gitea gitea-charts/gitea \
--create-namespace \
--set memcached.enabled=false \
--set postgresql.enabled=false \
--set gitea.config.database.DB_TYPE=sqlite3 \
--set gitea.admin.username=${GITEA_ADMIN_USERNAME} \
--set gitea.admin.password=${GITEA_ADMIN_PASSWORD} \
--set gitea.config.server.OFFLINE_MODE=true \
--set gitea.config.server.ROOT_URL=${GITEA_ENDPOINT}/ \
--wait
# Export Gitea connection details
echo "::set-output name=GITEA_ENDPOINT::${GITEA_ENDPOINT}"
- name: Install gitea provisioner-service
env:
GITEA_ADMIN_PASSWORD: ${{ steps.gitea_credentials.outputs.GITEA_ADMIN_PASSWORD }}
GITEA_ENDPOINT: ${{ steps.gitea.outputs.GITEA_ENDPOINT }}
run: |
helm install keptn-gitea-provisioner-service https://github.com/keptn-sandbox/keptn-gitea-provisioner-service/releases/download/0.1.0/keptn-gitea-provisioner-service-0.1.0.tgz \
--set gitea.endpoint=${GITEA_ENDPOINT} \
--set gitea.admin.create=true \
--set gitea.admin.username=${GITEA_ADMIN_USERNAME} \
--set gitea.admin.password=${GITEA_ADMIN_PASSWORD} \
--wait
- name: Install Keptn
id: install_keptn
uses: keptn-sandbox/[email protected]
timeout-minutes: 5
with:
KEPTN_VERSION: ${{ matrix.keptn-version }}
HELM_VALUES: |
# Keptn 0.17 and newer
apiGatewayNginx:
type: LoadBalancer
features:
automaticProvisioning:
serviceURL: http://keptn-gitea-provisioner-service.default
# Keptn 0.16 compatibility
control-plane:
apiGatewayNginx:
type: LoadBalancer
features:
automaticProvisioningURL: http://keptn-gitea-provisioner-service.default
KUBECONFIG: ${{ env.KUBECONFIG }}
- name: Test connection to keptn
run: |
curl -X GET "${{ steps.install_keptn.outputs.KEPTN_API_URL }}/v1/metadata" -H "accept: application/json" -H "x-token: ${{ steps.install_keptn.outputs.KEPTN_API_TOKEN }}"
# Install service from downloaded helm chart artifact
- name: Install service
run: |
helm upgrade --install --create-namespace -n keptn ${{ env.IMAGE }} \
./dist/helm-charts/*.tgz \
--wait
# If we failed any previous step we might have a problem and not reporting anything for the version
- name: Create pipeline failure report
if: failure()
run: |
echo "Failed to run integration tests!"
echo '{"Test": "TestGitHub Pipeline", "Action": "fail"}' >> $TEST_REPORT_FILENAME
- name: Run integration tests
env:
KEPTN_ENDPOINT: ${{ steps.install_keptn.outputs.KEPTN_API_URL }}
KEPTN_API_TOKEN: ${{ steps.install_keptn.outputs.KEPTN_API_TOKEN }}
shell: bash
run: gotestsum ./test/e2e/...
- name: Dump k8s debug info
if: always()
run: |
mkdir k8s_debug
kubectl describe nodes > k8s_debug/k8s_describe_nodes.txt
kubectl cluster-info dump > k8s_debug/k8s_cluster_info_dump.txt
kubectl get all -n keptn -o json > k8s_debug/k8s_keptn_objects.json
kubectl get events -n keptn --sort-by='.metadata.creationTimestamp' -A > k8s_debug/keptn_events.txt
kubectl logs -n keptn -l app.kubernetes.io/instance=keptn --prefix=true --previous=false --all-containers > k8s_debug/k8s_keptn_logs.txt || true
kubectl logs -n keptn -l app.kubernetes.io/instance=keptn-service-template-go --prefix=true --previous=false --all-containers > k8s_debug/service_template_logs.txt || true
kubectl logs -n keptn -l app.kubernetes.io/instance=keptn-service-template-go --prefix=true --previous=true --all-containers > k8s_debug/service_template_logs_previous.txt || true
kubectl describe pod -n keptn -l app.kubernetes.io/instance=keptn-service-template-go > k8s_debug/keptn_service_template_describe.txt || true
kubectl logs deployment/keptn-service-template-go -n keptn > k8s_debug/keptn_service_template_deployment_logs.txt || true
kubectl logs deployment/keptn-gitea-provisioner-service --prefix=true --previous=false --all-containers > k8s_debug/k8s_gitea_provisioner_logs.txt || true
kubectl get statefulsets,configmaps,pods,networkpolicy,serviceaccounts,role,rolebindings,events,services -n ${GITEA_NAMESPACE} -o json > k8s_debug/k8s_objects_gitea.json
kubectl logs statefulsets/gitea --prefix=true --previous=false --all-containers -n ${GITEA_NAMESPACE} > k8s_debug/k8s_logs_gitea.txt || true
# Upload the k8s debug archive, so we can use it for investigating
- name: Upload k8s debug archive
if: always()
uses: actions/upload-artifact@v2
with:
name: k8s-debug-archive-${{matrix.keptn-version}}
path: k8s_debug/