Skip to content
Open
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
6 changes: 4 additions & 2 deletions modules/python/clients/kubernetes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: Whether to log the template content.
:return: Processed YAML content as a string.
"""
if not os.path.isfile(template_path):
Expand All @@ -192,7 +193,8 @@ 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(f"Final template: \n{template}")

return template
except Exception as e:
Expand Down
10 changes: 9 additions & 1 deletion modules/python/kwok/kwok.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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:
Expand All @@ -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,
Expand Down Expand Up @@ -317,6 +318,12 @@ def main():
parser = argparse.ArgumentParser(
description="KWOK: Kubernetes WithOut Kubelet - Virtual Node/Pod Simulator"
)
parser.add_argument(
"--mute-node-creation",
dest="print_node_yaml",
action="store_false",
help="Mute only the Node YAML during creation; other logs are unchanged.",
)
parser.add_argument(
"--node-count",
type=int,
Expand Down Expand Up @@ -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()
Expand Down
Loading