Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion roles/github_runner_cluster/tasks/node_readiness.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
# Reads, from the cluster itself, every node's Ready condition (github_runner_cluster_node_readiness, "<node>=<True|False|Unknown>" a line, the status empty for a node with no Ready condition yet) and the nodes memory-pressure regrading has stepped down (github_runner_cluster_nodes_stepped_down). Run when the answer is needed, never cached, since the rescue of tasks/wait_for_nodes.yml reads them after a wait that took a while.
# Reads, from the cluster itself, every node's Ready condition (github_runner_cluster_node_readiness, "<node>=<True|False|Unknown>" a line, the status empty for a node with no Ready condition yet) and the nodes memory-pressure regrading has stepped down (github_runner_cluster_nodes_stepped_down). Run when the answer is needed, never cached, since the rescue of tasks/wait_for_nodes.yml reads them after a wait that took a while. Both reads change nothing, so they run under --check too: the wait that follows depends on their output.

- name: Read which nodes are Ready
ansible.builtin.command:
argv: [kubectl, get, nodes, -o, 'jsonpath={range .items[*]}{.metadata.name}{"="}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}']
environment:
KUBECONFIG: "{{ github_runner_cluster_kubeconfig_path }}"
changed_when: false
check_mode: false
register: github_runner_cluster_node_readiness

- name: Read which nodes memory-pressure regrading has stepped down
Expand All @@ -16,4 +17,5 @@
environment:
KUBECONFIG: "{{ github_runner_cluster_kubeconfig_path }}"
changed_when: false
check_mode: false
register: github_runner_cluster_nodes_stepped_down
13 changes: 11 additions & 2 deletions tests/unit/test_cluster_wait_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def setUp(self) -> None:
modules.mkdir(parents=True)
(modules / "k8s.py").write_text(K8S_MODULE)

def wait(self) -> subprocess.CompletedProcess[str]:
def wait(self, check: bool = False) -> subprocess.CompletedProcess[str]:
hosts, group_vars = self.hosts(("node1", "node2", "node3"), ("agent1",))
return self.run_tasks("wait_for_nodes", hosts, group_vars, limit="node1")
return self.run_tasks("wait_for_nodes", hosts, group_vars, check=check, limit="node1")

def kubectl_calls(self) -> list[str]:
return self.read_log("kubectl.log")
Expand Down Expand Up @@ -173,6 +173,15 @@ def test_a_cluster_holding_no_node_of_the_inventory_fails_rather_than_passing_an
self.assertEqual(self.waits(), [])


class CheckModeTest(WaitTestCase):
def test_a_check_run_reads_the_nodes_and_leaves_the_wait_itself_unrun(self) -> None:
self.nodes(node1="True", node2="True", node3="True", agent1="True")
result = self.wait(check=True)
self.assertEqual(result.returncode, 0, result.stdout)
self.assertEqual(self.waits(), [])
self.assertEqual(len([call for call in self.kubectl_calls() if call.startswith("get nodes")]), 2)


class WiringTest(unittest.TestCase):
def tasks(self, name: str) -> list[dict[str, Any]]:
loaded: list[dict[str, Any]] = yaml.safe_load((ROLE / "tasks" / name).read_text())
Expand Down
Loading