From 37368496c877daf316de5eb62adfabaa9710b121 Mon Sep 17 00:00:00 2001 From: leonardducareer <101617499+LeonardCareer@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:00:08 +1100 Subject: [PATCH 1/6] Make KWOK Node YAML logging opt-in --- modules/python/clients/kubernetes_client.py | 7 +++++-- modules/python/kwok/kwok.py | 9 ++++++++- .../tests/clients/test_kubernetes_client.py | 16 ++++++++++++++++ modules/python/tests/kwok/test_kwok_node.py | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/modules/python/clients/kubernetes_client.py b/modules/python/clients/kubernetes_client.py index a564c503f9..df7d67f580 100644 --- a/modules/python/clients/kubernetes_client.py +++ b/modules/python/clients/kubernetes_client.py @@ -175,12 +175,13 @@ def delete_namespace(self, namespace): return self.api.delete_namespace(namespace) # TODO: Explore https://kustomize.io for templating - def create_template(self, template_path: str, replacements: dict) -> str: + def create_template(self, template_path: str, replacements: dict, *, log_template: bool = True) -> str: """ Generate a Kubernetes resource template by replacing placeholders with actual values. :param template_path: Path to the YAML template file. :param replacements: Dictionary of placeholders and their corresponding values. + :param log_template: Log the rendered template after all replacements. :return: Processed YAML content as a string. """ if not os.path.isfile(template_path): @@ -192,7 +193,9 @@ def create_template(self, template_path: str, replacements: dict) -> str: for key, value in replacements.items(): template = template.replace(f"{{{{{key}}}}}", str(value)) - logger.info(f"Final template: \n{template}") + + if log_template: + logger.info("Final template: \n%s", template) return template except Exception as e: diff --git a/modules/python/kwok/kwok.py b/modules/python/kwok/kwok.py index 26a9cde834..35363c92f8 100644 --- a/modules/python/kwok/kwok.py +++ b/modules/python/kwok/kwok.py @@ -111,6 +111,7 @@ class Node(KWOK): node_pods: str = "110" node_gpu: str = "0" enable_dra: bool = False + print_node_yaml: bool = False def create(self): try: @@ -137,7 +138,7 @@ def create(self): "node_gpu": self.node_gpu } kwok_template = self.k8s_client.create_template( - self.node_manifest_path, replacements + self.node_manifest_path, replacements, log_template=self.print_node_yaml ) execute_with_retries( self.k8s_client.create_node, @@ -317,6 +318,11 @@ def main(): parser = argparse.ArgumentParser( description="KWOK: Kubernetes WithOut Kubelet - Virtual Node/Pod Simulator" ) + parser.add_argument( + "--print-node-yaml", + action="store_true", + help="Print each rendered KWOK Node manifest during creation (default: off).", + ) parser.add_argument( "--node-count", type=int, @@ -388,6 +394,7 @@ def main(): kwok_release=args.kwok_release, enable_metrics=args.enable_metrics, enable_dra=args.enable_dra, + print_node_yaml=args.print_node_yaml, ) if args.action == "create": node.create() diff --git a/modules/python/tests/clients/test_kubernetes_client.py b/modules/python/tests/clients/test_kubernetes_client.py index 0ab752312e..314301ca76 100644 --- a/modules/python/tests/clients/test_kubernetes_client.py +++ b/modules/python/tests/clients/test_kubernetes_client.py @@ -920,6 +920,22 @@ def test_create_template_success(self, mock_isfile, mock_open_file): mock_open_file.assert_called_once_with(template_path, "r", encoding="utf-8") self.assertEqual(result, expected_output) + @patch("clients.kubernetes_client.logger") + @patch("builtins.open", mock_open(read_data="{{name}}: {{value}}")) + @patch("os.path.isfile", return_value=True) + def test_create_template_logging(self, _mock_isfile, mock_logger): + """Muting the manifest must not affect rendering.""" + replacements = {"name": "node", "value": "example"} + for options in ({"log_template": False}, {}): + with self.subTest(options=options): + mock_logger.reset_mock() + result = self.client.create_template("template.yaml", replacements, **options) + self.assertEqual(result, "node: example") + if options.get("log_template", True): + mock_logger.info.assert_called_once_with("Final template: \n%s", result) + else: + mock_logger.info.assert_not_called() + @patch("os.path.isfile", return_value=False) def test_create_template_file_not_found(self, mock_isfile): """Test create_template when template file does not exist.""" diff --git a/modules/python/tests/kwok/test_kwok_node.py b/modules/python/tests/kwok/test_kwok_node.py index beb2b31252..1a13b69a66 100644 --- a/modules/python/tests/kwok/test_kwok_node.py +++ b/modules/python/tests/kwok/test_kwok_node.py @@ -117,6 +117,20 @@ def test_create_nodes(self, mock_apply): except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Node creation failed: {exc}") + @patch("kwok.kwok.Node.apply_kwok_manifests") + def test_node_yaml_logging_is_opt_in(self, _mock_apply): + """Only node templates use the node YAML switch.""" + self.node.node_count = 1 + for expected in (False, True): + with self.subTest(print_node_yaml=expected): + if expected: + self.node.print_node_yaml = True + self.mock_k8s_client.create_template.reset_mock() + self.node.create() + node_call, slice_call = self.mock_k8s_client.create_template.call_args_list + self.assertEqual(node_call.kwargs, {"log_template": expected}) + self.assertNotIn("log_template", slice_call.kwargs) + def test_tear_down_nodes(self): """ Test the deletion of KWOK nodes from the cluster. From 28581ae5b80a98c89195b6743899be9da5e02a1f Mon Sep 17 00:00:00 2001 From: leonardducareer <101617499+LeonardCareer@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:02:48 +1100 Subject: [PATCH 2/6] Allow disabling KWOK Node YAML logging --- modules/python/clients/kubernetes_client.py | 7 +++---- modules/python/kwok/kwok.py | 7 ++++--- .../tests/clients/test_kubernetes_client.py | 16 ---------------- modules/python/tests/kwok/test_kwok_node.py | 14 -------------- 4 files changed, 7 insertions(+), 37 deletions(-) diff --git a/modules/python/clients/kubernetes_client.py b/modules/python/clients/kubernetes_client.py index df7d67f580..4d4240f349 100644 --- a/modules/python/clients/kubernetes_client.py +++ b/modules/python/clients/kubernetes_client.py @@ -181,7 +181,7 @@ def create_template(self, template_path: str, replacements: dict, *, log_templat :param template_path: Path to the YAML template file. :param replacements: Dictionary of placeholders and their corresponding values. - :param log_template: Log the rendered template after all replacements. + :param log_template: Whether to log the template content. :return: Processed YAML content as a string. """ if not os.path.isfile(template_path): @@ -193,9 +193,8 @@ def create_template(self, template_path: str, replacements: dict, *, log_templat for key, value in replacements.items(): template = template.replace(f"{{{{{key}}}}}", str(value)) - - if log_template: - logger.info("Final template: \n%s", template) + if log_template: + logger.info(f"Final template: \n{template}") return template except Exception as e: diff --git a/modules/python/kwok/kwok.py b/modules/python/kwok/kwok.py index 35363c92f8..458731c1c2 100644 --- a/modules/python/kwok/kwok.py +++ b/modules/python/kwok/kwok.py @@ -6,6 +6,7 @@ import requests from clients.kubernetes_client import KubernetesClient +from utils.common import str2bool from utils.retries import execute_with_retries @@ -111,7 +112,7 @@ class Node(KWOK): node_pods: str = "110" node_gpu: str = "0" enable_dra: bool = False - print_node_yaml: bool = False + print_node_yaml: bool = True def create(self): try: @@ -320,8 +321,8 @@ def main(): ) parser.add_argument( "--print-node-yaml", - action="store_true", - help="Print each rendered KWOK Node manifest during creation (default: off).", + type=str2bool, default=True, + help="Print KWOK Node YAML during creation (default: true).", ) parser.add_argument( "--node-count", diff --git a/modules/python/tests/clients/test_kubernetes_client.py b/modules/python/tests/clients/test_kubernetes_client.py index 314301ca76..0ab752312e 100644 --- a/modules/python/tests/clients/test_kubernetes_client.py +++ b/modules/python/tests/clients/test_kubernetes_client.py @@ -920,22 +920,6 @@ def test_create_template_success(self, mock_isfile, mock_open_file): mock_open_file.assert_called_once_with(template_path, "r", encoding="utf-8") self.assertEqual(result, expected_output) - @patch("clients.kubernetes_client.logger") - @patch("builtins.open", mock_open(read_data="{{name}}: {{value}}")) - @patch("os.path.isfile", return_value=True) - def test_create_template_logging(self, _mock_isfile, mock_logger): - """Muting the manifest must not affect rendering.""" - replacements = {"name": "node", "value": "example"} - for options in ({"log_template": False}, {}): - with self.subTest(options=options): - mock_logger.reset_mock() - result = self.client.create_template("template.yaml", replacements, **options) - self.assertEqual(result, "node: example") - if options.get("log_template", True): - mock_logger.info.assert_called_once_with("Final template: \n%s", result) - else: - mock_logger.info.assert_not_called() - @patch("os.path.isfile", return_value=False) def test_create_template_file_not_found(self, mock_isfile): """Test create_template when template file does not exist.""" diff --git a/modules/python/tests/kwok/test_kwok_node.py b/modules/python/tests/kwok/test_kwok_node.py index 1a13b69a66..beb2b31252 100644 --- a/modules/python/tests/kwok/test_kwok_node.py +++ b/modules/python/tests/kwok/test_kwok_node.py @@ -117,20 +117,6 @@ def test_create_nodes(self, mock_apply): except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Node creation failed: {exc}") - @patch("kwok.kwok.Node.apply_kwok_manifests") - def test_node_yaml_logging_is_opt_in(self, _mock_apply): - """Only node templates use the node YAML switch.""" - self.node.node_count = 1 - for expected in (False, True): - with self.subTest(print_node_yaml=expected): - if expected: - self.node.print_node_yaml = True - self.mock_k8s_client.create_template.reset_mock() - self.node.create() - node_call, slice_call = self.mock_k8s_client.create_template.call_args_list - self.assertEqual(node_call.kwargs, {"log_template": expected}) - self.assertNotIn("log_template", slice_call.kwargs) - def test_tear_down_nodes(self): """ Test the deletion of KWOK nodes from the cluster. From a8782ffff71b788fecc2818cd70925b2554396ee Mon Sep 17 00:00:00 2001 From: leonardducareer <101617499+LeonardCareer@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:05:44 +1100 Subject: [PATCH 3/6] Skip template logging for KWOK Nodes --- modules/python/kwok/kwok.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/modules/python/kwok/kwok.py b/modules/python/kwok/kwok.py index 458731c1c2..11c93a06f9 100644 --- a/modules/python/kwok/kwok.py +++ b/modules/python/kwok/kwok.py @@ -6,7 +6,6 @@ import requests from clients.kubernetes_client import KubernetesClient -from utils.common import str2bool from utils.retries import execute_with_retries @@ -112,7 +111,6 @@ class Node(KWOK): node_pods: str = "110" node_gpu: str = "0" enable_dra: bool = False - print_node_yaml: bool = True def create(self): try: @@ -139,7 +137,7 @@ def create(self): "node_gpu": self.node_gpu } kwok_template = self.k8s_client.create_template( - self.node_manifest_path, replacements, log_template=self.print_node_yaml + self.node_manifest_path, replacements, log_template=False ) execute_with_retries( self.k8s_client.create_node, @@ -319,11 +317,6 @@ def main(): parser = argparse.ArgumentParser( description="KWOK: Kubernetes WithOut Kubelet - Virtual Node/Pod Simulator" ) - parser.add_argument( - "--print-node-yaml", - type=str2bool, default=True, - help="Print KWOK Node YAML during creation (default: true).", - ) parser.add_argument( "--node-count", type=int, @@ -395,7 +388,6 @@ def main(): kwok_release=args.kwok_release, enable_metrics=args.enable_metrics, enable_dra=args.enable_dra, - print_node_yaml=args.print_node_yaml, ) if args.action == "create": node.create() From 0c13c91491df93d75a2f47b11141cdc61a5047a7 Mon Sep 17 00:00:00 2001 From: leonardducareer <101617499+LeonardCareer@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:11:34 +1100 Subject: [PATCH 4/6] Allow disabling KWOK Node YAML logging --- modules/python/kwok/kwok.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/python/kwok/kwok.py b/modules/python/kwok/kwok.py index 11c93a06f9..458731c1c2 100644 --- a/modules/python/kwok/kwok.py +++ b/modules/python/kwok/kwok.py @@ -6,6 +6,7 @@ import requests from clients.kubernetes_client import KubernetesClient +from utils.common import str2bool from utils.retries import execute_with_retries @@ -111,6 +112,7 @@ class Node(KWOK): node_pods: str = "110" node_gpu: str = "0" enable_dra: bool = False + print_node_yaml: bool = True def create(self): try: @@ -137,7 +139,7 @@ def create(self): "node_gpu": self.node_gpu } kwok_template = self.k8s_client.create_template( - self.node_manifest_path, replacements, log_template=False + self.node_manifest_path, replacements, log_template=self.print_node_yaml ) execute_with_retries( self.k8s_client.create_node, @@ -317,6 +319,11 @@ def main(): parser = argparse.ArgumentParser( description="KWOK: Kubernetes WithOut Kubelet - Virtual Node/Pod Simulator" ) + parser.add_argument( + "--print-node-yaml", + type=str2bool, default=True, + help="Print KWOK Node YAML during creation (default: true).", + ) parser.add_argument( "--node-count", type=int, @@ -388,6 +395,7 @@ def main(): kwok_release=args.kwok_release, enable_metrics=args.enable_metrics, enable_dra=args.enable_dra, + print_node_yaml=args.print_node_yaml, ) if args.action == "create": node.create() From 99223d4970f1f350772cc04c8041374eed1f4fc0 Mon Sep 17 00:00:00 2001 From: leonardducareer <101617499+LeonardCareer@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:14:58 +1100 Subject: [PATCH 5/6] Use a presence-only flag to disable Node YAML logging --- modules/python/kwok/kwok.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/python/kwok/kwok.py b/modules/python/kwok/kwok.py index 458731c1c2..d0852c050f 100644 --- a/modules/python/kwok/kwok.py +++ b/modules/python/kwok/kwok.py @@ -6,7 +6,6 @@ import requests from clients.kubernetes_client import KubernetesClient -from utils.common import str2bool from utils.retries import execute_with_retries @@ -320,9 +319,10 @@ def main(): description="KWOK: Kubernetes WithOut Kubelet - Virtual Node/Pod Simulator" ) parser.add_argument( - "--print-node-yaml", - type=str2bool, default=True, - help="Print KWOK Node YAML during creation (default: true).", + "--no-print-node-yaml", + dest="print_node_yaml", + action="store_false", + help="Do not print KWOK Node YAML during creation.", ) parser.add_argument( "--node-count", From ffc83cdf4e0a9205f59299b25573f426984ee093 Mon Sep 17 00:00:00 2001 From: leonardducareer <101617499+LeonardCareer@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:18:25 +1100 Subject: [PATCH 6/6] Rename the KWOK flag to --mute-node-creation --- modules/python/kwok/kwok.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/python/kwok/kwok.py b/modules/python/kwok/kwok.py index d0852c050f..c815619180 100644 --- a/modules/python/kwok/kwok.py +++ b/modules/python/kwok/kwok.py @@ -319,10 +319,10 @@ def main(): description="KWOK: Kubernetes WithOut Kubelet - Virtual Node/Pod Simulator" ) parser.add_argument( - "--no-print-node-yaml", + "--mute-node-creation", dest="print_node_yaml", action="store_false", - help="Do not print KWOK Node YAML during creation.", + help="Mute only the Node YAML during creation; other logs are unchanged.", ) parser.add_argument( "--node-count",