Skip to content

[GitHub Actions] Replace k3s with k3d #722

[GitHub Actions] Replace k3s with k3d

[GitHub Actions] Replace k3s with k3d #722

Workflow file for this run

name: Install applications on Kubernetes
on:
pull_request:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
default: false
jobs:
install:
runs-on: self-hosted
steps:
- name: Cleanup
continue-on-error: true
run: |
ls -la ./
rm -rf ./* || true
rm -rf ./.??* || true
ls -la ./
- uses: actions/checkout@v3
- uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- run: pip install -r test/features/requirements.txt
- name: Install dependencies
env:
HELM_VERSION: "v3.16.3"
HELM_DIFF_VERSION: "3.9.12"
HELMFILE_VERSION: "v0.169.1"
YQ_VERSION: "v4.44.3"
run: |
./.github/ci_config/bin/install-dependencies
- name: Prepare the environment (add secrets and enable installation of all components)
run: |
DNAME='CN=CI,O=TheHyve,L=Utrecht,C=NL' ./bin/init
helmfile_mods='\ \ \ \ \ \ - ../.github/ci_config/ci-config.yaml\n'
helmfile_mods+='\ \ \ \ \ \ - ../.github/ci_config/secrets.yaml.gotmpl'
sed -i "/secrets.yaml/a $helmfile_mods" environments.yaml
sed -i '/_install: /s/false/true/' etc/production.yaml
# Deploy a minimal deployment accessible on 'localhost:80' with monitoring enabled
sed -i '/enable_logging_monitoring: /s/false/true/' etc/production.yaml
sed -i '/dev_deployment: /s/false/true/' etc/production.yaml
sed -i '/e2e_test: /s/false/true/' etc/production.yaml
- name: Ensure k3d cache directory exists
run: |
mkdir -p $HOME/k3d-containerd
test-helmfile-template:
needs: install
runs-on: self-hosted
steps:
- name: Test helmfile template
env:
FIREBASE_ADMINSDK_JSON: ${{ secrets.FIREBASE_ADMINSDK_JSON }}
run: |
helmfile template > /tmp/helmfile.yaml
delete-old-clusters:
runs-on: self-hosted
needs: test-helmfile-template
steps:
- name: Delete old clusters
run: |
k3d cluster delete --all || true
matrix-prep:
runs-on: self-hosted
needs: delete-old-clusters
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: nelonoel/[email protected]
- id: set-matrix
uses: JoshuaTheMiller/conditional-build-matrix@main
with:
# inputFile: '.github/workflows/matrix_includes.json' # Default input file path
filter: '[?runOnBranch==`${{ env.BRANCH_NAME }}` || runOnBranch==`always`]'
addInclude: true
test-k8s-versions:
needs: matrix-prep
runs-on: self-hosted
strategy:
matrix: ${{ fromJson(needs.matrix-prep.outputs.matrix) }}
steps:
- uses: nolar/setup-k3d-k3s@v1
with:
version: ${{ matrix.K3S_VERSION }}
k3d-args: --k3s-arg --disable=traefik@server:0 --k3s-arg --disable-helm-controller@server:0 --config .github/ci_config/k3d-config.yaml
# Note: k3d adds a 'k3d-' prefix to this name
k3d-name: ${{ matrix.KUBECTL_VERSION }}
# TODO would be better to do this with a command line parameter. I have been unable to get this to work.
- name: Set kubeContext
run: |
sed -i "s/kubeContext: .*/kubeContext: k3d-${{ matrix.KUBECTL_VERSION }}/" etc/production.yaml
- name: Install RADAR-Kubernetes
env:
FIREBASE_ADMINSDK_JSON: ${{ secrets.FIREBASE_ADMINSDK_JSON }}
run: |
echo "kubeconfig: $KUBECONFIG"
kubectl get pods --all-namespaces --context k3d-${{ matrix.KUBECTL_VERSION }}
helmfile sync
- name: Run end-to-end tests
run: |
cd test/features
behave -D secrets_file=$GITHUB_WORKSPACE/etc/secrets.yaml -D url=http://localhost:80 # Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Manually triggered tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
with:
limit-access-to-actor: true
- name: Slack Notification
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: ci-notifications
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_MESSAGE: 'The job has failed, go to https://github.com/RADAR-base/RADAR-Kubernetes/actions and use SSH for more information'
SLACK_TITLE: Post Title
SLACK_USERNAME: rtCamp
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
- name: Setup tmate session if jobs have failed
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 15
with:
limit-access-to-actor: true
- name: Report cluster state
if: always()
run: |
kubectl get pods --all-namespaces
# TODO We can remove the k3s uninstallation once the k3d PR is merged.
- name: Delete clusters when job was canceled
if: cancelled()
run: |
k3d cluster delete --all || true
k3s-uninstall.sh || true
check-gitignore:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check gitignore
run: |
echo "Checking whether any files that should be ignored are uploaded"
echo
if find . -not -path './.git/*' -type f | git check-ignore --stdin --no-index; then
echo
echo "Remove the above files from this branch"
exit 1
else
echo "No ignored files have been added"
fi