-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a tool to create a simple task template #739
Open
PuneetPunamiya
wants to merge
1
commit into
tektoncd:main
Choose a base branch
from
PuneetPunamiya:tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,30 @@ | ||
--- | ||
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: '' | ||
|
||
workspaces: | ||
- name: '' # Name of the workspace | ||
description: '' # Description of the workspace | ||
optional: true # Optional value of the workspace | ||
|
||
params: | ||
- name: '' # Name of parms | ||
description: '' # Description of the params | ||
default: '' # Default value of the params | ||
|
||
steps: | ||
- name: '' # Name of steps | ||
image: '' # Name of the image to be used for the resource | ||
script: | # Actions resource performs | ||
|
||
args: [] # Arguments to execute |
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 @@ | ||
## Install the Task | ||
|
||
``` | ||
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/ | ||
``` | ||
|
||
## Parameters | ||
|
||
|
||
## Workspaces | ||
|
||
|
||
## Usage |
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,152 @@ | ||
import os | ||
import yaml as y | ||
from ruamel.yaml import YAML | ||
import json | ||
import sys | ||
import argparse | ||
|
||
# Parent Directory path | ||
parent_dir = os.path.normpath( | ||
os.path.join(os.path.dirname( | ||
os.path.abspath(__file__)), '..')) | ||
|
||
TEP_TEMPLATE = os.path.normpath( | ||
os.path.join(os.path.dirname( | ||
os.path.abspath(__file__)), 'tep-template.md.template')) | ||
|
||
print(TEP_TEMPLATE) | ||
# 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) | ||
|
||
|
||
def createResourceTemplate(name: str, version: str, finalPath: str, file: str): | ||
if not os.path.exists(finalPath): | ||
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 | ||
|
||
# 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) | ||
else: | ||
print( | ||
f"Resource with name `{name}` and version `{version}` already exists") | ||
sys.exit(1) | ||
|
||
|
||
def kind(args): | ||
# Parent Directory path | ||
parent_dir = os.path.normpath( | ||
os.path.join(os.path.dirname( | ||
os.path.abspath(__file__)), '..')) | ||
|
||
resourcetype = args.kind[0] | ||
if resourcetype in task: | ||
parent_dir = parent_dir + "/task/" | ||
return resourcetype, parent_dir | ||
elif resourcetype in pipeline: | ||
parent_dir = parent_dir + "/pipeline/" | ||
return resourcetype, parent_dir | ||
else: | ||
sys.stdout.write("Please respond with 'task' or 'pipeline'") | ||
sys.exit(1) | ||
|
||
|
||
def resName(args): | ||
return args.name[0] | ||
|
||
|
||
def ver(args): | ||
return args.version[0] | ||
|
||
|
||
def readmeTemplate(tep, tep_io): | ||
header = { | ||
'title': tep['title'], | ||
} | ||
tep_io.write(f'# {header["title"].capitalize()}\n\n') | ||
|
||
|
||
def main(): | ||
|
||
resourcetype = "" | ||
name = "" | ||
version = "" | ||
|
||
parser = argparse.ArgumentParser(description="Resource Template Tool!") | ||
|
||
parser.add_argument("-k", "--kind", type=str, nargs=1, | ||
metavar=('type'), | ||
help="Type of the resource.") | ||
|
||
parser.add_argument("-n", "--name", type=str, nargs=1, | ||
metavar=('resourceName'), | ||
help="Name of the resource.") | ||
|
||
parser.add_argument("-v", "--version", type=str, nargs=1, | ||
metavar=('version'), | ||
help="Version of the resource.") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.kind != None: | ||
resourcetype, parent_dir = kind(args) | ||
if args.name != None: | ||
name = resName(args) | ||
if args.version != None: | ||
version = ver(args) | ||
|
||
if resourcetype == "": | ||
sys.stdout.write("Please enter the type of resource") | ||
sys.exit(1) | ||
|
||
if name == "": | ||
sys.stdout.write("Please enter the name of resource") | ||
sys.exit(1) | ||
|
||
if version == "": | ||
sys.stdout.write("Please enter the version of resource") | ||
sys.exit(1) | ||
|
||
# Path | ||
path = os.path.join(parent_dir, name.lower()) | ||
|
||
finalPath = os.path.join(path, version) | ||
|
||
# Speicfy the file name | ||
file = name + ".yaml" | ||
|
||
createResourceTemplate(name, version, finalPath, file) | ||
|
||
resource = dict(title=name) | ||
|
||
with open(os.path.join(finalPath, "README.md"), 'w+') as new_resource: | ||
readmeTemplate(resource, new_resource) | ||
with open(TEP_TEMPLATE, 'r') as template: | ||
new_resource.write(template.read()) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo