-
Notifications
You must be signed in to change notification settings - Fork 575
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
- 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
1 parent
cdf6971
commit 00a675f
Showing
2 changed files
with
88 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,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() |