diff --git a/roles/github_runner_cluster/tasks/node_readiness.yml b/roles/github_runner_cluster/tasks/node_readiness.yml index 3931293c..8a2f30f2 100644 --- a/roles/github_runner_cluster/tasks/node_readiness.yml +++ b/roles/github_runner_cluster/tasks/node_readiness.yml @@ -1,5 +1,5 @@ --- -# Reads, from the cluster itself, every node's Ready condition (github_runner_cluster_node_readiness, "=" 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, "=" 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: @@ -7,6 +7,7 @@ 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 @@ -16,4 +17,5 @@ environment: KUBECONFIG: "{{ github_runner_cluster_kubeconfig_path }}" changed_when: false + check_mode: false register: github_runner_cluster_nodes_stepped_down diff --git a/tests/unit/test_cluster_wait_nodes.py b/tests/unit/test_cluster_wait_nodes.py index 041867ad..03f43a87 100644 --- a/tests/unit/test_cluster_wait_nodes.py +++ b/tests/unit/test_cluster_wait_nodes.py @@ -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") @@ -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())