Skip to content

Commit 35ff7b0

Browse files
fix(test): fix join_cluster wait and get_local_node_status for MicroK8s
- join_cluster: call 'microk8s status --wait-ready' after joining so the node is fully registered in the cluster before wait_until_ready is called - get_local_node_status: MicroK8s HA nodes do not get the node-role.kubernetes.io/control-plane label; check whether snap.microk8s.daemon-k8s-dqlite.service is active instead - Restore continue-on-error on stop/start step until canonical/microk8s#5546 merges Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 38fd785 commit 35ff7b0

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

.github/workflows/microk8s-integration.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ jobs:
9191
sudo -E python -m pytest -rA -s tests/test-simple.py -k "not test_microk8s_stop_start"
9292
9393
- name: Run stop/start lifecycle test
94+
# canonical/microk8s#5546 fixes the flakiness; continue-on-error until it merges
95+
continue-on-error: true
9496
run: |
9597
cd microk8s
9698
sudo -E python -m pytest -rA -s tests/test-simple.py -k "test_microk8s_stop_start"

test/performance/tests/microk8s_util.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def get_join_token(primary: harness.Instance, _joining_node: harness.Instance) -
210210
def join_cluster(instance: harness.Instance, join_token: str):
211211
"""Join an existing MicroK8s cluster. Nodes join as control-plane by default."""
212212
instance.exec(["microk8s", "join", join_token])
213+
# Wait for this node's services to be fully up before returning so that
214+
# wait_until_ready() can immediately query kubectl get nodes.
215+
instance.exec(["microk8s", "status", "--wait-ready", "--timeout=300"])
213216

214217

215218
def wait_until_ready(
@@ -245,17 +248,17 @@ def ready_nodes(control_node: harness.Instance) -> List[Any]:
245248

246249

247250
def get_local_node_status(instance: harness.Instance) -> str:
248-
"""Return a string describing the node role (mirrors util.get_local_node_status).
251+
"""Return a string describing the node role.
249252
250-
All nodes joined via ``microk8s join`` without ``--worker`` are control-plane
251-
members, so this always returns a string containing "control-plane".
253+
In MicroK8s HA, nodes that joined without --worker run the dqlite daemon
254+
and are control-plane members. Check the service state rather than
255+
Kubernetes labels (which MicroK8s does not set for control-plane nodes).
252256
"""
253-
node_name = util.hostname(instance)
254257
result = instance.exec(
255-
["microk8s", "kubectl", "get", "node", node_name, "--show-labels"],
258+
["systemctl", "is-active", "snap.microk8s.daemon-k8s-dqlite.service"],
256259
capture_output=True,
260+
check=False,
257261
)
258-
labels = result.stdout.decode()
259-
if "node-role.kubernetes.io/control-plane" in labels:
262+
if result.stdout.decode().strip() == "active":
260263
return "control-plane"
261264
return "worker"

0 commit comments

Comments
 (0)