-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple script to generate an appwrapper from an input Kubernetes YAML (…
…#37)
- Loading branch information
1 parent
2a6ba01
commit 7b465c6
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |