Skip to content

Commit

Permalink
wip: rework integration test step
Browse files Browse the repository at this point in the history
Consolidated integration tests into a single action, as well as some parts of the self-hosted notary setup. Also updated Kubernetes test versions to the 3 latest and 3 older versions.
  • Loading branch information
phbelitz committed Nov 25, 2024
1 parent e144fc0 commit 95ccb2f
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 307 deletions.
19 changes: 0 additions & 19 deletions .github/actions/alerting-endpoint/action.yml

This file was deleted.

121 changes: 121 additions & 0 deletions .github/actions/integration-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Integration test
description: |
Run integration tests on a k3s cluster.
inputs:
registry:
description: "Docker registry to pull the image from"
required: true
username:
description: "Username for the Docker registry"
required: true
image:
description: "Image to pull from the registry"
required: true
tag:
description: "Tag of the image to pull"
required: true
k8s-version:
description: "Kubernetes version to install"
required: true
test:
description: "Test to run"
required: true

runs:
using: composite
steps:
- name: Install required packages
run: |
sudo snap install yq
sudo apt update
sudo apt install bash -y
shell: bash
- name: Setup k3s ${{ inputs.k8s-version }}
run: |
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL="${{ inputs.k8s-version }}" sh -s -
shell: bash
# By providing a kubeconfig owned by the current user with 600 permissions,
# kubectl becomes usable without sudo, and helm won't emit warnings about
# bloated access to group/world.
- name: Prepare a kubeconfig in ~/.kube/config
run: |
mkdir -p ~/.kube
sudo cat /etc/rancher/k3s/k3s.yaml > "$HOME/.kube/config"
chmod 600 "$HOME/.kube/config"
echo "KUBECONFIG=$HOME/.kube/config" >> $GITHUB_ENV
shell: bash
- name: Setup Helm
run: |
curl -sf https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
shell: bash
- name: Wait for coredns, metrics server, traefik
run: |
# Wait for a few seconds to allow deployments spin up
sleep 10
kubectl rollout status --watch --timeout 300s deployment/coredns -n kube-system
kubectl rollout status --watch --timeout 300s deployment/metrics-server -n kube-system
kubectl wait --for=condition=complete --timeout=300s job/helm-install-traefik-crd -n kube-system || true
kubectl wait --for=condition=complete --timeout=300s job/helm-install-traefik -n kube-system || true
kubectl rollout status --watch --timeout 300s deployment/traefik -n kube-system
shell: bash
- name: Get IP
id: get_ip
run: |
if [ "${{ inputs.test }}" == "alerting" ]; then
CONTAINER=$(docker container ls --no-trunc --format "{{json . }}" | jq ' . | select(.Image|match("alerting-endpoint"))')
CONTAINER_ID=$(echo ${CONTAINER} | jq -r .ID)
CONTAINER_NETWORK=$(echo ${CONTAINER} | jq -r .Networks)
SEARCH_PATH=.[0].NetworkSettings.Networks."${CONTAINER_NETWORK}".IPAddress
IP=$(docker container inspect ${CONTAINER_ID} | jq -r ${SEARCH_PATH})
else
IP=""
fi
echo IP=${IP} >> ${GITHUB_OUTPUT}
shell: bash
- name: Run test
run: |
bash test/integration/main.sh "${{ inputs.test }}"
env:
ALERTING_ENDPOINT_IP: ${{ steps.get_ip.outputs.ip }}
shell: bash
- name: Display Connaisseur configuration
if: always()
run: |
out=$(yq e '... comments=""' charts/connaisseur/values.yaml)
echo "::group::values.yaml"
echo "${out}" | yq
echo "::endgroup::"
echo "<details><summary>values.yaml</summary>" >> ${GITHUB_STEP_SUMMARY}
echo "<pre lang=\"yaml\"><code>${out}</code></pre>" >> ${GITHUB_STEP_SUMMARY}
echo "</details>" >> ${GITHUB_STEP_SUMMARY}
shell: bash
- name: Display k8s state if integration test failed
if: failure()
run: |
deploy_out=$(kubectl describe deployments.apps -n connaisseur -lapp.kubernetes.io/name=connaisseur)
if [ -n "${deploy_out}" ]; then
echo "${deploy_out}"
echo "<details><summary>connaisseur deployment</summary>" >> ${GITHUB_STEP_SUMMARY}
echo "<pre lang=\"yaml\"><code>${deploy_out}</code></pre>" >> ${GITHUB_STEP_SUMMARY}
echo "</details>" >> ${GITHUB_STEP_SUMMARY}
fi
pod_out=$(kubectl describe pods -n connaisseur -lapp.kubernetes.io/name=connaisseur)
if [ -n "${pod_out}" ]; then
echo "${pod_out}"
echo "<details><summary>connaisseur pods</summary>" >> ${GITHUB_STEP_SUMMARY}
echo "<pre lang=\"yaml\"><code>${pod_out}</code></pre>" >> ${GITHUB_STEP_SUMMARY}
echo "</details>" >> ${GITHUB_STEP_SUMMARY}
fi
shell: bash
- name: Display logs if integration test failed
if: failure()
run: |
logs_out=$(kubectl logs -n connaisseur -lapp.kubernetes.io/name=connaisseur --prefix=true --tail=-1)
if [ -n "${logs_out}" ]; then
echo "${logs_out}"
echo "<details><summary>connaisseur logs</summary>" >> ${GITHUB_STEP_SUMMARY}
echo "<pre lang=\"bash\"><code>${logs_out}</code></pre>" >> ${GITHUB_STEP_SUMMARY}
echo "</details>" >> ${GITHUB_STEP_SUMMARY}
fi
shell: bash
73 changes: 0 additions & 73 deletions .github/actions/k3s-cluster/action.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/actions/k8s-version-config/action.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/actions/notary-server-ip/action.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/actions/notary-service/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: notary-service
description: 'Sets up a notary service (signer or server)'
inputs:
service:
description: "Which kind of service is to be started (signer or server)"
required: true
add_host:
description: "What additional hosts to add to the service"
required: false
outputs:
ip:
description: "IP address of the notary service"
value: ${{ steps.get_service_ip.outputs.service_ip }}
runs:
using: composite
steps:
- name: Setup variables
id: setup_vars
run: |
case ${{ inputs.service }} in
"server")
PORT_MAP=4443:4443
ADD_HOST="--add-host ${{ inputs.add_host }}"
ADD_ARGS="-logf=json"
;;
"signer")
PORT_MAP=7899:7899
ADD_HOST=""
ADD_ARGS=""
;;
*)
echo "invalid service"
exit 1
;;
esac
shell: bash
- name: Setup service
run: |
docker run -d -p ${PORT} ${ADD_HOST} -v ./test/integration/self-hosted-notary/notary-service-container/${{ inputs.service }}:/etc/docker/notary-${{ inputs.service }} notary:${{ inputs.service }} -config=/etc/docker/notary-${{ inputs.service }}/config.json ${ADD_ARGS}
shell: bash
- name: Get IP
id: get_service_ip
run: |
NOTARY_CONTAINER=$(docker container ls --no-trunc --format "{{json . }}" | jq ' . | select(.Image|match("notary:${{ inputs.service }}"))')
NOTARY_CONTAINER_ID=$(echo ${NOTARY_CONTAINER} | jq -r .ID)
NOTARY_CONTAINER_NETWORK=$(echo ${NOTARY_CONTAINER} | jq -r .Networks)
NOTARY_SEARCH_PATH=.[0].NetworkSettings.Networks."${NOTARY_CONTAINER_NETWORK}".IPAddress
NOTARY_IP=$(docker container inspect ${NOTARY_CONTAINER_ID} | jq -r ${NOTARY_SEARCH_PATH})
echo service_ip=${NOTARY_IP} >> ${GITHUB_OUTPUT}
shell: bash
19 changes: 0 additions & 19 deletions .github/actions/notary-signer-ip/action.yaml

This file was deleted.

Loading

0 comments on commit 95ccb2f

Please sign in to comment.