Skip to content

Commit

Permalink
simple script to generate an appwrapper from an input Kubernetes YAML (
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrove-oss authored Aug 22, 2024
1 parent 2a6ba01 commit 7b465c6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ common configuration options. Using this Helm chart helps eliminate common
mistakes. Please see [pytorchjob-generator](tools/pytorchjob-generator) for
detailed usage instructions.

## Generating AppWrappers from Kubernetes YAML files

If you have a Kubernetes YAML file containing one or more
non-AppWrapper resources (eg Deployments, Pods, Services, etc),
you can use the [appwrapper-packager](tools/appwrapper-package) tool
to generate an AppWrapper yaml containing those resources.

## Queues

All workloads must target a local queue in their namespace. The local queue name
Expand Down
26 changes: 26 additions & 0 deletions tools/appwrapper-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AppWrapper Packager

The Python script in this directory takes as input a YAML file
containing one or more Kubernetes resources and generates
an output YAML file with an AppWrapper containing the input
resources.

Example invocation:
```sh
./awpack.py -i input.yaml -o aw.yaml -n my-appwrapper
```

Usage information:
```sh
usage: awpack.py [-h] -i INPUT [-n NAME] [-o OUTPUT]

Wrap Resources in an AppWrapper

options:
-h, --help show this help message and exit
-i INPUT, --input INPUT
input YAML file
-n NAME, --name NAME name of AppWrapper
-o OUTPUT, --output OUTPUT
output file
```
42 changes: 42 additions & 0 deletions tools/appwrapper-package/awpack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

import os
import string
import argparse
from pathlib import Path


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Wrap Resources in an AppWrapper"
)
parser.add_argument("-i", "--input", type=str, help="input YAML file", required=True)
parser.add_argument("-n", "--name", type=str, help="name of AppWrapper", default="sample-appwrapper")
parser.add_argument("-o", "--output", type=str, help="output file", default="aw.yaml")
args = parser.parse_args()

new_object = True

with open(args.output, mode="w") as output_file:
with open(args.input) as input_file:
output_file.write("apiVersion: workload.codeflare.dev/v1beta2\n")
output_file.write("kind: AppWrapper\n")
output_file.write("metadata:\n")
output_file.write(f" name: {args.name}\n")
output_file.write(" labels:\n")
output_file.write(" kueue.x-k8s.io/queue-name: default-queue\n")
output_file.write("spec:\n")
output_file.write(" components:\n")
while True:
line = input_file.readline()
if not line:
break
if line.startswith("---"):
new_object = True
continue
if line == "\n":
continue
if new_object:
output_file.write(" - template:\n")
new_object = False
output_file.write(" "+line)

0 comments on commit 7b465c6

Please sign in to comment.