mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2026-10-23 03:22:03 +02:00
* feat: allow the server and agent plays to roll one node at a time The server and agent roles restart their k3s service on every run, and the plays run against the whole group at once. On a cluster with three or more servers that restarts every etcd member together, which costs the cluster its quorum and its API server. k3s_server_serial and k3s_agent_serial set the serial of the two plays. Both default to 100%, the whole group in one batch, so a run that does not set them behaves as before. The HA integration test now rolls the servers with the variable instead of --forks=1, which serialises the role rather than the individual tasks. Signed-off-by: Kristofer <kristofer@atlascloud.is> * feat: hold each node until it serves again during a rolling run Setting k3s_server_serial to 1 rolls the servers one at a time, but the role returns as soon as the service manager reports k3s started, which is before the node serves again. On an embedded etcd cluster the next restart can then land while the previous member is still a learner, and a learner does not count towards the quorum. k3s_wait_ready holds each node at the end of its role until the API server reports it Ready. k3s_server_wait_etcd_voters holds each server until every server the run has already started carries EtcdIsVoter=True. Both default to false, are independent of each other, are skipped in check mode, and the upgrade role honors them as well. The new voter gate and the existing join barrier both wait only for the servers the run has reached, taken from the play's host list up to the end of the current batch: a whole-group count never completes on a fresh HA install rolled one node at a time. They match nodes by name rather than by count, so a re-run against a cluster that already holds more nodes also completes, and the comparison ignores case. k3s_node_name carries the name K3s registers the node under. It defaults to the lower-cased hostname and has to be set when a node is installed with --node-name. The HA integration job installs through tests/serial.yml, which imports site.yml with the serial variables in its vars, and the external job gives its server a node name that differs from its host name. Signed-off-by: Kristofer <kristofer@atlascloud.is> * docs: say why the node name is recorded as a fact A role default is not reachable through hostvars, so the barriers read a fact that each host sets for itself. Signed-off-by: Kristofer <kristofer@atlascloud.is> * docs: describe what upgrade.yml does rather than that it is unchanged Signed-off-by: Kristofer <kristofer@atlascloud.is> * Tolerate a host that left the play when listing started servers Extracting a key from hostvars raises when the key is missing. A host that went unreachable earlier in the play never recorded its node name, so the list comprehension that both barriers read failed the whole batch rather than the one host that dropped out. Select the hosts that carry the fact instead. Signed-off-by: Kristofer <kristofer@atlascloud.is> * Count the servers started so far in the server join barrier The barrier that confirms the servers joined matched the node names the run had recorded against the names the API server returned. Counting is enough for what the barrier is for, and it keeps the check independent of the node name: at the default serial it waits for the whole server group, which is what it waited for before, and under a serialised run it waits for the servers the run has started. Name matching stays in the two opt-in gates, which need it. Signed-off-by: Kristofer <kristofer@atlascloud.is> * Take the node name default from the OS nodename The kubelet registers a node under the name the operating system reports, which on a host with a search domain is the fully qualified name, not the short host name the default used. The server and agent plays gather no facts of their own, so the default also falls back to the inventory host name rather than requiring a gathered fact. Signed-off-by: Kristofer <kristofer@atlascloud.is> * Show the node name as a per-host setting in the sample inventory k3s_node_name names one node, so the sample carries it under a host entry rather than in the group vars every node reads. The sample also says where the serial variables are set, since a reader who meets them in the group vars block would reasonably try to set them there. Signed-off-by: Kristofer <kristofer@atlascloud.is> * State what the etcd voter gate checks and how to read a gate timeout The voter gate was described as the thing that keeps a rolling run from taking the quorum down, which overstates it: it checks one condition on the servers the run has started, and a quorum lost some other way is outside what it sees. Say that, say which check counts nodes and which match by name, and give the reader the two failure modes worth knowing before a gate times out on them. Signed-off-by: Kristofer <kristofer@atlascloud.is> * Install the HA test cluster at the default serial and give it an agent The HA job installed through tests/serial.yml, which left no coverage of a fresh multi-server install at the default serial, the setting a cluster that passes no serial variable actually runs. Put that back as the install step and move tests/serial.yml to the version-bump re-run, where rolling one node at a time is what the step is testing. The inventory had no agent, so the agent play never batched and the agent readiness gate never ran. Adding one covers both, and the job's container loops and assertions follow it. Signed-off-by: Kristofer <kristofer@atlascloud.is> * feat: roll the servers one at a time with an etcd voter wait k3s_server_serial sets the serial of the server play. It defaults to 100%, the whole group in one batch, so a run that does not set it behaves as before. Set it to 1 to restart the servers one at a time, and pass it through extra vars or import_playbook vars, since serial is templated before any inventory variable is bound. The join check waits for the servers started so far rather than the whole group, so a fresh HA install rolled one server at a time completes. A multi-server cluster on embedded etcd waits until every server reports EtcdIsVoter=True before the next batch starts. The agent play is unchanged. The HA integration job re-runs site.yml with k3s_server_serial=1 in place of --forks=1. Signed-off-by: Kristofer <kristofer@atlascloud.is> * docs: clarify the serial server rollout in the README Signed-off-by: Kristofer <kristofer@atlascloud.is> * docs: describe the etcd voter wait precisely Signed-off-by: Kristofer <kristofer@atlascloud.is> --------- Signed-off-by: Kristofer <kristofer@atlascloud.is>
632 lines
24 KiB
YAML
632 lines
24 KiB
YAML
---
|
|
name: Integration Test
|
|
|
|
on:
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
service_mgr: [systemd, openrc]
|
|
inventory: [basic, notoken]
|
|
exclude:
|
|
- service_mgr: openrc
|
|
inventory: notoken
|
|
env:
|
|
STARTING_K3S_VERSION: v1.34.3+k3s1
|
|
UPGRADE_K3S_VERSION: v1.35.1+k3s1
|
|
SITE_UPGRADE_K3S_VERSION: v1.35.6+k3s1
|
|
# K3s requires privileged containers to run inside Docker and access to cgrougs.
|
|
steps:
|
|
- name: Remove Unnecessary Tools
|
|
working-directory: /
|
|
run: |
|
|
sudo rm -rf \
|
|
/home/linuxbrew \
|
|
/home/packer \
|
|
/opt/az \
|
|
/opt/microsoft \
|
|
/usr/lib/firefox \
|
|
/usr/lib/google-cloud-sdk \
|
|
/usr/local/julia* \
|
|
/usr/local/share/boost \
|
|
/usr/local/share/chromium \
|
|
/usr/local/share/powershell \
|
|
/usr/share/az* \
|
|
/usr/share/dotnet \
|
|
/usr/share/miniconda \
|
|
/usr/share/swift
|
|
df -khl
|
|
- name: Set container OS based on service manager
|
|
id: set-container
|
|
run: |
|
|
if [ "${{ matrix.service_mgr }}" == "systemd" ]; then
|
|
echo "container_os=rancher/systemd-node:v0.0.8" >> $GITHUB_ENV
|
|
echo "container_cmd=/usr/lib/systemd/systemd --unit=noop.target --show-status=true" >> $GITHUB_ENV
|
|
echo "service_mgr=systemd" >> $GITHUB_ENV
|
|
else
|
|
echo "container_os=jrei/openrc-alpine" >> $GITHUB_ENV
|
|
echo "service_mgr=openrc" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Checkout codebase
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
|
|
|
|
- name: Set up Python 3.13.
|
|
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
with:
|
|
python-version: '3.13.x'
|
|
|
|
- name: Install Ansible and dependencies
|
|
run: |
|
|
pip install ansible netaddr
|
|
ansible-galaxy collection install -r collections/requirements.yml
|
|
|
|
- name: Verify Inventory
|
|
run: ansible-inventory -i tests/${{ matrix.inventory }}.yml --list
|
|
|
|
- name: Create Docker Network
|
|
run: docker network create k3s-ansible
|
|
|
|
- name: Start Docker containers
|
|
run: |
|
|
# Start the Server node
|
|
docker run -d --name server-node \
|
|
--hostname server-node \
|
|
--privileged \
|
|
-v /sys/fs/bpf:/sys/fs/bpf \
|
|
--memory 2048m \
|
|
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--volume=/lib/modules:/lib/modules:ro \
|
|
--cgroupns=host \
|
|
--network=k3s-ansible \
|
|
${{ env.container_os }} ${{ env.container_cmd }}
|
|
|
|
# Start the Agent node
|
|
docker run -d --name agent-node \
|
|
--hostname agent-node \
|
|
--privileged \
|
|
-v /sys/fs/bpf:/sys/fs/bpf \
|
|
--memory 2048m \
|
|
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--volume=/lib/modules:/lib/modules:ro \
|
|
--cgroupns=host \
|
|
--network=k3s-ansible \
|
|
${{ env.container_os }} ${{ env.container_cmd }}
|
|
|
|
- name: Install node dependencies (systemd)
|
|
if: matrix.service_mgr == 'systemd'
|
|
run: |
|
|
docker exec server-node zypper install -y python3-rpm
|
|
docker exec agent-node zypper install -y python3-rpm
|
|
|
|
- name: Install node dependencies (openrc)
|
|
if: matrix.service_mgr == 'openrc'
|
|
run: |
|
|
docker exec server-node apk add curl python3
|
|
docker exec agent-node apk add curl python3
|
|
|
|
- name: Replace k3s_version in inventory
|
|
run: |
|
|
sed -i "s/k3s_version: .*/k3s_version: ${STARTING_K3S_VERSION}/" tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Run Playbook
|
|
env:
|
|
ANSIBLE_FORCE_COLOR: '1'
|
|
run: ansible-playbook playbooks/site.yml -i tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Verify K3s is running on Server
|
|
run: docker exec server-node k3s kubectl get nodes | grep Ready
|
|
|
|
- name: Verify the server config file mode
|
|
if: matrix.inventory == 'basic'
|
|
run: docker exec server-node ls -l /etc/rancher/k3s/config.yaml | grep -q '^-rw-r-----'
|
|
|
|
- name: Verify K3s is running on Agent (systemd)
|
|
if: matrix.service_mgr == 'systemd'
|
|
run: docker exec agent-node systemctl status k3s-agent | grep running
|
|
|
|
- name: Verify K3s is running on Agent (openrc)
|
|
if: matrix.service_mgr == 'openrc'
|
|
run: docker exec agent-node rc-service k3s-agent status | grep started
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in 1 2 3 4 5 6; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 6 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Modify the k3s_version in inventory for upgrade
|
|
run: |
|
|
sed -i "s/k3s_version: .*/k3s_version: ${UPGRADE_K3S_VERSION}/" tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Run Upgrade Playbook
|
|
run: ansible-playbook playbooks/upgrade.yml -i tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Verify K3s upgraded on Server
|
|
run: docker exec server-node k3s --version | grep ${UPGRADE_K3S_VERSION}
|
|
|
|
- name: Verify K3s upgraded on Agent
|
|
run: docker exec agent-node k3s --version | grep ${UPGRADE_K3S_VERSION}
|
|
|
|
# Second upgrade, this time re-running site.yml with a bumped version: it
|
|
# must upgrade the running runtime on both the server and the agent, not
|
|
# just replace the on-disk binary.
|
|
- name: Modify the k3s_version in inventory for a site.yml upgrade
|
|
run: |
|
|
sed -i "s/k3s_version: .*/k3s_version: ${SITE_UPGRADE_K3S_VERSION}/" tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Run site Playbook to upgrade via a version bump
|
|
run: ansible-playbook playbooks/site.yml -i tests/${{ matrix.inventory }}.yml
|
|
|
|
# The install script replaces the on-disk binary regardless of a restart,
|
|
# so assert the running version the kubelet reports to the API: it only
|
|
# advances once the service was actually restarted onto the new build.
|
|
# This is what fails if the version-bump restart regresses.
|
|
- name: Verify the running K3s version upgraded on Server and Agent
|
|
run: |
|
|
for node in server-node agent-node; do
|
|
for attempt in 1 2 3 4 5 6; do
|
|
running=$(docker exec server-node k3s kubectl get node "$node" -o jsonpath='{.status.nodeInfo.kubeletVersion}' 2>&1)
|
|
echo "$node running version: $running"
|
|
if echo "$running" | grep -q "${SITE_UPGRADE_K3S_VERSION}"; then
|
|
break
|
|
fi
|
|
if [ "$attempt" -eq 6 ]; then
|
|
echo "$node did not reach ${SITE_UPGRADE_K3S_VERSION}"
|
|
exit 1
|
|
fi
|
|
sleep 10
|
|
done
|
|
done
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in {1..10}; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 10 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Add node-label to server config
|
|
run: |
|
|
printf " server_config_yaml: |\n node-label: foo=bar\n" >> tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Run site Playbook again to apply new server args
|
|
run: ansible-playbook playbooks/site.yml -i tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in {1..10}; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 10 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Verify new server args applied
|
|
run: |
|
|
for attempt in 1 2 3; do
|
|
echo "Attempt $attempt: checking node label"
|
|
output=$(docker exec server-node k3s kubectl get nodes -o jsonpath='{.items[*].metadata.labels.foo}' 2>&1)
|
|
echo "$output"
|
|
if echo "$output" | grep -q bar; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 3 ]; then
|
|
sleep 10
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Debug nodes/pods on failure
|
|
if: failure()
|
|
run: |
|
|
echo "NODE INFO"
|
|
docker exec server-node k3s kubectl get nodes -o wide
|
|
echo "POD INFO"
|
|
docker exec server-node k3s kubectl get pods -A -o wide
|
|
echo "CONFIG FILE"
|
|
docker exec server-node cat /etc/rancher/k3s/config.yaml
|
|
echo "Server ENV"
|
|
if [ $service_mgr == "systemd" ]; then
|
|
docker exec server-node cat /etc/systemd/system/k3s.service.env
|
|
elif [ $service_mgr == "openrc" ]; then
|
|
docker exec server-node cat /etc/rancher/k3s/k3s.env
|
|
fi
|
|
echo "Agent ENV"
|
|
if [ $service_mgr == "systemd" ]; then
|
|
docker exec agent-node cat /etc/systemd/system/k3s-agent.service.env
|
|
elif [ $service_mgr == "openrc" ]; then
|
|
docker exec agent-node cat /etc/rancher/k3s/k3s-agent.env
|
|
fi
|
|
echo "SERVER LOGS"
|
|
if [ $service_mgr == "systemd" ]; then
|
|
docker exec server-node journalctl -u k3s -n 50
|
|
elif [ $service_mgr == "openrc" ]; then
|
|
docker exec server-node tail -n 50 /var/log/k3s.log
|
|
fi
|
|
echo "AGENT LOGS"
|
|
if [ $service_mgr == "systemd" ]; then
|
|
docker exec agent-node journalctl -u k3s -n 50
|
|
elif [ $service_mgr == "openrc" ]; then
|
|
docker exec agent-node tail -n 50 /var/log/k3s.log
|
|
fi
|
|
|
|
|
|
- name: Remove K3s from Server and Agent
|
|
run: ansible-playbook playbooks/reset.yml -i tests/${{ matrix.inventory }}.yml
|
|
|
|
- name: Stop and remove Docker containers
|
|
run: |
|
|
docker stop server-node && docker rm -f server-node
|
|
docker stop agent-node && docker rm -f agent-node
|
|
docker network rm k3s-ansible
|
|
|
|
test-ha:
|
|
runs-on: ubuntu-latest
|
|
# K3s requires privileged containers to run inside Docker and access to cgrougs.
|
|
env:
|
|
SERVERS: server-node1 server-node2 server-node3
|
|
steps:
|
|
- name: Checkout codebase
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
|
|
|
|
- name: Set up Python 3.13.
|
|
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
with:
|
|
python-version: '3.13.x'
|
|
|
|
- name: Install Ansible and dependencies
|
|
run: |
|
|
pip install ansible netaddr
|
|
ansible-galaxy collection install -r collections/requirements.yml
|
|
|
|
- name: Verify Inventory
|
|
run: ansible-inventory -i tests/ha.yml --list
|
|
|
|
- name: Create Docker Network
|
|
run: docker network create k3s-ha-ansible
|
|
|
|
- name: Start Docker containers
|
|
run: |
|
|
for SERVER in $SERVERS; do
|
|
docker run -d --name $SERVER \
|
|
--hostname $SERVER \
|
|
--privileged \
|
|
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--volume=/lib/modules:/lib/modules:ro \
|
|
--cgroupns=host \
|
|
--network=k3s-ha-ansible \
|
|
rancher/systemd-node:v0.0.8 /usr/lib/systemd/systemd --unit=noop.target --show-status=true
|
|
done
|
|
|
|
- name: Install server dependencies
|
|
run: |
|
|
for SERVER in $SERVERS; do
|
|
docker exec $SERVER zypper install -y python3-rpm
|
|
done
|
|
|
|
- name: Run Playbook
|
|
env:
|
|
ANSIBLE_FORCE_COLOR: '1'
|
|
run: ansible-playbook playbooks/site.yml -i tests/ha.yml
|
|
|
|
- name: Verify K3s is running on servers
|
|
run: docker exec server-node1 k3s kubectl get nodes | grep Ready | wc -l | grep 3
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in 1 2 3 4 5 6; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node1 k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 6 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Modify the k3s_version in inventory for upgrade
|
|
run: |
|
|
sed -i 's/k3s_version: v1.33.4+k3s1/k3s_version: v1.34.1+k3s1/' tests/ha.yml
|
|
|
|
- name: Run Upgrade Playbook
|
|
run: ansible-playbook playbooks/upgrade.yml -i tests/ha.yml
|
|
|
|
- name: Verify K3s upgraded on all servers
|
|
run: |
|
|
sleep 5 && docker exec server-node1 k3s kubectl get nodes
|
|
for SERVER in $SERVERS; do
|
|
docker exec $SERVER k3s --version | grep v1.34.
|
|
done
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in 1 2 3 4 5 6; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node1 k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 6 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
# Re-running site.yml with a bumped version must upgrade every etcd
|
|
# server. k3s_server_serial=1 restarts them one at a time so the etcd
|
|
# quorum is never lost.
|
|
- name: Modify the k3s_version in inventory for a site.yml upgrade
|
|
run: |
|
|
sed -i 's/k3s_version: v1.34.1+k3s1/k3s_version: v1.34.3+k3s1/' tests/ha.yml
|
|
|
|
- name: Run site Playbook to upgrade the servers via a version bump
|
|
run: ansible-playbook playbooks/site.yml -i tests/ha.yml -e k3s_server_serial=1
|
|
|
|
# Assert the running (kubelet-reported) version, not the on-disk binary:
|
|
# without a rolling restart the joined servers stay on the old runtime.
|
|
- name: Verify the running K3s version upgraded on all servers via site.yml
|
|
run: |
|
|
docker exec server-node1 k3s kubectl get nodes -o wide
|
|
for SERVER in $SERVERS; do
|
|
for attempt in 1 2 3 4 5 6; do
|
|
running=$(docker exec server-node1 k3s kubectl get node "$SERVER" -o jsonpath='{.status.nodeInfo.kubeletVersion}' 2>&1)
|
|
echo "$SERVER running version: $running"
|
|
if echo "$running" | grep -q v1.34.3; then
|
|
break
|
|
fi
|
|
if [ "$attempt" -eq 6 ]; then
|
|
echo "$SERVER did not reach v1.34.3"
|
|
exit 1
|
|
fi
|
|
sleep 10
|
|
done
|
|
done
|
|
|
|
- name: Wait for all deployments to be ready after the site.yml upgrade
|
|
run: |
|
|
for attempt in {1..10}; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node1 k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 10 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Debug nodes/pods on failure
|
|
if: failure()
|
|
run: |
|
|
echo "NODE INFO"
|
|
docker exec server-node1 k3s kubectl get nodes -o wide
|
|
echo "POD INFO"
|
|
docker exec server-node1 k3s kubectl get pods -A -o wide
|
|
echo "CONFIG FILES"
|
|
for SERVER in $SERVERS; do
|
|
docker exec $SERVER cat /etc/rancher/k3s/config.yaml
|
|
done
|
|
echo "Server ENVS"
|
|
for SERVER in $SERVERS; do
|
|
docker exec $SERVER cat /etc/systemd/system/k3s.service.env
|
|
done
|
|
echo "SERVER LOGSS"
|
|
docker exec server-node1 journalctl -u k3s -n 10
|
|
|
|
- name: Remove K3s from server nodes
|
|
run: ansible-playbook playbooks/reset.yml -i tests/ha.yml
|
|
|
|
- name: Stop and remove Docker containers
|
|
run: |
|
|
for SERVER in $SERVERS; do
|
|
docker stop $SERVER && docker rm -f $SERVER
|
|
done
|
|
docker network rm k3s-ha-ansible
|
|
|
|
test-external:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout codebase
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
|
|
|
|
- name: Set up Python 3.13.
|
|
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
with:
|
|
python-version: '3.13.x'
|
|
|
|
- name: Install Ansible and dependencies
|
|
run: |
|
|
pip install ansible netaddr
|
|
ansible-galaxy collection install -r collections/requirements.yml
|
|
|
|
- name: Verify Inventory
|
|
run: ansible-inventory -i tests/external.yml --list
|
|
|
|
- name: Create Docker Network
|
|
run: docker network create k3s-ext-ansible
|
|
|
|
- name: Start Database container
|
|
run: |
|
|
docker run -d --name mysqlDB \
|
|
--network=k3s-ext-ansible \
|
|
-p 3306:3306 -e MYSQL_ROOT_PASSWORD=e2e mysql:8.4
|
|
|
|
- name: Start Server container
|
|
run: |
|
|
docker run -d --name server-node \
|
|
--privileged \
|
|
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--volume=/lib/modules:/lib/modules:ro \
|
|
--cgroupns=host \
|
|
--network=k3s-ext-ansible \
|
|
rancher/systemd-node:v0.0.8 /usr/lib/systemd/systemd --unit=noop.target --show-status=true
|
|
|
|
- name: Install server dependencies
|
|
run: docker exec server-node zypper install -y python3-rpm
|
|
|
|
- name: Run Playbook
|
|
env:
|
|
ANSIBLE_FORCE_COLOR: '1'
|
|
run: ansible-playbook playbooks/site.yml -i tests/external.yml
|
|
|
|
- name: Verify K3s is running on servers
|
|
run: docker exec server-node k3s kubectl get nodes | grep Ready | wc -l | grep 1
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in 1 2 3 4 5 6; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 6 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Stop and remove Docker containers
|
|
run: |
|
|
docker stop server-node && docker rm -f server-node
|
|
docker stop mysqlDB && docker rm -f mysqlDB
|
|
docker network rm k3s-ext-ansible
|
|
|
|
test-airgap:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout codebase
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
|
|
|
|
- name: Set up Python 3.13.
|
|
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
with:
|
|
python-version: '3.13.x'
|
|
|
|
- name: Install Ansible and dependencies
|
|
run: |
|
|
pip install ansible netaddr
|
|
ansible-galaxy collection install -r collections/requirements.yml
|
|
|
|
- name: Verify Inventory
|
|
run: ansible-inventory -i tests/airgap.yml --list
|
|
|
|
- name: Create Docker Network
|
|
run: docker network create k3s-airgp-ansible
|
|
|
|
- name: Start containers
|
|
run: |
|
|
docker run -d --name server-node \
|
|
--privileged \
|
|
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--volume=/lib/modules:/lib/modules:ro \
|
|
--cgroupns=host \
|
|
--network=k3s-airgp-ansible \
|
|
rancher/systemd-node:v0.0.8 /usr/lib/systemd/systemd --unit=noop.target --show-status=true
|
|
|
|
docker run -d --name agent-node \
|
|
--privileged \
|
|
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--volume=/lib/modules:/lib/modules:ro \
|
|
--cgroupns=host \
|
|
--network=k3s-airgp-ansible \
|
|
rancher/systemd-node:v0.0.8 /usr/lib/systemd/systemd --unit=noop.target --show-status=true
|
|
|
|
- name: Install node dependencies
|
|
run: |
|
|
docker exec server-node zypper install -y python3-rpm
|
|
docker exec agent-node zypper install -y python3-rpm
|
|
|
|
- name: Download K3s airgap artifacts
|
|
run: |
|
|
mkdir -p ./playbooks/test-airgap
|
|
wget -P ./playbooks/test-airgap https://github.com/k3s-io/k3s/releases/download/v1.33.8%2Bk3s1/k3s-airgap-images-amd64.tar.gz
|
|
wget -P ./playbooks/test-airgap https://github.com/k3s-io/k3s/releases/download/v1.33.8%2Bk3s1/k3s
|
|
|
|
- name: Run Playbook
|
|
env:
|
|
ANSIBLE_FORCE_COLOR: '1'
|
|
run: ansible-playbook playbooks/site.yml -i tests/airgap.yml
|
|
|
|
- name: Verify K3s is running on servers
|
|
run: docker exec server-node k3s kubectl get nodes | grep Ready | wc -l | grep 2
|
|
|
|
- name: Validate its the correct K3s version
|
|
run: |
|
|
docker exec server-node k3s --version | grep v1.33.8
|
|
docker exec agent-node k3s --version | grep v1.33.8
|
|
|
|
- name: Wait for all deployments to be ready
|
|
run: |
|
|
for attempt in 1 2 3 4 5 6; do
|
|
echo "Attempt $attempt: checking deployments"
|
|
output=$(docker exec server-node k3s kubectl get deployments -n kube-system -o jsonpath='{range .items[*]}{.metadata.name}={.status.readyReplicas}/{.spec.replicas}{"\n"}{end}' 2>&1)
|
|
echo "$output"
|
|
if ! echo "$output" | grep -q "<no value>" && echo "$output" | awk -F '[=/]' '{if ($2 != $3) exit 1}' ; then
|
|
exit 0
|
|
fi
|
|
if [ "$attempt" -lt 6 ]; then
|
|
sleep 15
|
|
fi
|
|
done
|
|
exit 1
|
|
|
|
- name: Debug nodes/pods on failure
|
|
if: failure()
|
|
run: |
|
|
echo "NODE INFO"
|
|
docker exec server-node k3s kubectl get nodes -o wide
|
|
echo "POD INFO"
|
|
docker exec server-node k3s kubectl get pods -A -o wide
|
|
echo "CONFIG FILE"
|
|
docker exec server-node cat /etc/rancher/k3s/config.yaml
|
|
echo "Server ENV"
|
|
docker exec server-node cat /etc/systemd/system/k3s.service.env
|
|
echo "Agent ENV"
|
|
docker exec agent-node cat /etc/systemd/system/k3s-agent.service.env
|
|
echo "SERVER LOGS"
|
|
docker exec server-node journalctl -u k3s -n 10
|
|
|
|
- name: Stop and remove Docker containers
|
|
run: |
|
|
docker stop server-node && docker rm -f server-node
|
|
docker stop agent-node && docker rm -f agent-node
|
|
docker network rm k3s-airgp-ansible
|
|
|