Skip to content

Commit

Permalink
Adds a tool to create a task template
Browse files Browse the repository at this point in the history
Signed-off-by: Puneet Punamiya <[email protected]>
  • Loading branch information
PuneetPunamiya committed May 26, 2021
1 parent cdf6971 commit d96a5b3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
13 changes: 13 additions & 0 deletions template.yaml
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: ""
65 changes: 65 additions & 0 deletions tools.py
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)

0 comments on commit d96a5b3

Please sign in to comment.