Skip to content

Commit

Permalink
Use --prefix-name option for tkn clustertask start
Browse files Browse the repository at this point in the history
Adding --prefix-name option for tkn clustertask start to allow a user to specify what the name of the TaskRun they will create is. Default name will follow the format clustertaskname-run-.

This option will override --last, which will use the name of the last TaskRun for a clustertask if nothing is specified.

Signed-off-by: vinamra28 <[email protected]>
  • Loading branch information
vinamra28 authored and tekton-robot committed Sep 18, 2020
1 parent 3bdd4ae commit 231d374
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/cmd/tkn_clustertask_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ like cat,foo,bar
-o, --outputresource strings pass the output resource name and ref as name=ref
-p, --param stringArray pass the param as key=value for string type, or key=value1,value2,... for array type
--pod-template string local or remote file containing a PodTemplate definition
--prefix-name string specify a prefix for the TaskRun name (must be lowercase alphanumeric characters)
-s, --serviceaccount string pass the serviceaccount name
--showlog show logs right after starting the ClusterTask
--timeout string timeout for TaskRun
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/tkn-clustertask-start.1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Start ClusterTasks
\fB\-\-pod\-template\fP=""
local or remote file containing a PodTemplate definition

.PP
\fB\-\-prefix\-name\fP=""
specify a prefix for the TaskRun name (must be lowercase alphanumeric characters)

.PP
\fB\-s\fP, \fB\-\-serviceaccount\fP=""
pass the serviceaccount name
Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/clustertask/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type startOptions struct {
TimeOut string
DryRun bool
Output string
PrefixName string
Workspaces []string
UseParamDefaults bool
clustertask *v1beta1.ClusterTask
Expand Down Expand Up @@ -169,6 +170,7 @@ like cat,foo,bar
c.Flags().StringVar(&opt.TimeOut, "timeout", "", "timeout for TaskRun")
c.Flags().BoolVarP(&opt.DryRun, "dry-run", "", false, "preview TaskRun without running it")
c.Flags().StringVarP(&opt.Output, "output", "", "", "format of TaskRun dry-run (yaml or json)")
c.Flags().StringVarP(&opt.PrefixName, "prefix-name", "", "", "specify a prefix for the TaskRun name (must be lowercase alphanumeric characters)")
c.Flags().StringVar(&opt.PodTemplate, "pod-template", "", "local or remote file containing a PodTemplate definition")
c.Flags().BoolVar(&opt.UseParamDefaults, "use-param-defaults", false, "use default parameter values without prompting for input")

Expand Down Expand Up @@ -211,7 +213,11 @@ func startClusterTask(opt startOptions, args []string) error {
tr.Spec.Timeout = &metav1.Duration{Duration: timeoutDuration}
}

tr.ObjectMeta.GenerateName = ctname + "-run-"
if opt.PrefixName == "" {
tr.ObjectMeta.GenerateName = ctname + "-run-"
} else {
tr.ObjectMeta.GenerateName = opt.PrefixName + "-"
}

// TaskRuns are namespaced so using same LastRun method as Task
if opt.Last {
Expand Down
70 changes: 70 additions & 0 deletions pkg/cmd/clustertask/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,41 @@ func Test_ClusterTask_Start(t *testing.T) {
wantError: true,
want: "cannot use --last with --use-param-defaults option",
},
{
name: "Dry Run with --prefix-name",
command: []string{"start", "clustertask-3",
"-i", "my-repo=git",
"-i", "my-image=image",
"-p", "myarg=value1",
"-p", "print=boom,boom",
"-l", "key=value",
"-o", "code-image=output-image",
"-w", "name=test,emptyDir=",
"-s=svc1",
"--dry-run",
"--prefix-name", "customname"},
dynamic: seeds[6].dynamicClient,
input: seeds[6].pipelineClient,
inputStream: nil,
wantError: false,
goldenFile: true,
},
{
name: "Dry Run with --prefix-name and --last",
command: []string{"start", "clustertask-1",
"-i", "my-repo=git",
"-o", "code-image=output-image",
"-l", "key=value",
"-s=svc1",
"--dry-run",
"--last",
"--prefix-name", "customname"},
dynamic: seeds[1].dynamicClient,
input: seeds[1].pipelineClient,
inputStream: nil,
wantError: false,
goldenFile: true,
},
}

for _, tp := range testParams {
Expand Down Expand Up @@ -1456,6 +1491,41 @@ func Test_ClusterTask_Start_v1beta1(t *testing.T) {
wantError: true,
want: "cannot use --last with --use-param-defaults option",
},
{
name: "Dry Run with --prefix-name v1beta1",
command: []string{"start", "clustertask-3",
"-i", "my-repo=git",
"-i", "my-image=image",
"-p", "myarg=value1",
"-p", "print=boom",
"-l", "key=value",
"-o", "code-image=output-image",
"-w", "name=test,emptyDir=",
"-s=svc1",
"--dry-run",
"--prefix-name", "customname"},
dynamic: seeds[5].dynamicClient,
input: seeds[5].pipelineClient,
inputStream: nil,
wantError: false,
goldenFile: true,
},
{
name: "Dry Run with --prefix-name and --last v1beta1",
command: []string{"start", "clustertask-1",
"-i", "my-repo=git",
"-o", "code-image=output-image",
"-l", "key=value",
"-s=svc1",
"--dry-run",
"--last",
"--prefix-name", "customname"},
dynamic: seeds[1].dynamicClient,
input: seeds[1].pipelineClient,
inputStream: nil,
wantError: false,
goldenFile: true,
},
}

for _, tp := range testParams {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
creationTimestamp: null
generateName: customname-
labels:
key: value
spec:
inputs:
params:
- name: myarg
value: value1
- name: print
value:
- boom
- boom
resources:
- name: my-image
resourceRef:
name: image
- name: my-repo
resourceRef:
name: git
outputs:
resources:
- name: code-image
resourceRef:
name: output-image
serviceAccountName: svc1
taskRef:
kind: ClusterTask
name: clustertask-3
workspaces:
- emptyDir: {}
name: test
status:
podName: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
creationTimestamp: null
generateName: customname-
labels:
key: value
spec:
inputs:
params:
- name: myarg
value: value
- name: print
value:
- booms
- booms
- booms
resources:
- name: my-repo
resourceRef:
name: git
outputs:
resources:
- name: code-image
resourceRef:
name: output-image
- name: my-image
resourceRef:
name: image
serviceAccountName: svc1
taskRef:
kind: ClusterTask
name: clustertask-1
timeout: 1h0m0s
workspaces:
- emptyDir: {}
name: test
status:
podName: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
creationTimestamp: null
generateName: customname-
labels:
key: value
spec:
params:
- name: myarg
value: value
- name: print
value:
- booms
- booms
- booms
resources:
inputs:
- name: my-repo
resourceRef:
name: git
outputs:
- name: code-image
resourceRef:
name: output-image
serviceAccountName: svc1
taskRef:
kind: ClusterTask
name: clustertask-1
workspaces:
- emptyDir: {}
name: test
status:
podName: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
creationTimestamp: null
generateName: customname-
labels:
key: value
spec:
params:
- name: myarg
value: value1
- name: print
value:
- boom
resources:
inputs:
- name: my-image
resourceRef:
name: image
- name: my-repo
resourceRef:
name: git
outputs:
- name: code-image
resourceRef:
name: output-image
serviceAccountName: svc1
taskRef:
kind: ClusterTask
name: clustertask-3
workspaces:
- emptyDir: {}
name: test
status:
podName: ""

0 comments on commit 231d374

Please sign in to comment.