Skip to content

Commit

Permalink
Adds a tool to create a task template
Browse files Browse the repository at this point in the history
  - This patch adds a tool which help to create
    a manifest template for task/pipeline based
    on Tekton Catalog Organization Proposal

Signed-off-by: Puneet Punamiya <[email protected]>
  • Loading branch information
PuneetPunamiya committed Jun 11, 2021
1 parent cdf6971 commit 00a675f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/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: ''
75 changes: 75 additions & 0 deletions tools/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os
import yaml as y
from ruamel.yaml import YAML
import json
import sys

# Parent Directory path
parent_dir = os.path.normpath(
os.path.join(os.path.dirname(
os.path.abspath(__file__)), '..'))

# Type of Resource
task = {'task', 't', 'Task'}
pipeline = {'pipeline', 'p', 'Pipeline'}

# Basic Template of Manifest according to TEP
template = "template.yaml"

yaml = YAML()
with open(template) as fpi:
data = yaml.load(fpi)

jsondata = json.dumps(data, indent=2)
json_object = json.loads(jsondata)

# Type of resource
type = input("Enter type of resource: task/pipeline: ").lower()
if type in task:
parent_dir = parent_dir + "/task/"
elif type in pipeline:
parent_dir = parent_dir + "/pipeline/"
else:
sys.stdout.write("Please respond with 'task' or 'pipeline'")
sys.exit(1)

name = input("\n" + "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"


def createResourceTemplate():
try:
os.makedirs(finalPath)
print("\n" + "Directory 📁 '% s' created" % name + "\n")

minPipelineVersion = input("Enter min pipeline version: ")
tags = input("Enter tags related to task: ")
displayName = input("Enter displayName of task: ")

metadata = json_object["metadata"]

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)


if __name__ == '__main__':
createResourceTemplate()

0 comments on commit 00a675f

Please sign in to comment.