-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a tool to create a task template
Signed-off-by: Puneet Punamiya <[email protected]>
- Loading branch information
1 parent
cdf6971
commit d96a5b3
Showing
2 changed files
with
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: "" | ||
labels: | ||
app.kubernetes.io/version: "" | ||
annotations: | ||
tekton.dev/pipelines.minVersion: "" | ||
tekton.dev/tags: "" | ||
tekton.dev/displayName: "" | ||
spec: | ||
description: "" |
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,65 @@ | ||
# importing os module | ||
import os | ||
import yaml as y | ||
from ruamel.yaml import YAML | ||
import json | ||
import sys | ||
|
||
in_file = "template.yaml" | ||
|
||
yaml = YAML(typ='safe') | ||
with open(in_file) as fpi: | ||
data = yaml.load(fpi) | ||
|
||
jsondata = json.dumps(data, indent=2) | ||
json_object = json.loads(jsondata) | ||
|
||
# # Parent Directory path | ||
parent_dir = "" | ||
|
||
task = {'task', 't', 'Task'} | ||
pipeline = {'pipeline', 'p', 'Pipeline'} | ||
|
||
print("Enter type of resource", "Task-", task, "or", "Pipeline-", pipeline) | ||
choice = input().lower() | ||
if choice in task: | ||
parent_dir = "task" | ||
elif choice in pipeline: | ||
parent_dir = "pipeline" | ||
else: | ||
sys.stdout.write("Please respond with 'task' or 'pipeline'") | ||
|
||
|
||
name = input("Enter name of resource: ") | ||
version = input("Enter version of the resource: ") | ||
|
||
# # Path | ||
path = os.path.join(parent_dir, name.lower()) | ||
|
||
finalPath = os.path.join(path, version) | ||
|
||
# # Speicfy the file name | ||
file = name + ".yaml" | ||
metadata = json_object["metadata"] | ||
|
||
try: | ||
os.makedirs(finalPath) | ||
print("Directory '% s' created" % name) | ||
|
||
minPipelineVersion = input("Enter min pipeline version: ") | ||
tags = input("Enter tags related to task: ") | ||
displayName = input("Enter displayName of task: ") | ||
|
||
metadata["name"] = name | ||
metadata["labels"]["app.kubernetes.io/version"] = version | ||
metadata["annotations"]["tekton.dev/tags"] = tags | ||
metadata["annotations"]["tekton.dev/pipelines.minVersion"] = minPipelineVersion | ||
metadata["annotations"]["tekton.dev/displayName"] = displayName | ||
|
||
except OSError as error: | ||
print("""Resource with %s and version %s already exists""" % (name, version)) | ||
sys.exit(1) | ||
|
||
# Creating a file at specified location | ||
with open(os.path.join(finalPath, file), 'w') as yaml_file: | ||
y.dump(json_object, yaml_file, default_flow_style=False) |