From 0bcc83ebe7ead888c67bd427c339deddcc77e2bc Mon Sep 17 00:00:00 2001 From: pratap0007 Date: Fri, 21 Mar 2025 18:40:25 +0530 Subject: [PATCH] Remove the deprecated clustertask command Clustertask support is deprecated and removed this patch will remove the clustertask support Signed-off-by: Shiv Verma --- README.md | 1 - docs/cmd/tkn_clustertask.md | 35 - docs/cmd/tkn_clustertask_create.md | 40 - docs/cmd/tkn_clustertask_delete.md | 52 - docs/cmd/tkn_clustertask_describe.md | 49 - docs/cmd/tkn_clustertask_list.md | 39 - docs/cmd/tkn_clustertask_logs.md | 56 - docs/cmd/tkn_clustertask_start.md | 82 -- docs/cmd/tkn_task_create.md | 41 - docs/cmd/tkn_taskrun_delete.md | 1 - docs/man/man1/tkn-clustertask-create.1 | 55 - docs/man/man1/tkn-clustertask-delete.1 | 98 -- docs/man/man1/tkn-clustertask-describe.1 | 86 -- docs/man/man1/tkn-clustertask-list.1 | 64 - docs/man/man1/tkn-clustertask-logs.1 | 113 -- docs/man/man1/tkn-clustertask-start.1 | 169 --- docs/man/man1/tkn-clustertask.1 | 41 - docs/man/man1/tkn-task-create.1 | 59 - docs/man/man1/tkn-taskrun-delete.1 | 4 - pkg/clustertask/clustertask.go | 78 -- pkg/clustertask/clustertask_test.go | 288 ---- pkg/cmd/bundle/list.go | 2 +- pkg/cmd/clustertask/clustertask.go | 51 - pkg/cmd/clustertask/clustertask_test.go | 36 - pkg/cmd/clustertask/create.go | 122 -- pkg/cmd/clustertask/create_test.go | 191 --- pkg/cmd/clustertask/delete.go | 163 --- pkg/cmd/clustertask/delete_test.go | 329 ----- pkg/cmd/clustertask/describe.go | 232 ---- pkg/cmd/clustertask/describe_test.go | 639 --------- pkg/cmd/clustertask/list.go | 118 -- pkg/cmd/clustertask/list_test.go | 158 --- pkg/cmd/clustertask/logs.go | 210 --- pkg/cmd/clustertask/logs_test.go | 203 --- pkg/cmd/clustertask/start.go | 402 ------ pkg/cmd/clustertask/start_test.go | 920 ------------- ...estClusterTaskDescribe_With_Results.golden | 14 - ...ClusterTaskDescribe_With_Workspaces.golden | 12 - ...houtNameIfOnlyOneClusterTaskPresent.golden | 2 - ...eIfOnlyOneV1beta1ClusterTaskPresent.golden | 2 - ...lusterTaskDescribe_with_annotations.golden | 4 - ...TestClusterTaskListNoHeadersv1beta1.golden | 3 - ...sterTaskListOnlyClusterTasksv1beta1.golden | 7 - ...ing_param_default_one_of_everything.golden | 18 - ...Describe_clustertask_with_name_only.golden | 2 - ..._full_clustertask_multiple_taskruns.golden | 20 - ...th_--prefix-name_and_--last_v1beta1.golden | 26 - ...-Dry_Run_with_--prefix-name_v1beta1.golden | 24 - ...am-defaults_and_no_specified_params.golden | 18 - ...param-defaults_and_specified_params.golden | 24 - ...usterTask_Start-Dry_run_with_--last.golden | 26 - ...tart-Dry_run_with_--timeout_v1beta1.golden | 19 - ...Task_Start-Dry_run_with_PodTemplate.golden | 26 - ...tart-Dry_run_with_no_output_v1beta1.golden | 18 - pkg/cmd/clustertask/testdata/podtemplate.yaml | 18 - pkg/cmd/root.go | 2 - pkg/cmd/task/create.go | 123 -- pkg/cmd/task/create_test.go | 188 --- pkg/cmd/task/delete.go | 2 +- pkg/cmd/task/delete_test.go | 30 - pkg/cmd/task/describe.go | 2 +- pkg/cmd/task/describe_test.go | 28 - pkg/cmd/task/start.go | 5 +- pkg/cmd/task/task.go | 1 - pkg/cmd/taskrun/delete.go | 24 +- pkg/cmd/taskrun/delete_test.go | 1161 +---------------- pkg/cmd/taskrun/list.go | 2 +- pkg/cmd/taskrun/list_test.go | 101 +- .../TestListTaskRuns-all_in_namespace.golden | 1 - .../TestListTaskRuns-by_output_as_name.golden | 1 - ...stTaskRuns-filter_taskruns_by_label.golden | 1 - ...ter_taskruns_by_label_with_in_query.golden | 1 - ..._taskruns_greater_than_maximum_case.golden | 1 - .../TestListTaskRuns-print_by_template.golden | 1 - .../TestListTaskRuns-print_in_reverse.golden | 1 - ...s-print_in_reverse_with_output_flag.golden | 1 - ...ns-print_taskruns_in_all_namespaces.golden | 1 - ...s_in_all_namespaces_without_headers.golden | 1 - ...stTaskRuns_v1beta1-all_in_namespace.golden | 1 - ...tTaskRuns_v1beta1-by_output_as_name.golden | 1 - ...ns_v1beta1-filter_taskruns_by_label.golden | 1 - ...ter_taskruns_by_label_with_in_query.golden | 1 - ..._taskruns_greater_than_maximum_case.golden | 1 - ...tTaskRuns_v1beta1-print_by_template.golden | 1 - ...stTaskRuns_v1beta1-print_in_reverse.golden | 1 - ...1-print_in_reverse_with_output_flag.golden | 1 - ...a1-print_taskruns_in_all_namespaces.golden | 1 - ...s_in_all_namespaces_without_headers.golden | 1 - pkg/cmd/testdata/TestPluginList.golden | 1 - pkg/options/describe.go | 3 - pkg/options/describe_test.go | 140 +- pkg/options/logs.go | 5 - pkg/options/logs_test.go | 37 - pkg/options/resource_names.go | 1 - pkg/options/start.go | 126 -- pkg/task/tasklastrun.go | 10 +- pkg/task/tasklastrun_test.go | 397 ------ pkg/test/builder/unstructured.go | 9 - pkg/test/controller.go | 11 - pkg/test/dynamic/clientset/tekton.go | 2 +- pkg/test/dynamic/dynamictestclient.go | 1 - test/README.md | 23 +- test/builder/builder.go | 95 -- test/e2e/clustertask/start_test.go | 391 ------ test/framework/clients.go | 3 - .../clustertask-with-optional-workspace.yaml | 30 - test/resources/read-file-clustertask.yaml | 36 - 107 files changed, 103 insertions(+), 8417 deletions(-) delete mode 100644 docs/cmd/tkn_clustertask.md delete mode 100644 docs/cmd/tkn_clustertask_create.md delete mode 100644 docs/cmd/tkn_clustertask_delete.md delete mode 100644 docs/cmd/tkn_clustertask_describe.md delete mode 100644 docs/cmd/tkn_clustertask_list.md delete mode 100644 docs/cmd/tkn_clustertask_logs.md delete mode 100644 docs/cmd/tkn_clustertask_start.md delete mode 100644 docs/cmd/tkn_task_create.md delete mode 100644 docs/man/man1/tkn-clustertask-create.1 delete mode 100644 docs/man/man1/tkn-clustertask-delete.1 delete mode 100644 docs/man/man1/tkn-clustertask-describe.1 delete mode 100644 docs/man/man1/tkn-clustertask-list.1 delete mode 100644 docs/man/man1/tkn-clustertask-logs.1 delete mode 100644 docs/man/man1/tkn-clustertask-start.1 delete mode 100644 docs/man/man1/tkn-clustertask.1 delete mode 100644 docs/man/man1/tkn-task-create.1 delete mode 100644 pkg/clustertask/clustertask.go delete mode 100644 pkg/clustertask/clustertask_test.go delete mode 100644 pkg/cmd/clustertask/clustertask.go delete mode 100644 pkg/cmd/clustertask/clustertask_test.go delete mode 100644 pkg/cmd/clustertask/create.go delete mode 100644 pkg/cmd/clustertask/create_test.go delete mode 100644 pkg/cmd/clustertask/delete.go delete mode 100644 pkg/cmd/clustertask/delete_test.go delete mode 100644 pkg/cmd/clustertask/describe.go delete mode 100644 pkg/cmd/clustertask/describe_test.go delete mode 100644 pkg/cmd/clustertask/list.go delete mode 100644 pkg/cmd/clustertask/list_test.go delete mode 100644 pkg/cmd/clustertask/logs.go delete mode 100644 pkg/cmd/clustertask/logs_test.go delete mode 100644 pkg/cmd/clustertask/start.go delete mode 100644 pkg/cmd/clustertask/start_test.go delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Results.golden delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Workspaces.golden delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneClusterTaskPresent.golden delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneV1beta1ClusterTaskPresent.golden delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_with_annotations.golden delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskListNoHeadersv1beta1.golden delete mode 100644 pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasksv1beta1.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_missing_param_default_one_of_everything.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_with_name_only.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_full_clustertask_multiple_taskruns.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_and_--last_v1beta1.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_v1beta1.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_no_specified_params.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_specified_params.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--timeout_v1beta1.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_PodTemplate.golden delete mode 100644 pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden delete mode 100644 pkg/cmd/clustertask/testdata/podtemplate.yaml delete mode 100644 pkg/cmd/task/create.go delete mode 100644 pkg/cmd/task/create_test.go delete mode 100644 test/e2e/clustertask/start_test.go delete mode 100644 test/resources/clustertask-with-optional-workspace.yaml delete mode 100644 test/resources/read-file-clustertask.yaml diff --git a/README.md b/README.md index 85fabf2b0b..752c298e57 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,6 @@ The following commands help you understand and effectively use the Tekton CLI: * `tkn help:` Displays a list of the commands with helpful information. * [`tkn bundle:`](docs/cmd/tkn_bundle.md) Manage Tekton [bundles](https://github.com/tektoncd/pipeline/blob/main/docs/tekton-bundle-contracts.md) - * [`tkn clustertask:`](docs/cmd/tkn_clustertask.md) Parent command of the ClusterTask command group. * [`tkn clustertriggerbinding:`](docs/cmd/tkn_clustertriggerbinding.md) Parent command of the ClusterTriggerBinding command group. * [`tkn completion:`](docs/cmd/tkn_completion.md) Outputs a BASH, ZSH, Fish or PowerShell completion script for `tkn` to allow command completion with Tab. * [`tkn customrun:`](docs/cmd/tkn_customrun.md) Parent command of the Customrun command group. diff --git a/docs/cmd/tkn_clustertask.md b/docs/cmd/tkn_clustertask.md deleted file mode 100644 index 0ff308d484..0000000000 --- a/docs/cmd/tkn_clustertask.md +++ /dev/null @@ -1,35 +0,0 @@ -## tkn clustertask - -Manage ClusterTasks - -***Aliases**: ct,clustertasks* - -### Usage - -``` -tkn clustertask -``` - -### Synopsis - -Manage ClusterTasks - -### Options - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -h, --help help for clustertask - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn](tkn.md) - CLI for tekton pipelines -* [tkn clustertask create](tkn_clustertask_create.md) - Create a ClusterTask from Task -* [tkn clustertask delete](tkn_clustertask_delete.md) - Delete ClusterTasks in a cluster -* [tkn clustertask describe](tkn_clustertask_describe.md) - Describe a ClusterTask -* [tkn clustertask list](tkn_clustertask_list.md) - Lists ClusterTasks -* [tkn clustertask logs](tkn_clustertask_logs.md) - Show ClusterTask logs -* [tkn clustertask start](tkn_clustertask_start.md) - Start ClusterTasks - diff --git a/docs/cmd/tkn_clustertask_create.md b/docs/cmd/tkn_clustertask_create.md deleted file mode 100644 index 113ef014a8..0000000000 --- a/docs/cmd/tkn_clustertask_create.md +++ /dev/null @@ -1,40 +0,0 @@ -## tkn clustertask create - -Create a ClusterTask from Task - -### Usage - -``` -tkn clustertask create -``` - -### Synopsis - -Create a ClusterTask from Task - -### Examples - -Create a ClusterTask from Task 'foo' present in namespace 'ns': - tkn clustertask create --from foo -or - tkn clustertask create foobar --from=foo - -### Options - -``` - --from string Create a ClusterTask from Task in a particular namespace - -h, --help help for create -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks - diff --git a/docs/cmd/tkn_clustertask_delete.md b/docs/cmd/tkn_clustertask_delete.md deleted file mode 100644 index 4300d3d2a8..0000000000 --- a/docs/cmd/tkn_clustertask_delete.md +++ /dev/null @@ -1,52 +0,0 @@ -## tkn clustertask delete - -Delete ClusterTasks in a cluster - -***Aliases**: rm* - -### Usage - -``` -tkn clustertask delete -``` - -### Synopsis - -Delete ClusterTasks in a cluster - -### Examples - -Delete ClusterTasks with names 'foo' and 'bar': - - tkn clustertask delete foo bar - -or - - tkn ct rm foo bar - - -### Options - -``` - --all Delete all ClusterTasks (default: false) - --allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true) - -f, --force Whether to force deletion (default: false) - -h, --help help for delete - -o, --output string Output format. One of: (json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file). - --show-managed-fields If true, keep the managedFields when printing objects in JSON or YAML format. - --template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. - --trs Whether to delete ClusterTask(s) and related resources (TaskRuns) (default: false) -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks - diff --git a/docs/cmd/tkn_clustertask_describe.md b/docs/cmd/tkn_clustertask_describe.md deleted file mode 100644 index 59b7b20d3b..0000000000 --- a/docs/cmd/tkn_clustertask_describe.md +++ /dev/null @@ -1,49 +0,0 @@ -## tkn clustertask describe - -Describe a ClusterTask - -***Aliases**: desc* - -### Usage - -``` -tkn clustertask describe -``` - -### Synopsis - -Describe a ClusterTask - -### Examples - -Describe a ClusterTask of name 'foo': - - tkn clustertask describe foo - -or - - tkn ct desc foo - - -### Options - -``` - --allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true) - -h, --help help for describe - -o, --output string Output format. One of: (json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file). - --show-managed-fields If true, keep the managedFields when printing objects in JSON or YAML format. - --template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks - diff --git a/docs/cmd/tkn_clustertask_list.md b/docs/cmd/tkn_clustertask_list.md deleted file mode 100644 index a61e586f4c..0000000000 --- a/docs/cmd/tkn_clustertask_list.md +++ /dev/null @@ -1,39 +0,0 @@ -## tkn clustertask list - -Lists ClusterTasks - -***Aliases**: ls* - -### Usage - -``` -tkn clustertask list -``` - -### Synopsis - -Lists ClusterTasks - -### Options - -``` - --allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true) - -h, --help help for list - --no-headers do not print column headers with output (default print column headers with output) - -o, --output string Output format. One of: (json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file). - --show-managed-fields If true, keep the managedFields when printing objects in JSON or YAML format. - --template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks - diff --git a/docs/cmd/tkn_clustertask_logs.md b/docs/cmd/tkn_clustertask_logs.md deleted file mode 100644 index 01787c57f3..0000000000 --- a/docs/cmd/tkn_clustertask_logs.md +++ /dev/null @@ -1,56 +0,0 @@ -## tkn clustertask logs - -Show ClusterTask logs - -### Usage - -``` -tkn clustertask logs -``` - -### Synopsis - -Show ClusterTask logs - -### Examples - -Interactive mode: shows logs of the selected TaskRun: - - tkn clustertask logs -n namespace - -Interactive mode: shows logs of the selected TaskRun of the given ClusterTask: - - tkn clustertask logs clustertask -n namespace - -Show logs of given ClusterTask for last TaskRun: - - tkn clustertask logs clustertask -n namespace --last - -Show logs for given ClusterTask and associated TaskRun: - - tkn clustertask logs clustertask taskrun -n namespace - - -### Options - -``` - -a, --all show all logs including init steps injected by tekton - -f, --follow stream live logs - -h, --help help for logs - -L, --last show logs for last TaskRun - --limit int lists number of TaskRuns (default 5) - -t, --timestamps show logs with timestamp -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks - diff --git a/docs/cmd/tkn_clustertask_start.md b/docs/cmd/tkn_clustertask_start.md deleted file mode 100644 index 2dc3bf4ce3..0000000000 --- a/docs/cmd/tkn_clustertask_start.md +++ /dev/null @@ -1,82 +0,0 @@ -## tkn clustertask start - -Start ClusterTasks - -### Usage - -``` -tkn clustertask start -``` - -### Synopsis - -Start ClusterTasks - -### Examples - -Start ClusterTask foo by creating a TaskRun named "foo-run-xyz123" in namespace 'bar': - - tkn clustertask start foo -n bar - -or - - tkn ct start foo -n bar - -For params value, if you want to provide multiple values, provide them comma separated -like cat,foo,bar - -For passing the workspaces via flags: - -- In case of emptyDir, you can pass it like -w name=my-empty-dir,emptyDir= -- In case of configMap, you can pass it like -w name=my-config,config=rpg,item=ultimav=1 -- In case of secrets, you can pass it like -w name=my-secret,secret=secret-name -- In case of pvc, you can pass it like -w name=my-pvc,claimName=pvc1 -- In case of volumeClaimTemplate, you can pass it like -w name=my-volume-claim-template,volumeClaimTemplateFile=workspace-template.yaml - but before you need to create a workspace-template.yaml file. Sample contents of the file are as follows: - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi -- In case of binding a CSI workspace, you can pass it like -w name=my-csi,csiFile=csi.yaml - but you need to create a csi.yaml file before hand. Sample contents of the file are as follows: - - driver: secrets-store.csi.k8s.io - readOnly: true - volumeAttributes: - secretProviderClass: "vault-database" - - -### Options - -``` - --dry-run preview TaskRun without running it - -h, --help help for start - -l, --labels strings pass labels as label=value. - -L, --last re-run the ClusterTask using last TaskRun values - --output string format of TaskRun (yaml or json) - -p, --param stringArray pass the param as key=value for string type, or key=value1,value2,... for array type, or key="key1:value1, key2:value2" for object 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 - --skip-optional-workspace skips the prompt for optional workspaces - --timeout string timeout for TaskRun - --use-param-defaults use default parameter values without prompting for input - --use-taskrun string specify a TaskRun name to use its values to re-run the TaskRun - -w, --workspace stringArray pass one or more workspaces to map to the corresponding physical volumes -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks - diff --git a/docs/cmd/tkn_task_create.md b/docs/cmd/tkn_task_create.md deleted file mode 100644 index c278f19ed0..0000000000 --- a/docs/cmd/tkn_task_create.md +++ /dev/null @@ -1,41 +0,0 @@ -## tkn task create - -Create a Task from ClusterTask - -### Usage - -``` -tkn task create -``` - -### Synopsis - -Create a Task from ClusterTask - -### Examples - -Create a Task from ClusterTask 'foo' in namespace 'ns': - tkn task create --from foo -or - tkn task create foobar --from=foo -n ns - -### Options - -``` - --from string Create a ClusterTask from Task in a particular namespace - -h, --help help for create -``` - -### Options inherited from parent commands - -``` - -c, --context string name of the kubeconfig context to use (default: kubectl config current-context) - -k, --kubeconfig string kubectl config file (default: $HOME/.kube/config) - -n, --namespace string namespace to use (default: from $KUBECONFIG) - -C, --no-color disable coloring (default: false) -``` - -### SEE ALSO - -* [tkn task](tkn_task.md) - Manage Tasks - diff --git a/docs/cmd/tkn_taskrun_delete.md b/docs/cmd/tkn_taskrun_delete.md index 50c88ae28c..d34f16466f 100644 --- a/docs/cmd/tkn_taskrun_delete.md +++ b/docs/cmd/tkn_taskrun_delete.md @@ -30,7 +30,6 @@ or ``` --all Delete all TaskRuns in a namespace (default: false) --allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true) - --clustertask string The name of a ClusterTask whose TaskRuns should be deleted (does not delete the ClusterTask) -f, --force Whether to force deletion (default: false) -h, --help help for delete -i, --ignore-running ignore running TaskRun (default true) diff --git a/docs/man/man1/tkn-clustertask-create.1 b/docs/man/man1/tkn-clustertask-create.1 deleted file mode 100644 index f7c8b51f6a..0000000000 --- a/docs/man/man1/tkn-clustertask-create.1 +++ /dev/null @@ -1,55 +0,0 @@ -.TH "TKN\-CLUSTERTASK\-CREATE" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask\-create \- Create a ClusterTask from Task - - -.SH SYNOPSIS -.PP -\fBtkn clustertask create\fP - - -.SH DESCRIPTION -.PP -Create a ClusterTask from Task - - -.SH OPTIONS -.PP -\fB\-\-from\fP="" - Create a ClusterTask from Task in a particular namespace - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for create - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH EXAMPLE -.PP -Create a ClusterTask from Task 'foo' present in namespace 'ns': - tkn clustertask create \-\-from foo -or - tkn clustertask create foobar \-\-from=foo - - -.SH SEE ALSO -.PP -\fBtkn\-clustertask(1)\fP diff --git a/docs/man/man1/tkn-clustertask-delete.1 b/docs/man/man1/tkn-clustertask-delete.1 deleted file mode 100644 index d27c7d5156..0000000000 --- a/docs/man/man1/tkn-clustertask-delete.1 +++ /dev/null @@ -1,98 +0,0 @@ -.TH "TKN\-CLUSTERTASK\-DELETE" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask\-delete \- Delete ClusterTasks in a cluster - - -.SH SYNOPSIS -.PP -\fBtkn clustertask delete\fP - - -.SH DESCRIPTION -.PP -Delete ClusterTasks in a cluster - - -.SH OPTIONS -.PP -\fB\-\-all\fP[=false] - Delete all ClusterTasks (default: false) - -.PP -\fB\-\-allow\-missing\-template\-keys\fP[=true] - If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. - -.PP -\fB\-f\fP, \fB\-\-force\fP[=false] - Whether to force deletion (default: false) - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for delete - -.PP -\fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: (json, yaml, name, go\-template, go\-template\-file, template, templatefile, jsonpath, jsonpath\-as\-json, jsonpath\-file). - -.PP -\fB\-\-show\-managed\-fields\fP[=false] - If true, keep the managedFields when printing objects in JSON or YAML format. - -.PP -\fB\-\-template\fP="" - Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. - -.PP -\fB\-\-trs\fP[=false] - Whether to delete ClusterTask(s) and related resources (TaskRuns) (default: false) - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH EXAMPLE -.PP -Delete ClusterTasks with names 'foo' and 'bar': - -.PP -.RS - -.nf -tkn clustertask delete foo bar - -.fi -.RE - -.PP -or - -.PP -.RS - -.nf -tkn ct rm foo bar - -.fi -.RE - - -.SH SEE ALSO -.PP -\fBtkn\-clustertask(1)\fP diff --git a/docs/man/man1/tkn-clustertask-describe.1 b/docs/man/man1/tkn-clustertask-describe.1 deleted file mode 100644 index 9be72c0cb0..0000000000 --- a/docs/man/man1/tkn-clustertask-describe.1 +++ /dev/null @@ -1,86 +0,0 @@ -.TH "TKN\-CLUSTERTASK\-DESCRIBE" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask\-describe \- Describe a ClusterTask - - -.SH SYNOPSIS -.PP -\fBtkn clustertask describe\fP - - -.SH DESCRIPTION -.PP -Describe a ClusterTask - - -.SH OPTIONS -.PP -\fB\-\-allow\-missing\-template\-keys\fP[=true] - If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for describe - -.PP -\fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: (json, yaml, name, go\-template, go\-template\-file, template, templatefile, jsonpath, jsonpath\-as\-json, jsonpath\-file). - -.PP -\fB\-\-show\-managed\-fields\fP[=false] - If true, keep the managedFields when printing objects in JSON or YAML format. - -.PP -\fB\-\-template\fP="" - Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH EXAMPLE -.PP -Describe a ClusterTask of name 'foo': - -.PP -.RS - -.nf -tkn clustertask describe foo - -.fi -.RE - -.PP -or - -.PP -.RS - -.nf -tkn ct desc foo - -.fi -.RE - - -.SH SEE ALSO -.PP -\fBtkn\-clustertask(1)\fP diff --git a/docs/man/man1/tkn-clustertask-list.1 b/docs/man/man1/tkn-clustertask-list.1 deleted file mode 100644 index 1ed72587a3..0000000000 --- a/docs/man/man1/tkn-clustertask-list.1 +++ /dev/null @@ -1,64 +0,0 @@ -.TH "TKN\-CLUSTERTASK\-LIST" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask\-list \- Lists ClusterTasks - - -.SH SYNOPSIS -.PP -\fBtkn clustertask list\fP - - -.SH DESCRIPTION -.PP -Lists ClusterTasks - - -.SH OPTIONS -.PP -\fB\-\-allow\-missing\-template\-keys\fP[=true] - If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for list - -.PP -\fB\-\-no\-headers\fP[=false] - do not print column headers with output (default print column headers with output) - -.PP -\fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: (json, yaml, name, go\-template, go\-template\-file, template, templatefile, jsonpath, jsonpath\-as\-json, jsonpath\-file). - -.PP -\fB\-\-show\-managed\-fields\fP[=false] - If true, keep the managedFields when printing objects in JSON or YAML format. - -.PP -\fB\-\-template\fP="" - Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH SEE ALSO -.PP -\fBtkn\-clustertask(1)\fP diff --git a/docs/man/man1/tkn-clustertask-logs.1 b/docs/man/man1/tkn-clustertask-logs.1 deleted file mode 100644 index 45cb2bb3f8..0000000000 --- a/docs/man/man1/tkn-clustertask-logs.1 +++ /dev/null @@ -1,113 +0,0 @@ -.TH "TKN\-CLUSTERTASK\-LOGS" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask\-logs \- Show ClusterTask logs - - -.SH SYNOPSIS -.PP -\fBtkn clustertask logs\fP - - -.SH DESCRIPTION -.PP -Show ClusterTask logs - - -.SH OPTIONS -.PP -\fB\-a\fP, \fB\-\-all\fP[=false] - show all logs including init steps injected by tekton - -.PP -\fB\-f\fP, \fB\-\-follow\fP[=false] - stream live logs - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for logs - -.PP -\fB\-L\fP, \fB\-\-last\fP[=false] - show logs for last TaskRun - -.PP -\fB\-\-limit\fP=5 - lists number of TaskRuns - -.PP -\fB\-t\fP, \fB\-\-timestamps\fP[=false] - show logs with timestamp - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH EXAMPLE -.PP -Interactive mode: shows logs of the selected TaskRun: - -.PP -.RS - -.nf -tkn clustertask logs \-n namespace - -.fi -.RE - -.PP -Interactive mode: shows logs of the selected TaskRun of the given ClusterTask: - -.PP -.RS - -.nf -tkn clustertask logs clustertask \-n namespace - -.fi -.RE - -.PP -Show logs of given ClusterTask for last TaskRun: - -.PP -.RS - -.nf -tkn clustertask logs clustertask \-n namespace \-\-last - -.fi -.RE - -.PP -Show logs for given ClusterTask and associated TaskRun: - -.PP -.RS - -.nf -tkn clustertask logs clustertask taskrun \-n namespace - -.fi -.RE - - -.SH SEE ALSO -.PP -\fBtkn\-clustertask(1)\fP diff --git a/docs/man/man1/tkn-clustertask-start.1 b/docs/man/man1/tkn-clustertask-start.1 deleted file mode 100644 index 139b91350c..0000000000 --- a/docs/man/man1/tkn-clustertask-start.1 +++ /dev/null @@ -1,169 +0,0 @@ -.TH "TKN\-CLUSTERTASK\-START" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask\-start \- Start ClusterTasks - - -.SH SYNOPSIS -.PP -\fBtkn clustertask start\fP - - -.SH DESCRIPTION -.PP -Start ClusterTasks - - -.SH OPTIONS -.PP -\fB\-\-dry\-run\fP[=false] - preview TaskRun without running it - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for start - -.PP -\fB\-l\fP, \fB\-\-labels\fP=[] - pass labels as label=value. - -.PP -\fB\-L\fP, \fB\-\-last\fP[=false] - re\-run the ClusterTask using last TaskRun values - -.PP -\fB\-\-output\fP="" - format of TaskRun (yaml or json) - -.PP -\fB\-p\fP, \fB\-\-param\fP=[] - pass the param as key=value for string type, or key=value1,value2,... for array type, or key="key1:value1, key2:value2" for object type - -.PP -\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 - -.PP -\fB\-\-showlog\fP[=false] - show logs right after starting the ClusterTask - -.PP -\fB\-\-skip\-optional\-workspace\fP[=false] - skips the prompt for optional workspaces - -.PP -\fB\-\-timeout\fP="" - timeout for TaskRun - -.PP -\fB\-\-use\-param\-defaults\fP[=false] - use default parameter values without prompting for input - -.PP -\fB\-\-use\-taskrun\fP="" - specify a TaskRun name to use its values to re\-run the TaskRun - -.PP -\fB\-w\fP, \fB\-\-workspace\fP=[] - pass one or more workspaces to map to the corresponding physical volumes - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH EXAMPLE -.PP -Start ClusterTask foo by creating a TaskRun named "foo\-run\-xyz123" in namespace 'bar': - -.PP -.RS - -.nf -tkn clustertask start foo \-n bar - -.fi -.RE - -.PP -or - -.PP -.RS - -.nf -tkn ct start foo \-n bar - -.fi -.RE - -.PP -For params value, if you want to provide multiple values, provide them comma separated -like cat,foo,bar - -.PP -For passing the workspaces via flags: - -.RS -.IP \(bu 2 -In case of emptyDir, you can pass it like \-w name=my\-empty\-dir,emptyDir= -.IP \(bu 2 -In case of configMap, you can pass it like \-w name=my\-config,config=rpg,item=ultimav=1 -.IP \(bu 2 -In case of secrets, you can pass it like \-w name=my\-secret,secret=secret\-name -.IP \(bu 2 -In case of pvc, you can pass it like \-w name=my\-pvc,claimName=pvc1 -.IP \(bu 2 -In case of volumeClaimTemplate, you can pass it like \-w name=my\-volume\-claim\-template,volumeClaimTemplateFile=workspace\-template.yaml -but before you need to create a workspace\-template.yaml file. Sample contents of the file are as follows: -spec: -accessModes: - -.RS -.IP \(bu 2 -ReadWriteOnce -resources: -requests: -storage: 1Gi - -.RE -.IP \(bu 2 -In case of binding a CSI workspace, you can pass it like \-w name=my\-csi,csiFile=csi.yaml -but you need to create a csi.yaml file before hand. Sample contents of the file are as follows: - -.br - -.RE - -.PP -driver: secrets\-store.csi.k8s.io - readOnly: true - volumeAttributes: - secretProviderClass: "vault\-database" - - -.SH SEE ALSO -.PP -\fBtkn\-clustertask(1)\fP diff --git a/docs/man/man1/tkn-clustertask.1 b/docs/man/man1/tkn-clustertask.1 deleted file mode 100644 index 2bcf3b8b05..0000000000 --- a/docs/man/man1/tkn-clustertask.1 +++ /dev/null @@ -1,41 +0,0 @@ -.TH "TKN\-CLUSTERTASK" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-clustertask \- Manage ClusterTasks - - -.SH SYNOPSIS -.PP -\fBtkn clustertask\fP - - -.SH DESCRIPTION -.PP -Manage ClusterTasks - - -.SH OPTIONS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for clustertask - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH SEE ALSO -.PP -\fBtkn(1)\fP, \fBtkn\-clustertask\-create(1)\fP, \fBtkn\-clustertask\-delete(1)\fP, \fBtkn\-clustertask\-describe(1)\fP, \fBtkn\-clustertask\-list(1)\fP, \fBtkn\-clustertask\-logs(1)\fP, \fBtkn\-clustertask\-start(1)\fP diff --git a/docs/man/man1/tkn-task-create.1 b/docs/man/man1/tkn-task-create.1 deleted file mode 100644 index df74f6e4ea..0000000000 --- a/docs/man/man1/tkn-task-create.1 +++ /dev/null @@ -1,59 +0,0 @@ -.TH "TKN\-TASK\-CREATE" "1" "" "Auto generated by spf13/cobra" "" -.nh -.ad l - - -.SH NAME -.PP -tkn\-task\-create \- Create a Task from ClusterTask - - -.SH SYNOPSIS -.PP -\fBtkn task create\fP - - -.SH DESCRIPTION -.PP -Create a Task from ClusterTask - - -.SH OPTIONS -.PP -\fB\-\-from\fP="" - Create a ClusterTask from Task in a particular namespace - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for create - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -.PP -\fB\-c\fP, \fB\-\-context\fP="" - name of the kubeconfig context to use (default: kubectl config current\-context) - -.PP -\fB\-k\fP, \fB\-\-kubeconfig\fP="" - kubectl config file (default: $HOME/.kube/config) - -.PP -\fB\-n\fP, \fB\-\-namespace\fP="" - namespace to use (default: from $KUBECONFIG) - -.PP -\fB\-C\fP, \fB\-\-no\-color\fP[=false] - disable coloring (default: false) - - -.SH EXAMPLE -.PP -Create a Task from ClusterTask 'foo' in namespace 'ns': - tkn task create \-\-from foo -or - tkn task create foobar \-\-from=foo \-n ns - - -.SH SEE ALSO -.PP -\fBtkn\-task(1)\fP diff --git a/docs/man/man1/tkn-taskrun-delete.1 b/docs/man/man1/tkn-taskrun-delete.1 index f320f44e2c..87809dc6a9 100644 --- a/docs/man/man1/tkn-taskrun-delete.1 +++ b/docs/man/man1/tkn-taskrun-delete.1 @@ -27,10 +27,6 @@ Delete TaskRuns in a namespace \fB\-\-allow\-missing\-template\-keys\fP[=true] If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. -.PP -\fB\-\-clustertask\fP="" - The name of a ClusterTask whose TaskRuns should be deleted (does not delete the ClusterTask) - .PP \fB\-f\fP, \fB\-\-force\fP[=false] Whether to force deletion (default: false) diff --git a/pkg/clustertask/clustertask.go b/pkg/clustertask/clustertask.go deleted file mode 100644 index 0a68588133..0000000000 --- a/pkg/clustertask/clustertask.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "os" - - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var clustertaskGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "clustertasks"} - -func GetAllClusterTaskNames(gr schema.GroupVersionResource, c *cli.Clients) ([]string, error) { - var clustertasks *v1beta1.ClusterTaskList - if err := actions.ListV1(gr, c, metav1.ListOptions{}, "", &clustertasks); err != nil { - return nil, fmt.Errorf("failed to list clusterTasks: %v", err) - } - - ret := []string{} - for _, item := range clustertasks.Items { - ret = append(ret, item.ObjectMeta.Name) - } - return ret, nil -} - -// TODO: remove as all the function uses are moved to new func -// It will fetch the ClusterTask based on ClusterTask name -func Get(c *cli.Clients, clustertaskname string, opts metav1.GetOptions) (*v1beta1.ClusterTask, error) { - unstructuredCT, err := actions.Get(clustertaskGroupResource, c.Dynamic, c.Tekton.Discovery(), clustertaskname, "", opts) - if err != nil { - return nil, err - } - - var clustertask *v1beta1.ClusterTask - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCT.UnstructuredContent(), &clustertask); err != nil { - fmt.Fprintf(os.Stderr, "failed to get clustertask\n") - return nil, err - } - return clustertask, nil -} - -func Create(c *cli.Clients, ct *v1beta1.ClusterTask, opts metav1.CreateOptions) (*v1beta1.ClusterTask, error) { - object, err := runtime.DefaultUnstructuredConverter.ToUnstructured(ct) - if err != nil { - return nil, err - } - unstructuredCT := &unstructured.Unstructured{ - Object: object, - } - newUnstructuredCT, err := actions.Create(clustertaskGroupResource, c, unstructuredCT, "", opts) - if err != nil { - return nil, err - } - var clusterTask *v1beta1.ClusterTask - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(newUnstructuredCT.UnstructuredContent(), &clusterTask); err != nil { - return nil, err - } - return clusterTask, nil -} diff --git a/pkg/clustertask/clustertask_test.go b/pkg/clustertask/clustertask_test.go deleted file mode 100644 index aa5e7a239a..0000000000 --- a/pkg/clustertask/clustertask_test.go +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "testing" - "time" - - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestClusterTask_GetAllTaskNames(t *testing.T) { - version := "v1beta1" - clock := test.FakeClock() - ctdata := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - // created 5 minutes back - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-5 * time.Minute)}, - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: ctdata, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1CT(ctdata[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - ctdata2 := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - // created 5 minutes back - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-5 * time.Minute)}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask2", - // created 5 minutes back - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-5 * time.Minute)}, - }, - }, - } - cs2, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: ctdata2, - }) - cs2.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - tdc2 := testDynamic.Options{} - dc2, err := tdc2.Client( - cb.UnstructuredV1beta1CT(ctdata2[0], version), - cb.UnstructuredV1beta1CT(ctdata2[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - p2 := &test.Params{Tekton: cs2.Pipeline, Clock: clock, Kube: cs2.Kube, Dynamic: dc2} - - c1, err := p.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - c2, err := p2.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - testParams := []struct { - name string - client *cli.Clients - want []string - }{ - { - name: "Single ClusterTask", - client: c1, - want: []string{"clustertask"}, - }, - { - name: "Multi ClusterTasks", - client: c2, - want: []string{"clustertask", "clustertask2"}, - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - got, err := GetAllClusterTaskNames(clustertaskGroupResource, tp.client) - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, tp.want, got) - }) - } -} - -func TestClusterTask_List(t *testing.T) { - version := "v1beta1" - clock := test.FakeClock() - ctdata := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: ctdata, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1CT(ctdata[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - ctdata2 := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask2", - }, - }, - } - cs2, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: ctdata2, - }) - cs2.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - tdc2 := testDynamic.Options{} - dc2, err := tdc2.Client( - cb.UnstructuredV1beta1CT(ctdata2[0], version), - cb.UnstructuredV1beta1CT(ctdata2[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - p2 := &test.Params{Tekton: cs2.Pipeline, Clock: clock, Kube: cs2.Kube, Dynamic: dc2} - - c1, err := p.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - c2, err := p2.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - testParams := []struct { - name string - client *cli.Clients - want []string - }{ - { - name: "Single clusterTask", - client: c1, - want: []string{"clustertask"}, - }, - { - name: "Multi clusterTasks", - client: c2, - want: []string{"clustertask", "clustertask2"}, - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - var clustertasks *v1beta1.ClusterTaskList - if err := actions.ListV1(clustertaskGroupResource, tp.client, metav1.ListOptions{}, "", &clustertasks); err != nil { - t.Errorf("unexpected Error") - } - - ctnames := []string{} - for _, ct := range clustertasks.Items { - ctnames = append(ctnames, ct.Name) - } - test.AssertOutput(t, tp.want, ctnames) - }) - } -} - -func TestClusterTask_Get(t *testing.T) { - version := "v1beta1" - clock := test.FakeClock() - ctdata := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask2", - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: ctdata, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1CT(ctdata[0], version), - cb.UnstructuredV1beta1CT(ctdata[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - c, err := p.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - var clustertask *v1beta1.ClusterTask - err = actions.GetV1(clustertaskGroupResource, c, "clustertask", "", metav1.GetOptions{}, &clustertask) - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, "clustertask", clustertask.Name) -} - -func TestClusterTask_Create(t *testing.T) { - version := "v1beta1" - clock := test.FakeClock() - ctdata := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client() - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - c, err := p.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - got, err := Create(c, ctdata[0], metav1.CreateOptions{}) - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, "clustertask", got.Name) -} diff --git a/pkg/cmd/bundle/list.go b/pkg/cmd/bundle/list.go index a014312cb8..eaecc8e8c9 100644 --- a/pkg/cmd/bundle/list.go +++ b/pkg/cmd/bundle/list.go @@ -27,7 +27,7 @@ import ( // TODO: Find a more generic way to do this var ( - allowedKinds = []string{"task", "pipeline", "clustertask"} + allowedKinds = []string{"task", "pipeline"} ) func normalizeKind(kind string) string { diff --git a/pkg/cmd/clustertask/clustertask.go b/pkg/cmd/clustertask/clustertask.go deleted file mode 100644 index 761b7162a6..0000000000 --- a/pkg/cmd/clustertask/clustertask.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright © 2019 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/cli/prerun" - "github.com/tektoncd/cli/pkg/flags" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var taskrunGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "taskruns"} -var clustertaskGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "clustertasks"} - -func Command(p cli.Params) *cobra.Command { - cmd := &cobra.Command{ - Use: "clustertask", - Aliases: []string{"ct", "clustertasks"}, - Short: "Manage ClusterTasks", - Annotations: map[string]string{ - "commandType": "main", - }, - PersistentPreRunE: prerun.PersistentPreRunE(p), - } - - flags.AddTektonOptions(cmd) - _ = cmd.PersistentFlags().MarkHidden("namespace") - cmd.AddCommand( - deleteCommand(p), - describeCommand(p), - listCommand(p), - startCommand(p), - logCommand(p), - createCommand(p), - ) - cmd.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return cmd -} diff --git a/pkg/cmd/clustertask/clustertask_test.go b/pkg/cmd/clustertask/clustertask_test.go deleted file mode 100644 index d262cd2897..0000000000 --- a/pkg/cmd/clustertask/clustertask_test.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright © 2019 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "testing" - - "github.com/tektoncd/cli/pkg/test" -) - -const ( - versionB1 = "v1beta1" -) - -func TestClusterTask_invalid(t *testing.T) { - - p := &test.Params{} - - clustertask := Command(p) - out, err := test.ExecuteCommand(clustertask, "foobar") - if err == nil { - t.Errorf("No errors was defined. Output: %s", out) - } -} diff --git a/pkg/cmd/clustertask/create.go b/pkg/cmd/clustertask/create.go deleted file mode 100644 index 0ece868d25..0000000000 --- a/pkg/cmd/clustertask/create.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright © 2021 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "errors" - "fmt" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - ctactions "github.com/tektoncd/cli/pkg/clustertask" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/task" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type createOptions struct { - From string -} - -func createCommand(p cli.Params) *cobra.Command { - opts := &createOptions{} - eg := `Create a ClusterTask from Task 'foo' present in namespace 'ns': - tkn clustertask create --from foo -or - tkn clustertask create foobar --from=foo` - - c := &cobra.Command{ - Use: "create", - ValidArgsFunction: formatted.ParentCompletion, - Short: "Create a ClusterTask from Task", - Example: eg, - Annotations: map[string]string{ - "commandType": "main", - }, - SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { - s := &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - if opts.From == "" { - return errors.New("--from flag not passed") - } - - if len(args) != 0 { - return createClusterTaskFromTask(s, p, args[0], opts.From) - } - return createClusterTaskFromTask(s, p, "", opts.From) - - }, - } - c.Flags().StringVarP(&opts.From, "from", "", "", "Create a ClusterTask from Task in a particular namespace") - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} - -func createClusterTaskFromTask(s *cli.Stream, p cli.Params, ctName, tName string) error { - c, err := p.Clients() - if err != nil { - return err - } - - if ctName == "" { - ctName = tName - } - - ct, _ := ctactions.Get(c, ctName, metav1.GetOptions{}) - - if ct != nil { - return fmt.Errorf(errClusterTaskAlreadyPresent, ctName) - } - - namespace := p.Namespace() - - t, err := task.Get(c, tName, metav1.GetOptions{}, namespace) - if err != nil { - return fmt.Errorf("Task %s does not exist in namespace %s", tName, namespace) - } - - newCT, err := ctactions.Create(c, taskToClusterTask(t, ctName), metav1.CreateOptions{}) - if err != nil { - return err - } - - fmt.Fprintf(s.Out, "ClusterTask %s created from Task %s present in namespace %s\n", newCT.Name, t.Name, namespace) - - return nil -} - -func taskToClusterTask(t *v1beta1.Task, newCTName string) *v1beta1.ClusterTask { - ct := &v1beta1.ClusterTask{} - - // Copy required Metadata from Task to ClusterTask - ct.ObjectMeta = metav1.ObjectMeta{ - Name: newCTName, - Labels: t.Labels, - Annotations: t.Annotations, - OwnerReferences: t.OwnerReferences, - } - ct.TypeMeta = metav1.TypeMeta{ - APIVersion: t.APIVersion, - Kind: "ClusterTask", - } - // Copy the Specs from Task to ClusterTask - ct.Spec = t.Spec - - return ct -} diff --git a/pkg/cmd/clustertask/create_test.go b/pkg/cmd/clustertask/create_test.go deleted file mode 100644 index d88722efce..0000000000 --- a/pkg/cmd/clustertask/create_test.go +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright © 2021 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "testing" - - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestCreate_TaskNotExist(t *testing.T) { - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "t-1", - }, - Spec: v1beta1.TaskSpec{ - Description: "a task", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1T(tasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{Tasks: tasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - p.SetNamespace("default") - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "ct", "--from", "t-1") - if err == nil { - t.Errorf("Expected error got nil") - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: Task t-1 does not exist in namespace default\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate(t *testing.T) { - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "t-1", - Namespace: "default", - }, - Spec: v1beta1.TaskSpec{ - Description: "a task", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1T(tasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{Tasks: tasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - p.SetNamespace("default") - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "ct-1", "--from", "t-1") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nClusterTask ct-1 created from Task t-1 present in namespace default\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate_InNamespace(t *testing.T) { - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "t-1", - Namespace: "ns", - }, - Spec: v1beta1.TaskSpec{ - Description: "a task", - }, - }, - } - - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1T(tasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{Tasks: tasks, Namespaces: namespaces}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "--from", "t-1", "-n", "ns") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nClusterTask t-1 created from Task t-1 present in namespace ns\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate_WithoutFlag(t *testing.T) { - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "t-1", - }, - Spec: v1beta1.TaskSpec{ - Description: "a task", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1T(tasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{Tasks: tasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "ct-1") - if err == nil { - t.Errorf("Expected error got nil") - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: --from flag not passed\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate_taskToClusterTask(t *testing.T) { - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "task-1", - }, - }, - } - ctask := taskToClusterTask(tasks[0], "ctask-1") - test.AssertOutput(t, "ClusterTask", ctask.Kind) -} diff --git a/pkg/cmd/clustertask/delete.go b/pkg/cmd/clustertask/delete.go deleted file mode 100644 index 16b5e2679c..0000000000 --- a/pkg/cmd/clustertask/delete.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright © 2019 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - clustertaskpkg "github.com/tektoncd/cli/pkg/clustertask" - "github.com/tektoncd/cli/pkg/deleter" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/options" - v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "go.uber.org/multierr" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -// ctExists validates that the arguments are valid ClusterTask names -func ctExists(args []string, p cli.Params) ([]string, error) { - - availableCts := make([]string, 0) - c, err := p.Clients() - if err != nil { - return availableCts, err - } - var errorList error - for _, name := range args { - var clustertask *v1beta1.ClusterTask - err := actions.GetV1(clustertaskGroupResource, c, name, "", metav1.GetOptions{}, &clustertask) - if err != nil { - errorList = multierr.Append(errorList, err) - continue - } - availableCts = append(availableCts, name) - } - return availableCts, errorList -} - -func deleteCommand(p cli.Params) *cobra.Command { - opts := &options.DeleteOptions{Resource: "ClusterTask", ForceDelete: false, DeleteAll: false} - f := cliopts.NewPrintFlags("delete") - eg := `Delete ClusterTasks with names 'foo' and 'bar': - - tkn clustertask delete foo bar - -or - - tkn ct rm foo bar -` - - c := &cobra.Command{ - Use: "delete", - Aliases: []string{"rm"}, - Short: "Delete ClusterTasks in a cluster", - Example: eg, - Args: cobra.MinimumNArgs(0), - SilenceUsage: true, - Annotations: map[string]string{ - "commandType": "main", - }, - ValidArgsFunction: formatted.ParentCompletion, - RunE: func(cmd *cobra.Command, args []string) error { - s := &cli.Stream{ - In: cmd.InOrStdin(), - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - availableCts, errs := ctExists(args, p) - if len(availableCts) == 0 && errs != nil { - return errs - } - - if err := opts.CheckOptions(s, availableCts, ""); err != nil { - return err - } - - if err := deleteClusterTasks(opts, s, p, availableCts); err != nil { - return err - } - return errs - }, - } - f.AddFlags(c) - c.Flags().BoolVarP(&opts.ForceDelete, "force", "f", false, "Whether to force deletion (default: false)") - c.Flags().BoolVarP(&opts.DeleteAll, "all", "", false, "Delete all ClusterTasks (default: false)") - c.Flags().BoolVarP(&opts.DeleteRelated, "trs", "", false, "Whether to delete ClusterTask(s) and related resources (TaskRuns) (default: false)") - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} -func deleteClusterTasks(opts *options.DeleteOptions, s *cli.Stream, p cli.Params, ctNames []string) error { - ctGroupResource := schema.GroupVersionResource{Group: "tekton.dev", Resource: "clustertasks"} - trGroupResource := schema.GroupVersionResource{Group: "tekton.dev", Resource: "taskruns"} - - cs, err := p.Clients() - if err != nil { - return fmt.Errorf("Failed to create tekton client") - } - d := deleter.New("ClusterTask", func(taskName string) error { - return actions.Delete(ctGroupResource, cs.Dynamic, cs.Tekton.Discovery(), taskName, "", metav1.DeleteOptions{}) - }) - switch { - case opts.DeleteAll: - cts, err := clustertaskpkg.GetAllClusterTaskNames(clustertaskGroupResource, cs) - if err != nil { - return err - } - d.Delete(cts) - case opts.DeleteRelated: - d.WithRelated("TaskRun", taskRunLister(cs, p), func(taskRunName string) error { - return actions.Delete(trGroupResource, cs.Dynamic, cs.Tekton.Discovery(), taskRunName, p.Namespace(), metav1.DeleteOptions{}) - }) - deletedClusterTaskNames := d.Delete(ctNames) - d.DeleteRelated(deletedClusterTaskNames) - default: - d.Delete(ctNames) - - } - - if !opts.DeleteAll { - d.PrintSuccesses(s) - } else if opts.DeleteAll { - if d.Errors() == nil { - fmt.Fprint(s.Out, "All ClusterTasks deleted\n") - } - } - return d.Errors() -} - -func taskRunLister(cs *cli.Clients, p cli.Params) func(string) ([]string, error) { - return func(taskName string) ([]string, error) { - lOpts := metav1.ListOptions{ - LabelSelector: fmt.Sprintf("tekton.dev/clusterTask=%s", taskName), - } - - var taskRuns *v1.TaskRunList - if err := actions.ListV1(taskrunGroupResource, cs, lOpts, p.Namespace(), &taskRuns); err != nil { - return nil, err - } - var names []string - for _, tr := range taskRuns.Items { - names = append(names, tr.Name) - } - return names, nil - } -} diff --git a/pkg/cmd/clustertask/delete_test.go b/pkg/cmd/clustertask/delete_test.go deleted file mode 100644 index d06cf18137..0000000000 --- a/pkg/cmd/clustertask/delete_test.go +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright © 2019 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "io" - "strings" - "testing" - "time" - - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/dynamic" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func TestClusterTaskDelete(t *testing.T) { - version := "v1beta1" - clock := test.FakeClock() - taskCreated := clock.Now().Add(-1 * time.Minute) - - type clients struct { - pipelineClient test.Clients - dynamicClient dynamic.Interface - } - - clusterTaskData := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tomatoes", - CreationTimestamp: metav1.Time{Time: taskCreated}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tomatoes2", - CreationTimestamp: metav1.Time{Time: taskCreated}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tomatoes3", - CreationTimestamp: metav1.Time{Time: taskCreated}, - }, - }, - } - taskRunData := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "task-run-1", - Labels: map[string]string{"tekton.dev/clusterTask": "tomatoes"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "tomatoes", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "task-run-2", - Labels: map[string]string{"tekton.dev/clusterTask": "tomatoes"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "tomatoes", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - // NamespacedTask (Task) is provided in the TaskRef of TaskRun, so as to - // verify TaskRun created by Task is not getting deleted while deleting - // ClusterTask with `--trs` flag and name of Task and ClusterTask is same. - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "task-run-3", - Labels: map[string]string{"tekton.dev/task": "tomatoes"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "tomatoes", - Kind: v1beta1.NamespacedTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - } - - seeds := make([]clients, 0) - for i := 0; i < 6; i++ { - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: clusterTaskData, - TaskRuns: taskRunData, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1CT(clusterTaskData[0], version), - cb.UnstructuredV1beta1CT(clusterTaskData[1], version), - cb.UnstructuredV1beta1CT(clusterTaskData[2], version), - cb.UnstructuredV1beta1TR(taskRunData[0], version), - cb.UnstructuredV1beta1TR(taskRunData[1], version), - cb.UnstructuredV1beta1TR(taskRunData[2], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - seeds = append(seeds, clients{cs, dc}) - } - - testParams := []struct { - name string - command []string - dynamic dynamic.Interface - input test.Clients - inputStream io.Reader - wantError bool - want string - }{ - { - name: "With force delete flag (shorthand)", - command: []string{"rm", "tomatoes", "-f"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nClusterTasks deleted: \"tomatoes\"\n", - }, - { - name: "With force delete flag", - command: []string{"rm", "tomatoes", "--force"}, - dynamic: seeds[1].dynamicClient, - input: seeds[1].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nClusterTasks deleted: \"tomatoes\"\n", - }, - { - name: "Without force delete flag, reply no", - command: []string{"rm", "tomatoes"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: strings.NewReader("n"), - wantError: true, - want: "canceled deleting ClusterTask(s) \"tomatoes\"", - }, - { - name: "Without force delete flag, reply yes", - command: []string{"rm", "tomatoes"}, - dynamic: seeds[3].dynamicClient, - input: seeds[3].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nAre you sure you want to delete ClusterTask(s) \"tomatoes\" (y/n): ClusterTasks deleted: \"tomatoes\"\n", - }, - { - name: "Remove non existent resource", - command: []string{"rm", "nonexistent"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "clustertasks.tekton.dev \"nonexistent\" not found", - }, - { - name: "Remove multiple non existent resources", - command: []string{"rm", "nonexistent", "nonexistent2", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "clustertasks.tekton.dev \"nonexistent\" not found; clustertasks.tekton.dev \"nonexistent2\" not found", - }, - { - name: "Remove multiple non existent resources with --trs flag", - command: []string{"rm", "nonexistent", "nonexistent2", "-n", "ns", "--trs"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "clustertasks.tekton.dev \"nonexistent\" not found; clustertasks.tekton.dev \"nonexistent2\" not found", - }, - { - name: "With delete taskrun(s) flag, reply yes", - command: []string{"rm", "tomatoes", "-n", "ns", "--trs"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nAre you sure you want to delete ClusterTask(s) \"tomatoes\" and related resources (y/n): TaskRuns deleted: \"task-run-1\", \"task-run-2\"\nClusterTasks deleted: \"tomatoes\"\n", - }, - { - name: "With force delete flag, reply yes, multiple clustertasks", - command: []string{"rm", "tomatoes2", "tomatoes3", "-f"}, - dynamic: seeds[1].dynamicClient, - input: seeds[1].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nClusterTasks deleted: \"tomatoes2\", \"tomatoes3\"\n", - }, - { - name: "Without force delete flag, reply yes, multiple clustertasks", - command: []string{"rm", "tomatoes2", "tomatoes3"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nAre you sure you want to delete ClusterTask(s) \"tomatoes2\", \"tomatoes3\" (y/n): ClusterTasks deleted: \"tomatoes2\", \"tomatoes3\"\n", - }, - { - name: "Delete all with prompt", - command: []string{"delete", "--all"}, - dynamic: seeds[3].dynamicClient, - input: seeds[3].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nAre you sure you want to delete all ClusterTasks (y/n): All ClusterTasks deleted\n", - }, - { - name: "Delete all with -f", - command: []string{"delete", "--all", "-f"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nAll ClusterTasks deleted\n", - }, - { - name: "Error from using clustertask name with --all", - command: []string{"delete", "tomatoes2", "--all"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "--all flag should not have any arguments or flags specified with it", - }, - { - name: "Error from using clustertask delete with no names or --all", - command: []string{"delete"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: true, - want: "must provide ClusterTask name(s) or use --all flag with delete", - }, - { - name: "Delete the ClusterTask present and give error for non-existent ClusterTask", - command: []string{"delete", "nonexistent", "tomatoes2"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "clustertasks.tekton.dev \"nonexistent\" not found", - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - p := &test.Params{Tekton: tp.input.Pipeline, Dynamic: tp.dynamic} - clustertask := Command(p) - - if tp.inputStream != nil { - clustertask.SetIn(tp.inputStream) - } - - out, err := test.ExecuteCommand(clustertask, tp.command...) - if tp.wantError { - if err == nil { - t.Errorf("Error expected here") - } - test.AssertOutput(t, tp.want, err.Error()) - } else { - if err != nil { - t.Errorf("Unexpected Error") - } - test.AssertOutput(t, tp.want, out) - } - }) - } -} diff --git a/pkg/cmd/clustertask/describe.go b/pkg/cmd/clustertask/describe.go deleted file mode 100644 index 5b855ed5fe..0000000000 --- a/pkg/cmd/clustertask/describe.go +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "text/tabwriter" - "text/template" - - "github.com/jonboulle/clockwork" - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - clustertaskpkg "github.com/tektoncd/cli/pkg/clustertask" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/options" - trsort "github.com/tektoncd/cli/pkg/taskrun/sort" - v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -const describeTemplate = `{{decorate "bold" "Name"}}: {{ .ClusterTask.Name }} -{{- if ne .ClusterTask.Spec.Description "" }} -{{decorate "bold" "Description"}}: {{ .ClusterTask.Spec.Description }} -{{- end }} -{{- $annotations := removeLastAppliedConfig .ClusterTask.Annotations -}} -{{- if $annotations }} -{{decorate "bold" "Annotations"}}: -{{- range $k, $v := $annotations }} - {{ $k }}={{ $v }} -{{- end }} -{{- end }} - -{{- if ne (len .ClusterTask.Spec.Params) 0 }} - -{{decorate "params" ""}}{{decorate "underline bold" "Params\n"}} - NAME TYPE DESCRIPTION DEFAULT VALUE -{{- range $p := .ClusterTask.Spec.Params }} -{{- if not $p.Default }} - {{decorate "bullet" $p.Name }} {{ $p.Type }} {{ formatDesc $p.Description }} {{ "---" }} -{{- else }} -{{- if eq $p.Type "string" }} - {{decorate "bullet" $p.Name }} {{ $p.Type }} {{ formatDesc $p.Description }} {{ $p.Default.StringVal }} -{{- else if eq $p.Type "array" }} - {{decorate "bullet" $p.Name }} {{ $p.Type }} {{ formatDesc $p.Description }} {{ $p.Default.ArrayVal }} -{{- else }} - {{decorate "bullet" $p.Name }} {{ $p.Type }} {{ formatDesc $p.Description }} {{ $p.Default.ObjectVal }} -{{- end }} -{{- end }} -{{- end }} -{{- end }} - -{{- if ne (len .ClusterTask.Spec.Results) 0 }} - -{{decorate "results" ""}}{{decorate "underline bold" "Results\n"}} - NAME DESCRIPTION -{{- range $result := .ClusterTask.Spec.Results }} - {{ decorate "bullet" $result.Name }} {{ formatDesc $result.Description }} -{{- end }} -{{- end }} - -{{- if ne (len .ClusterTask.Spec.Workspaces) 0 }} - -{{decorate "workspaces" ""}}{{decorate "underline bold" "Workspaces\n"}} - NAME DESCRIPTION -{{- range $workspace := .ClusterTask.Spec.Workspaces }} - {{ decorate "bullet" $workspace.Name }} {{ formatDesc $workspace.Description }} -{{- end }} -{{- end }} - -{{- if ne (len .ClusterTask.Spec.Steps) 0 }} - -{{decorate "steps" ""}}{{decorate "underline bold" "Steps\n"}} -{{- range $step := .ClusterTask.Spec.Steps }} - {{ autoStepName $step.Name | decorate "bullet" }} -{{- end }} -{{- end }} - -{{- if ne (len .TaskRuns.Items) 0 }} - -{{decorate "taskruns" ""}}{{decorate "underline bold" "Taskruns\n"}} -NAME STARTED DURATION STATUS -{{ range $tr:=.TaskRuns.Items }} -{{- $tr.Name }} {{ formatAge $tr.Status.StartTime $.Time}} {{ formatDuration $tr.Status.StartTime $tr.Status.CompletionTime }} {{ formatCondition $tr.Status.Conditions }} -{{ end }} -{{- end }} -` - -func describeCommand(p cli.Params) *cobra.Command { - f := cliopts.NewPrintFlags("describe") - opts := &options.DescribeOptions{Params: p} - eg := `Describe a ClusterTask of name 'foo': - - tkn clustertask describe foo - -or - - tkn ct desc foo -` - - c := &cobra.Command{ - Use: "describe", - Aliases: []string{"desc"}, - Short: "Describe a ClusterTask", - Example: eg, - Annotations: map[string]string{ - "commandType": "main", - }, - SilenceUsage: true, - ValidArgsFunction: formatted.ParentCompletion, - RunE: func(cmd *cobra.Command, args []string) error { - s := &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - output, err := cmd.LocalFlags().GetString("output") - if err != nil { - return fmt.Errorf("output option not set properly: %v", err) - } - - cs, err := p.Clients() - if err != nil { - return err - } - - if len(args) == 0 { - clusterTaskNames, err := clustertaskpkg.GetAllClusterTaskNames(clustertaskGroupResource, cs) - if err != nil { - return err - } - if len(clusterTaskNames) == 1 { - opts.ClusterTaskName = clusterTaskNames[0] - } else { - err = askClusterTaskName(opts, clusterTaskNames) - if err != nil { - return err - } - } - } else { - opts.ClusterTaskName = args[0] - } - - if output != "" { - p, err := f.ToPrinter() - if err != nil { - return err - } - return actions.PrintObjectV1(clustertaskGroupResource, opts.ClusterTaskName, cmd.OutOrStdout(), cs, p, "") - } - - return printClusterTaskDescription(s, cs, opts.ClusterTaskName, p.Namespace(), p.Time()) - }, - } - - f.AddFlags(c) - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} - -func printClusterTaskDescription(s *cli.Stream, cs *cli.Clients, ctname, namespace string, time clockwork.Clock) error { - var clustertask *v1beta1.ClusterTask - err := actions.GetV1(clustertaskGroupResource, cs, ctname, "", metav1.GetOptions{}, &clustertask) - if err != nil { - return fmt.Errorf("failed to get ClusterTask %s", ctname) - } - - opts := metav1.ListOptions{ - LabelSelector: fmt.Sprintf("tekton.dev/clusterTask=%s", ctname), - } - - var taskRuns *v1.TaskRunList - if err := actions.ListV1(taskrunGroupResource, cs, opts, namespace, &taskRuns); err != nil { - return fmt.Errorf("failed to get TaskRuns for ClusterTask %s", ctname) - } - - trsort.SortByStartTime(taskRuns.Items) - - var data = struct { - ClusterTask *v1beta1.ClusterTask - TaskRuns *v1.TaskRunList - Time clockwork.Clock - }{ - ClusterTask: clustertask, - TaskRuns: taskRuns, - Time: time, - } - - funcMap := template.FuncMap{ - "formatAge": formatted.Age, - "formatDuration": formatted.Duration, - "formatCondition": formatted.Condition, - "decorate": formatted.DecorateAttr, - "autoStepName": formatted.AutoStepName, - "formatDesc": formatted.FormatDesc, - "removeLastAppliedConfig": formatted.RemoveLastAppliedConfig, - } - - w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent) - t := template.Must(template.New("Describe ClusterTask").Funcs(funcMap).Parse(describeTemplate)) - err = t.Execute(w, data) - if err != nil { - return fmt.Errorf("failed to execute template") - } - return w.Flush() -} - -func askClusterTaskName(opts *options.DescribeOptions, clusterTaskNames []string) error { - if len(clusterTaskNames) == 0 { - return fmt.Errorf("no ClusterTasks found") - } - err := opts.Ask(options.ResourceNameClusterTask, clusterTaskNames) - if err != nil { - return err - } - - return nil -} diff --git a/pkg/cmd/clustertask/describe_test.go b/pkg/cmd/clustertask/describe_test.go deleted file mode 100644 index 05be2b7858..0000000000 --- a/pkg/cmd/clustertask/describe_test.go +++ /dev/null @@ -1,639 +0,0 @@ -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "errors" - "fmt" - "io" - "strings" - "testing" - "time" - - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "gotest.tools/v3/golden" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - k8stest "k8s.io/client-go/testing" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func Test_ClusterTaskDescribe(t *testing.T) { - clock := test.FakeClock() - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-full", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "myarg", - Type: v1beta1.ParamTypeString, - Description: "param type is string", - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, - StringVal: "default", - }, - }, - { - Name: "print", - Type: v1beta1.ParamTypeArray, - Description: "param type is array", - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"booms", "booms", "booms"}, - }, - }, - }, - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - { - Name: "exit", - Image: "busybox", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-one-everything", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Description: "a test description", - Params: []v1beta1.ParamSpec{ - { - Name: "myarg", - Type: v1beta1.ParamTypeString, - }, - }, - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-justname", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - }, - } - - taskruns := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-1", - Namespace: "ns", - Labels: map[string]string{ - "tekton.dev/clusterTask": "clustertask-full", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "clustertask-full", - Kind: v1beta1.ClusterTaskKind, - }, - ServiceAccountName: "svc", - Params: []v1beta1.Param{ - { - Name: "myarg", - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, - StringVal: "value", - }, - }, - { - Name: "print", - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"booms", "booms", "booms"}, - }, - }, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(17 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-2", - Namespace: "ns", - Labels: map[string]string{ - "tekton.dev/clusterTask": "clustertask-one-everything", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "clustertask-one-everything", - Kind: v1beta1.ClusterTaskKind, - }, - ServiceAccountName: "svc", - Params: []v1beta1.Param{ - { - Name: "myarg", - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, - StringVal: "value", - }, - }, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(17 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-3", - Namespace: "ns", - Labels: map[string]string{ - "tekton.dev/clusterTask": "clustertask-full", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "clustertask-full", - Kind: v1beta1.ClusterTaskKind, - }, - ServiceAccountName: "svc", - Params: []v1beta1.Param{ - { - Name: "myarg", - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, - StringVal: "value", - }, - }, - { - Name: "print", - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"booms", "booms", "booms"}, - }, - }, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: v1beta1.TaskRunReasonRunning.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(-12 * time.Minute)}, - }, - }, - }, - } - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - cb.UnstructuredV1beta1CT(clustertasks[1], version), - cb.UnstructuredV1beta1CT(clustertasks[2], version), - cb.UnstructuredV1beta1TR(taskruns[0], version), - cb.UnstructuredV1beta1TR(taskruns[1], version), - cb.UnstructuredV1beta1TR(taskruns[2], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks, Namespaces: ns, TaskRuns: taskruns}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} - p.SetNamespace("ns") - - tdc2 := testDynamic.Options{ - PrependReactors: []testDynamic.PrependOpt{{ - Verb: "list", - Resource: "taskruns", - Action: func(_ k8stest.Action) (bool, runtime.Object, error) { - return true, nil, errors.New("fake list taskrun error") - }}}} - dynamic2, err := tdc2.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - cb.UnstructuredV1beta1CT(clustertasks[1], version), - cb.UnstructuredV1beta1CT(clustertasks[2], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - cs2, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks, Namespaces: ns}) - cs2.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p2 := &test.Params{Tekton: cs2.Pipeline, Kube: cs2.Kube, Dynamic: dynamic2, Clock: clock} - p2.SetNamespace("ns") - - testParams := []struct { - name string - command []string - param *test.Params - inputStream io.Reader - wantError bool - }{ - { - name: "Describe with no arguments", - command: []string{"describe", "notexist"}, - param: p, - inputStream: nil, - wantError: true, - }, - { - name: "Describe clustertask with name only", - command: []string{"describe", "clustertask-justname"}, - param: p, - inputStream: nil, - wantError: false, - }, - { - name: "Describe full clustertask multiple taskruns", - command: []string{"describe", "clustertask-full"}, - param: p, - inputStream: nil, - wantError: false, - }, - { - name: "Describe clustertask missing param default one of everything", - command: []string{"describe", "clustertask-one-everything"}, - param: p, - inputStream: nil, - wantError: false, - }, - { - name: "Failure from listing taskruns", - command: []string{"describe", "clustertask-full"}, - param: p2, - inputStream: nil, - wantError: true, - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - clustertask := Command(tp.param) - - if tp.inputStream != nil { - clustertask.SetIn(tp.inputStream) - } - - got, err := test.ExecuteCommand(clustertask, tp.command...) - if tp.wantError { - if err == nil { - t.Errorf("Error expected here") - } - } else { - if err != nil { - t.Errorf("Unexpected error") - } - golden.Assert(t, got, strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-")) - } - }) - } -} - -func TestClusterTaskDescribe_WithoutNameIfOnlyOneClusterTaskPresent(t *testing.T) { - cstasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "task-1", - }, - }, - } - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(cstasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: cstasks}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - clusterTask := Command(p) - out, err := test.ExecuteCommand(clusterTask, "desc") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestClusterTask_custom_output(t *testing.T) { - name := "clustertask" - expected := "Command \"describe\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nclustertask.tekton.dev/" + name - - clock := test.FakeClock() - - cstasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: cstasks, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "", - }, - }, - }, - }) - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(cstasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} - clustertask := Command(p) - got, err := test.ExecuteCommand(clustertask, "desc", "-o", "name", name) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - got = strings.TrimSpace(got) - if got != expected { - t.Errorf("Result should be '%s' != '%s'", got, expected) - } -} - -func TestClusterTaskV1beta1_custom_output(t *testing.T) { - name := "clustertask" - expected := "Command \"describe\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nclustertask.tekton.dev/" + name - - clock := test.FakeClock() - - cstasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{Name: name}, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: cstasks, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "", - }, - }, - }, - }) - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(cstasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} - clustertask := Command(p) - got, err := test.ExecuteCommand(clustertask, "desc", "-o", "name", name) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - got = strings.TrimSpace(got) - if got != expected { - t.Errorf("Result should be '%s' != '%s'", got, expected) - } -} - -func TestClusterTaskDescribe_With_Results(t *testing.T) { - clock := test.FakeClock() - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-1", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertest description", - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - }, - Results: []v1beta1.TaskResult{ - { - Name: "result-1", - Description: "This is a description for result 1", - }, - { - Name: "result-2", - Description: "This is a description for result 2", - }, - { - Name: "result-3", - }, - }, - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dynamic} - clustertask := Command(p) - out, err := test.ExecuteCommand(clustertask, "desc", "clustertask-1") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestClusterTaskDescribe_With_Workspaces(t *testing.T) { - clock := test.FakeClock() - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-1", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertest description", - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - }, - Workspaces: []v1beta1.WorkspaceDeclaration{ - { - Name: "test", - Description: "test workspace", - MountPath: "/workspace/test/file", - ReadOnly: true, - }, - }, - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dynamic} - clustertask := Command(p) - out, err := test.ExecuteCommand(clustertask, "desc", "clustertask-1") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestClusterTaskDescribe_WithoutNameIfOnlyOneV1beta1ClusterTaskPresent(t *testing.T) { - cttasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "task-1", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(cttasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: cttasks}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - cttask := Command(p) - out, err := test.ExecuteCommand(cttask, "desc") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestClusterTaskDescribe_with_annotations(t *testing.T) { - cttasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-1", - Annotations: map[string]string{ - corev1.LastAppliedConfigAnnotation: "LastAppliedConfig", - "tekton.dev/tags": "testing", - }, - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(cttasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: cttasks}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - cttask := Command(p) - out, err := test.ExecuteCommand(cttask, "desc") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} diff --git a/pkg/cmd/clustertask/list.go b/pkg/cmd/clustertask/list.go deleted file mode 100644 index a171ec38ff..0000000000 --- a/pkg/cmd/clustertask/list.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright © 2019 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "text/tabwriter" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -const ( - emptyMsg = "No ClusterTasks found\n" - body = "%s\t%s\t%s\n" - header = "NAME\tDESCRIPTION\tAGE" -) - -type listOptions struct { - NoHeaders bool -} - -func listCommand(p cli.Params) *cobra.Command { - opts := &listOptions{} - f := cliopts.NewPrintFlags("list") - - c := &cobra.Command{ - Use: "list", - Aliases: []string{"ls"}, - Short: "Lists ClusterTasks", - Annotations: map[string]string{ - "commandType": "main", - }, - RunE: func(cmd *cobra.Command, _ []string) error { - - output, err := cmd.LocalFlags().GetString("output") - if err != nil { - return fmt.Errorf("output option not set properly: %v", err) - } - - cs, err := p.Clients() - if err != nil { - return err - } - - if output != "" { - ctGroupResource := schema.GroupVersionResource{Group: "tekton.dev", Resource: "clustertasks"} - p, err := f.ToPrinter() - if err != nil { - return err - } - return actions.PrintObjects(ctGroupResource, cmd.OutOrStdout(), cs.Dynamic, cs.Tekton.Discovery(), p, "") - } - stream := &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - return printClusterTaskDetails(stream, p, opts.NoHeaders) - }, - } - f.AddFlags(c) - c.Flags().BoolVar(&opts.NoHeaders, "no-headers", opts.NoHeaders, "do not print column headers with output (default print column headers with output)") - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} - -func printClusterTaskDetails(s *cli.Stream, p cli.Params, noHeaders bool) error { - cs, err := p.Clients() - if err != nil { - return err - } - - var clustertasks *v1beta1.ClusterTaskList - err = actions.ListV1(clustertaskGroupResource, cs, metav1.ListOptions{}, "", &clustertasks) - if err != nil { - return fmt.Errorf("failed to list ClusterTasks") - } - - if len(clustertasks.Items) == 0 { - fmt.Fprint(s.Out, emptyMsg) - return nil - } - - w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent) - - if !noHeaders { - fmt.Fprintln(w, header) - } - - clusterTaskItems := clustertasks.Items - - for idx := range clusterTaskItems { - fmt.Fprintf(w, body, - clusterTaskItems[idx].Name, - formatted.FormatDesc(clusterTaskItems[idx].Spec.Description), - formatted.Age(&clusterTaskItems[idx].CreationTimestamp, p.Time()), - ) - } - return w.Flush() -} diff --git a/pkg/cmd/clustertask/list_test.go b/pkg/cmd/clustertask/list_test.go deleted file mode 100644 index dbc7b24562..0000000000 --- a/pkg/cmd/clustertask/list_test.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright © 2019 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "testing" - "time" - - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "gotest.tools/v3/golden" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestClusterTaskList_Empty(t *testing.T) { - cs, _ := test.SeedV1beta1TestData(t, test.Data{}) - cs.Pipeline.Resources = cb.APIResourceList("v1beta1", []string{"clustertask"}) - tdc := testDynamic.Options{} - dynamic, err := tdc.Client() - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dynamic} - clustertask := Command(p) - - output, err := test.ExecuteCommand(clustertask, "list") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - warning := "Command \"list\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" - test.AssertOutput(t, warning+emptyMsg, output) -} - -func TestClusterTaskListOnlyClusterTasksv1beta1(t *testing.T) { - clock := test.FakeClock() - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "guavas", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "avocados", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-20 * time.Second)}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pineapple", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-512 * time.Hour)}, - }, - Spec: v1beta1.TaskSpec{ - Description: "a test clustertask", - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "apple", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-513 * time.Hour)}, - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertask to test description", - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "mango", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-514 * time.Hour)}, - }, - Spec: v1beta1.TaskSpec{ - Description: "", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - cb.UnstructuredV1beta1CT(clustertasks[1], version), - cb.UnstructuredV1beta1CT(clustertasks[2], version), - cb.UnstructuredV1beta1CT(clustertasks[3], version), - cb.UnstructuredV1beta1CT(clustertasks[4], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Clock: clock, Dynamic: dynamic} - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - - clustertask := Command(p) - output, err := test.ExecuteCommand(clustertask, "list") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, output, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestClusterTaskListNoHeadersv1beta1(t *testing.T) { - clock := test.FakeClock() - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "guavas", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "avocados", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-20 * time.Second)}, - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - cb.UnstructuredV1beta1CT(clustertasks[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Clock: clock, Dynamic: dynamic} - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"}) - - clustertask := Command(p) - output, err := test.ExecuteCommand(clustertask, "list", "--no-headers") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, output, fmt.Sprintf("%s.golden", t.Name())) -} diff --git a/pkg/cmd/clustertask/logs.go b/pkg/cmd/clustertask/logs.go deleted file mode 100644 index bd87b3c504..0000000000 --- a/pkg/cmd/clustertask/logs.go +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright © 2021 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/clustertask" - "github.com/tektoncd/cli/pkg/cmd/taskrun" - "github.com/tektoncd/cli/pkg/flags" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/options" - "github.com/tektoncd/cli/pkg/task" - taskrunpkg "github.com/tektoncd/cli/pkg/taskrun" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func nameArg(args []string, p cli.Params) error { - if len(args) == 1 { - c, err := p.Clients() - if err != nil { - return err - } - name := args[0] - var clustertask *v1beta1.ClusterTask - if err = actions.GetV1(clustertaskGroupResource, c, name, "", metav1.GetOptions{}, &clustertask); err != nil { - return err - } - } - return nil -} - -func logCommand(p cli.Params) *cobra.Command { - opts := options.NewLogOptions(p) - - eg := `Interactive mode: shows logs of the selected TaskRun: - - tkn clustertask logs -n namespace - -Interactive mode: shows logs of the selected TaskRun of the given ClusterTask: - - tkn clustertask logs clustertask -n namespace - -Show logs of given ClusterTask for last TaskRun: - - tkn clustertask logs clustertask -n namespace --last - -Show logs for given ClusterTask and associated TaskRun: - - tkn clustertask logs clustertask taskrun -n namespace -` - c := &cobra.Command{ - Use: "logs", - DisableFlagsInUseLine: true, - Short: "Show ClusterTask logs", - Example: eg, - SilenceUsage: true, - ValidArgsFunction: formatted.ParentCompletion, - Annotations: map[string]string{ - "commandType": "main", - }, - - Args: func(cmd *cobra.Command, args []string) error { - if err := flags.InitParams(p, cmd); err != nil { - return err - } - return nameArg(args, p) - }, - RunE: func(cmd *cobra.Command, args []string) error { - opts.Stream = &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - return run(opts, args) - }, - } - c.Flags().BoolVarP(&opts.Last, "last", "L", false, "show logs for last TaskRun") - c.Flags().BoolVarP(&opts.AllSteps, "all", "a", false, "show all logs including init steps injected by tekton") - c.Flags().BoolVarP(&opts.Follow, "follow", "f", false, "stream live logs") - c.Flags().BoolVarP(&opts.Timestamps, "timestamps", "t", false, "show logs with timestamp") - c.Flags().IntVarP(&opts.Limit, "limit", "", 5, "lists number of TaskRuns") - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} - -func run(opts *options.LogOptions, args []string) error { - if err := initOpts(opts, args); err != nil { - return err - } - - if opts.ClusterTaskName == "" || opts.TaskrunName == "" { - return nil - } - - return taskrun.Run(opts) -} - -func initOpts(opts *options.LogOptions, args []string) error { - // ensure the client is properly initialized - if _, err := opts.Params.Clients(); err != nil { - return err - } - - if err := opts.ValidateOpts(); err != nil { - return err - } - - switch len(args) { - case 0: // no inputs - return getAllInputs(opts) - - case 1: // clustertask name provided - opts.ClusterTaskName = args[0] - return askRunName(opts) - - case 2: // both clustertask and run provided - opts.ClusterTaskName = args[0] - opts.TaskrunName = args[1] - - default: - return fmt.Errorf("too many arguments") - } - return nil -} - -func getAllInputs(opts *options.LogOptions) error { - cs, err := opts.Params.Clients() - if err != nil { - return err - } - - cts, err := clustertask.GetAllClusterTaskNames(clustertaskGroupResource, cs) - if err != nil { - return err - } - - if len(cts) == 0 { - return fmt.Errorf("no ClusterTasks found") - } - - if len(cts) == 1 { - opts.ClusterTaskName = strings.Fields(cts[0])[0] - } else if err := opts.Ask(options.ResourceNameClusterTask, cts); err != nil { - return err - } - - return askRunName(opts) -} - -func askRunName(opts *options.LogOptions) error { - cs, err := opts.Params.Clients() - if err != nil { - return err - } - - if opts.Last { - name, err := initLastRunName(cs, opts.ClusterTaskName, opts.Params.Namespace()) - if err != nil { - return err - } - opts.TaskrunName = name - return nil - } - - lOpts := metav1.ListOptions{ - LabelSelector: fmt.Sprintf("tekton.dev/clusterTask=%s", opts.ClusterTaskName), - } - - trs, err := taskrunpkg.GetAllTaskRuns(taskrunGroupResource, lOpts, cs, opts.Params.Namespace(), opts.Limit, opts.Params.Time()) - if err != nil { - return err - } - - if len(trs) == 0 { - return fmt.Errorf("no TaskRuns found for ClusterTask %s", opts.ClusterTaskName) - } - - if len(trs) == 1 { - opts.TaskrunName = strings.Fields(trs[0])[0] - return nil - } - - return opts.Ask(options.ResourceNameTaskRun, trs) -} - -func initLastRunName(cs *cli.Clients, name, namespace string) (string, error) { - lastrun, err := task.LastRun(cs, name, namespace, "ClusterTask") - if err != nil { - return "", err - } - return lastrun.Name, nil -} diff --git a/pkg/cmd/clustertask/logs_test.go b/pkg/cmd/clustertask/logs_test.go deleted file mode 100644 index 491917f60a..0000000000 --- a/pkg/cmd/clustertask/logs_test.go +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright © 2021 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "testing" - "time" - - "github.com/AlecAivazis/survey/v2/core" - "github.com/tektoncd/cli/pkg/options" - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/dynamic" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func init() { - // disable color output for all prompts to simplify testing - core.DisableColor = true -} - -func TestClusterTaskLog(t *testing.T) { - clock := test.FakeClock() - clustertask1 := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "task", - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: clustertask1, - }) - cs.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"clustertask", "taskrun"}) - tdc1 := testDynamic.Options{} - dc1, err := tdc1.Client( - cb.UnstructuredV1beta1CT(clustertask1[0], versionB1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - testParams := []struct { - name string - command []string - input test.Clients - dc dynamic.Interface - wantError bool - want string - }{ - { - name: "Found no taskruns", - command: []string{"logs", "task", "-n", "ns"}, - input: cs, - dc: dc1, - wantError: true, - want: "Command \"logs\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: no TaskRuns found for ClusterTask task\n", - }, - { - name: "Specify notexist task name", - command: []string{"logs", "notexist", "-n", "ns"}, - input: cs, - dc: dc1, - wantError: true, - want: "Command \"logs\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: clustertasks.tekton.dev \"notexist\" not found\n", - }, - { - name: "Specify notexist taskrun name", - command: []string{"logs", "task", "notexist", "-n", "ns"}, - input: cs, - dc: dc1, - wantError: true, - want: "Command \"logs\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: Unable to get TaskRun: taskruns.tekton.dev \"notexist\" not found\n", - }, - { - name: "Specify negative number to limit", - command: []string{"logs", "task", "-n", "ns", "--limit", "-1"}, - input: cs, - dc: dc1, - wantError: true, - want: "Command \"logs\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: limit was -1 but must be a positive number\n", - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - p := &test.Params{Tekton: tp.input.Pipeline, Clock: clock, Kube: tp.input.Kube, Dynamic: tp.dc} - c := Command(p) - - out, err := test.ExecuteCommand(c, tp.command...) - if tp.wantError { - if err == nil { - t.Errorf("error expected here") - } - test.AssertOutput(t, tp.want, out) - } else { - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, tp.want, out) - } - }) - } -} - -func TestLogs_Auto_Select_FirstClusterTask(t *testing.T) { - taskName := "dummyTask" - ns := "dummyNamespaces" - clock := test.FakeClock() - - ctdata := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: taskName, - }, - }, - } - - trdata := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: ns, - Name: "dummyTR", - Labels: map[string]string{"tekton.dev/clusterTask": taskName}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(-5 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - }, - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - ClusterTasks: ctdata, - TaskRuns: trdata, - }) - cs.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"clustertask", "taskrun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1CT(ctdata[0], versionB1), - cb.UnstructuredV1beta1TR(trdata[0], versionB1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := test.Params{ - Kube: cs.Kube, - Tekton: cs.Pipeline, - Dynamic: dc, - } - p.SetNamespace(ns) - - lopt := &options.LogOptions{ - Params: &p, - Follow: false, - Limit: 5, - } - err = getAllInputs(lopt) - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if lopt.ClusterTaskName != taskName { - t.Error("No auto selection of the first ClusterTask when we have only one") - } -} diff --git a/pkg/cmd/clustertask/start.go b/pkg/cmd/clustertask/start.go deleted file mode 100644 index ba4c76071e..0000000000 --- a/pkg/cmd/clustertask/start.go +++ /dev/null @@ -1,402 +0,0 @@ -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "os" - "strings" - "time" - - "github.com/AlecAivazis/survey/v2" - "github.com/AlecAivazis/survey/v2/terminal" - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/cmd/taskrun" - "github.com/tektoncd/cli/pkg/file" - "github.com/tektoncd/cli/pkg/flags" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/labels" - "github.com/tektoncd/cli/pkg/options" - "github.com/tektoncd/cli/pkg/params" - "github.com/tektoncd/cli/pkg/pods" - tractions "github.com/tektoncd/cli/pkg/taskrun" - "github.com/tektoncd/cli/pkg/workspaces" - v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/yaml" -) - -var ( - errNoClusterTask = errors.New("missing ClusterTask name") - errInvalidClusterTask = "ClusterTask name %s does not exist" - errClusterTaskAlreadyPresent = "ClusterTask with name %s already exists" -) - -type startOptions struct { - cliparams cli.Params - stream *cli.Stream - Params []string - ServiceAccountName string - Last bool - Labels []string - ShowLog bool - TimeOut string - DryRun bool - Output string - PrefixName string - Workspaces []string - UseParamDefaults bool - clustertask *v1beta1.ClusterTask - askOpts survey.AskOpt - TektonOptions flags.TektonOptions - PodTemplate string - UseTaskRun string - SkipOptionalWorkspace bool -} - -// NameArg validates that the first argument is a valid clustertask name -func NameArg(args []string, p cli.Params, opt *startOptions) error { - if len(args) == 0 { - return errNoClusterTask - } - - c, err := p.Clients() - if err != nil { - return err - } - - name := args[0] - var ct *v1beta1.ClusterTask - err = actions.GetV1(clustertaskGroupResource, c, name, "", metav1.GetOptions{}, &ct) - if err != nil { - return fmt.Errorf(errInvalidClusterTask, name) - } - opt.clustertask = ct - if ct.Spec.Params != nil { - params.FilterParamsByType(ct.Spec.Params) - } - - return nil -} - -func startCommand(p cli.Params) *cobra.Command { - opt := startOptions{ - cliparams: p, - askOpts: func(opt *survey.AskOptions) error { - opt.Stdio = terminal.Stdio{ - In: os.Stdin, - Out: os.Stdout, - Err: os.Stderr, - } - return nil - }, - } - - eg := `Start ClusterTask foo by creating a TaskRun named "foo-run-xyz123" in namespace 'bar': - - tkn clustertask start foo -n bar - -or - - tkn ct start foo -n bar - -For params value, if you want to provide multiple values, provide them comma separated -like cat,foo,bar - -For passing the workspaces via flags: - -- In case of emptyDir, you can pass it like -w name=my-empty-dir,emptyDir= -- In case of configMap, you can pass it like -w name=my-config,config=rpg,item=ultimav=1 -- In case of secrets, you can pass it like -w name=my-secret,secret=secret-name -- In case of pvc, you can pass it like -w name=my-pvc,claimName=pvc1 -- In case of volumeClaimTemplate, you can pass it like -w name=my-volume-claim-template,volumeClaimTemplateFile=workspace-template.yaml - but before you need to create a workspace-template.yaml file. Sample contents of the file are as follows: - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi -- In case of binding a CSI workspace, you can pass it like -w name=my-csi,csiFile=csi.yaml - but you need to create a csi.yaml file before hand. Sample contents of the file are as follows: - - driver: secrets-store.csi.k8s.io - readOnly: true - volumeAttributes: - secretProviderClass: "vault-database" -` - - c := &cobra.Command{ - Use: "start", - Short: "Start ClusterTasks", - Annotations: map[string]string{ - "commandType": "main", - }, - Example: eg, - SilenceUsage: true, - ValidArgsFunction: formatted.ParentCompletion, - Args: func(cmd *cobra.Command, args []string) error { - if opt.UseParamDefaults && (opt.Last || opt.UseTaskRun != "") { - return errors.New("cannot use --last or --use-taskrun options with --use-param-defaults option") - } - format := strings.ToLower(opt.Output) - if format != "" && format != "json" && format != "yaml" { - return fmt.Errorf("output format specified is %s but must be yaml or json", opt.Output) - } - if format != "" && opt.ShowLog { - return errors.New("cannot use --output option with --showlog option") - } - if err := flags.InitParams(p, cmd); err != nil { - return err - } - return NameArg(args, p, &opt) - }, - RunE: func(cmd *cobra.Command, args []string) error { - opt.stream = &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - if opt.Last && opt.UseTaskRun != "" { - return fmt.Errorf("using --last and --use-taskrun are not compatible") - } - opt.TektonOptions = flags.GetTektonOptions(cmd) - return startClusterTask(opt, args) - }, - } - c.Flags().StringArrayVarP(&opt.Params, "param", "p", []string{}, "pass the param as key=value for string type, or key=value1,value2,... for array type, or key=\"key1:value1, key2:value2\" for object type") - c.Flags().StringVarP(&opt.ServiceAccountName, "serviceaccount", "s", "", "pass the serviceaccount name") - c.Flags().BoolVarP(&opt.Last, "last", "L", false, "re-run the ClusterTask using last TaskRun values") - c.Flags().StringVarP(&opt.UseTaskRun, "use-taskrun", "", "", "specify a TaskRun name to use its values to re-run the TaskRun") - c.Flags().StringSliceVarP(&opt.Labels, "labels", "l", []string{}, "pass labels as label=value.") - c.Flags().StringArrayVarP(&opt.Workspaces, "workspace", "w", []string{}, "pass one or more workspaces to map to the corresponding physical volumes") - c.Flags().BoolVarP(&opt.ShowLog, "showlog", "", false, "show logs right after starting the ClusterTask") - 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 (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") - c.Flags().BoolVarP(&opt.SkipOptionalWorkspace, "skip-optional-workspace", "", false, "skips the prompt for optional workspaces") - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} - -func startClusterTask(opt startOptions, args []string) error { - tr := &v1beta1.TaskRun{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "tekton.dev/v1beta1", - Kind: "TaskRun", - }, - ObjectMeta: metav1.ObjectMeta{}, - } - - cs, err := opt.cliparams.Clients() - if err != nil { - return err - } - - ctname := args[0] - tr.Spec = v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: ctname, - Kind: v1beta1.ClusterTaskKind, // Specify TaskRun is for a ClusterTask kind - }, - } - - if err := opt.getInputs(); err != nil { - return err - } - - if opt.Last || opt.UseTaskRun != "" { - taskRunOpts := options.TaskRunOpts{ - CliParams: opt.cliparams, - Last: opt.Last, - UseTaskRun: opt.UseTaskRun, - PrefixName: opt.PrefixName, - } - err := taskRunOpts.UseTaskRunFrom(tr, cs, ctname, "ClusterTask") - if err != nil { - return err - } - } - - if opt.PrefixName == "" && !opt.Last && opt.UseTaskRun == "" { - tr.ObjectMeta.GenerateName = ctname + "-run-" - } else if opt.PrefixName != "" { - tr.ObjectMeta.GenerateName = opt.PrefixName + "-" - } - - if opt.TimeOut != "" { - timeoutDuration, err := time.ParseDuration(opt.TimeOut) - if err != nil { - return err - } - tr.Spec.Timeout = &metav1.Duration{Duration: timeoutDuration} - } - - labels, err := labels.MergeLabels(tr.ObjectMeta.Labels, opt.Labels) - if err != nil { - return err - } - tr.ObjectMeta.Labels = labels - - workspaces, err := workspaces.Merge(tr.Spec.Workspaces, opt.Workspaces, cs.HTTPClient) - if err != nil { - return err - } - tr.Spec.Workspaces = workspaces - - param, err := params.MergeParam(tr.Spec.Params, opt.Params) - if err != nil { - return err - } - tr.Spec.Params = param - - if len(opt.ServiceAccountName) > 0 { - tr.Spec.ServiceAccountName = opt.ServiceAccountName - } - - podTemplateLocation := opt.PodTemplate - if podTemplateLocation != "" { - podTemplate, err := pods.ParsePodTemplate(cs.HTTPClient, podTemplateLocation, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", podTemplateLocation)) - if err != nil { - return err - } - tr.Spec.PodTemplate = &podTemplate - } - - if opt.DryRun { - gvr, err := actions.GetGroupVersionResource(taskrunGroupResource, cs.Tekton.Discovery()) - if err != nil { - return err - } - if gvr.Version == "v1" { - var trv1 v1.TaskRun - err = tr.ConvertTo(context.Background(), &trv1) - if err != nil { - return err - } - trv1.Kind = "TaskRun" - trv1.APIVersion = "tekton.dev/v1" - return printTaskRun(opt.Output, opt.stream, &trv1) - } - return printTaskRun(opt.Output, opt.stream, tr) - } - - trCreated, err := tractions.Create(cs, tr, metav1.CreateOptions{}, opt.cliparams.Namespace()) - if err != nil { - return err - } - - if opt.Output != "" { - gvr, err := actions.GetGroupVersionResource(taskrunGroupResource, cs.Tekton.Discovery()) - if err != nil { - return err - } - if gvr.Version == "v1" { - var trv1 v1.TaskRun - err = trCreated.ConvertTo(context.Background(), &trv1) - if err != nil { - return err - } - trv1.Kind = "TaskRun" - trv1.APIVersion = "tekton.dev/v1" - return printTaskRun(opt.Output, opt.stream, &trv1) - } - return printTaskRun(opt.Output, opt.stream, trCreated) - } - - fmt.Fprintf(opt.stream.Out, "TaskRun started: %s\n", trCreated.Name) - if !opt.ShowLog { - inOrderString := "\nIn order to track the TaskRun progress run:\ntkn taskrun " - if opt.TektonOptions.Context != "" { - inOrderString += fmt.Sprintf("--context=%s ", opt.TektonOptions.Context) - } - inOrderString += fmt.Sprintf("logs %s -f -n %s\n", trCreated.Name, trCreated.Namespace) - - fmt.Fprint(opt.stream.Out, inOrderString) - return nil - } - - fmt.Fprintf(opt.stream.Out, "Waiting for logs to be available...\n") - runLogOpts := &options.LogOptions{ - TaskrunName: trCreated.Name, - Stream: opt.stream, - Follow: true, - Prefixing: true, - Params: opt.cliparams, - AllSteps: false, - } - return taskrun.Run(runLogOpts) -} - -func printTaskRun(output string, s *cli.Stream, tr interface{}) error { - format := strings.ToLower(output) - - if format == "" || format == "yaml" { - trBytes, err := yaml.Marshal(tr) - if err != nil { - return err - } - fmt.Fprintf(s.Out, "%s", trBytes) - } - - if format == "json" { - trBytes, err := json.MarshalIndent(tr, "", "\t") - if err != nil { - return err - } - fmt.Fprintf(s.Out, "%s\n", trBytes) - } - - return nil -} - -func (opt *startOptions) getInputs() error { - intOpts := options.InteractiveOpts{ - Stream: opt.stream, - CliParams: opt.cliparams, - AskOpts: opt.askOpts, - Ns: opt.cliparams.Namespace(), - SkipOptionalWorkspace: opt.SkipOptionalWorkspace, - } - - params.FilterParamsByType(opt.clustertask.Spec.Params) - if !opt.Last && opt.UseTaskRun == "" { - skipParams, err := params.ParseParams(opt.Params) - if err != nil { - return err - } - if err := intOpts.ClusterTaskParams(opt.clustertask, skipParams, opt.UseParamDefaults); err != nil { - return err - } - opt.Params = append(opt.Params, intOpts.Params...) - } - - if len(opt.Workspaces) == 0 && !opt.Last && opt.UseTaskRun == "" { - if err := intOpts.ClusterTaskWorkspaces(opt.clustertask); err != nil { - return err - } - opt.Workspaces = append(opt.Workspaces, intOpts.Workspaces...) - } - - return nil -} diff --git a/pkg/cmd/clustertask/start_test.go b/pkg/cmd/clustertask/start_test.go deleted file mode 100644 index a2e29393be..0000000000 --- a/pkg/cmd/clustertask/start_test.go +++ /dev/null @@ -1,920 +0,0 @@ -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "io" - "reflect" - "strings" - "testing" - "time" - - "github.com/tektoncd/cli/pkg/actions" - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - pipelinev1beta1test "github.com/tektoncd/pipeline/test" - "gotest.tools/v3/golden" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/runtime/serializer" - util_runtime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/dynamic" - k8stest "k8s.io/client-go/testing" -) - -func newDynamicClientOpt(version, taskRunName string, objs ...runtime.Object) testDynamic.Options { - scheme := runtime.NewScheme() - codecs := serializer.NewCodecFactory(scheme) - var localSchemeBuilder runtime.SchemeBuilder - if version == "v1beta1" { - localSchemeBuilder = runtime.SchemeBuilder{v1beta1.AddToScheme} - } - metav1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) - util_runtime.Must(localSchemeBuilder.AddToScheme(scheme)) - - o := k8stest.NewObjectTracker(scheme, codecs.UniversalDecoder()) - for _, obj := range objs { - if err := o.Add(obj); err != nil { - panic(err) - } - } - - tdc := testDynamic.Options{ - AddReactorRes: "*", - AddReactorVerb: "*", - AddReactorFun: k8stest.ObjectReaction(o), - WatchResource: "*", - WatchReactionFun: func(action k8stest.Action) (handled bool, ret watch.Interface, err error) { - gvr := action.GetResource() - ns := action.GetNamespace() - watch, err := o.Watch(gvr, ns) - if err != nil { - return false, nil, err - } - return true, watch, nil - }, - PrependReactors: []testDynamic.PrependOpt{ - { - Resource: "taskruns", - Verb: "create", - Action: func(action k8stest.Action) (bool, runtime.Object, error) { - create := action.(k8stest.CreateActionImpl) - unstructuredTR := create.GetObject().(*unstructured.Unstructured) - unstructuredTR.SetName(taskRunName) - rFunc := k8stest.ObjectReaction(o) - _, o, err := rFunc(action) - return true, o, err - }, - }, - { - Resource: "taskruns", - Verb: "get", - Action: func(action k8stest.Action) (bool, runtime.Object, error) { - getAction, _ := action.(k8stest.GetActionImpl) - res := getAction.GetResource() - ns := getAction.GetNamespace() - name := getAction.GetName() - obj, err := o.Get(res, ns, name) - if err != nil { - return false, nil, err - } - if reflect.TypeOf(obj).String() == "*unstructured.Unstructured" { - return true, obj, nil - } - - v1beta1TR := obj.(*v1beta1.TaskRun) - unstructuredTR := cb.UnstructuredV1beta1TR(v1beta1TR, versionB1) - return true, unstructuredTR, nil - }, - }, - }, - } - - return tdc -} - -func Test_ClusterTask_Start(t *testing.T) { - clock := test.FakeClock() - type clients struct { - pipelineClient test.Clients - dynamicClient dynamic.Interface - } - seeds := make([]clients, 0) - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-1", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "myarg", - Type: v1beta1.ParamTypeString, - }, - { - Name: "print", - Type: v1beta1.ParamTypeArray, - }, - }, - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - { - Name: "exit", - Image: "busybox", - }, - }, - Workspaces: []v1beta1.WorkspaceDeclaration{ - { - Name: "test", - Description: "test workspace", - MountPath: "/workspace/test/file", - ReadOnly: true, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-2", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "myarg", - Type: v1beta1.ParamTypeString, - }, - }, - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - { - Name: "exit", - Image: "busybox", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-3", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "myarg", - Type: v1beta1.ParamTypeString, - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, - StringVal: "arg1", - }, - }, - { - Name: "print", - Type: v1beta1.ParamTypeArray, - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"boom", "boom"}, - }, - }, - }, - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - { - Name: "exit", - Image: "busybox", - }, - }, - Workspaces: []v1beta1.WorkspaceDeclaration{ - { - Name: "test", - Description: "test workspace", - MountPath: "/workspace/test/file", - ReadOnly: true, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask-4", - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-1 * time.Minute)}, - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - }, - Workspaces: []v1beta1.WorkspaceDeclaration{ - { - Name: "test", - Description: "test workspace", - MountPath: "/workspace/test/file", - ReadOnly: true, - Optional: true, - }, - }, - }, - }, - } - - taskruns := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-123", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/clusterTask": "clustertask-1"}, - }, - Spec: v1beta1.TaskRunSpec{ - Params: []v1beta1.Param{ - { - Name: "myarg", - Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "value"}, - }, - { - Name: "print", - Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"booms", "booms", "booms"}}, - }, - }, - ServiceAccountName: "svc", - TaskRef: &v1beta1.TaskRef{ - Name: "clustertask-1", - Kind: v1beta1.ClusterTaskKind, - }, - Workspaces: []v1beta1.WorkspaceBinding{ - { - Name: "test", - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now()}, - }, - }, - }, - } - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - seedData0, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, TaskRuns: taskruns, ClusterTasks: clustertasks}) - objs0 := []runtime.Object{clustertasks[0], taskruns[0]} - tdc0 := newDynamicClientOpt(versionB1, "taskrun-1", objs0...) - dc0, _ := tdc0.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - cs := test.Clients{Pipeline: seedData0.Pipeline, Kube: seedData0.Kube} - cs.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"taskrun", "clustertask", "task"}) - // seeds[0] - seeds = append(seeds, clients{pipelineClient: cs, dynamicClient: dc0}) - - // seeds[1] - Same data as seeds[0] but creates a new TaskRun - seedData1, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, TaskRuns: taskruns, ClusterTasks: clustertasks}) - objs1 := []runtime.Object{clustertasks[0], taskruns[0]} - tdc1 := newDynamicClientOpt(versionB1, "taskrun-2", objs1...) - dc1, _ := tdc1.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - cs1 := test.Clients{Pipeline: seedData1.Pipeline, Kube: seedData1.Kube} - cs1.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "clustertask"}) - // seeds[1] - No TaskRun with ClusterTask - seeds = append(seeds, clients{pipelineClient: cs1, dynamicClient: dc1}) - - objs2 := []runtime.Object{clustertasks[0]} - seedData2, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks, Namespaces: ns, TaskRuns: taskruns}) - tdc2 := newDynamicClientOpt(versionB1, "taskrun-2", objs2...) - dc2, _ := tdc2.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], versionB1), - ) - cs2 := test.Clients{Pipeline: seedData2.Pipeline, Kube: seedData2.Kube} - cs2.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "clustertask"}) - // seeds[2] - seeds = append(seeds, clients{pipelineClient: cs2, dynamicClient: dc2}) - - // seeds[3] - For Dry Run tests with v1beta1 - tdc3 := testDynamic.Options{} - dc3, _ := tdc3.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], versionB1), - cb.UnstructuredV1beta1CT(clustertasks[1], versionB1), - ) - cs3, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks, Namespaces: ns}) - cs3.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "clustertask"}) - // seeds[3] - seeds = append(seeds, clients{pipelineClient: cs3, dynamicClient: dc3}) - - // seeds[4] - For Dry Run tests with v1beta1 - tdc4 := testDynamic.Options{} - dc4, _ := tdc4.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], versionB1), - cb.UnstructuredV1beta1CT(clustertasks[1], versionB1), - ) - cs4, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks, Namespaces: ns}) - cs4.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "clustertask"}) - // seeds[4] - seeds = append(seeds, clients{pipelineClient: cs4, dynamicClient: dc4}) - - seedData5, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, TaskRuns: taskruns, ClusterTasks: clustertasks}) - objs5 := []runtime.Object{clustertasks[2], taskruns[0]} - tdc5 := newDynamicClientOpt(versionB1, "taskrun-3", objs5...) - dc5, _ := tdc5.Client( - cb.UnstructuredV1beta1CT(clustertasks[2], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - cs5 := pipelinev1beta1test.Clients{Pipeline: seedData5.Pipeline, Kube: seedData5.Kube} - cs5.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"taskrun", "clustertask", "task"}) - // seeds[5] - seeds = append(seeds, clients{pipelineClient: cs, dynamicClient: dc5}) - - // seeds[6] - Same data as seeds[0] but creates a new TaskRun - seedData6, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, TaskRuns: taskruns, ClusterTasks: clustertasks}) - objs6 := []runtime.Object{clustertasks[0], taskruns[0]} - tdc6 := newDynamicClientOpt(versionB1, "taskrun-4", objs6...) - dc6, _ := tdc6.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - cs6 := test.Clients{Pipeline: seedData6.Pipeline, Kube: seedData6.Kube} - cs6.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "clustertask"}) - // seeds[6] - For starting ClusterTask with use-taskrun flag - seeds = append(seeds, clients{pipelineClient: cs6, dynamicClient: dc6}) - - // seeds[7] - Same data as seeds[0] but creates a new TaskRun - seedData7, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, TaskRuns: taskruns, ClusterTasks: clustertasks}) - objs7 := []runtime.Object{clustertasks[3], taskruns[0]} - tdc7 := newDynamicClientOpt(versionB1, "taskrun-5", objs7...) - dc7, _ := tdc7.Client( - cb.UnstructuredV1beta1CT(clustertasks[3], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - cs7 := test.Clients{Pipeline: seedData7.Pipeline, Kube: seedData7.Kube} - cs7.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "clustertask"}) - // seeds[7] - For starting ClusterTask with skip-optional-workspaces flag - seeds = append(seeds, clients{pipelineClient: cs7, dynamicClient: dc7}) - - testParams := []struct { - name string - command []string - dynamic dynamic.Interface - input test.Clients - inputStream io.Reader - wantError bool - hasPrefix bool - want string - goldenFile bool - }{ - { - name: "Start with no arguments", - command: []string{"start"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "missing ClusterTask name", - }, - { - name: "ClusterTask doesn't exist", - command: []string{"start", "notexist"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "ClusterTask name notexist does not exist", - }, - { - name: "Use --last with no taskruns", - command: []string{"start", "clustertask-1", "--last"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "no TaskRuns related to ClusterTask clustertask-1 found in namespace ns", - }, - { - name: "Start clustertask", - command: []string{"start", "clustertask-1", - "-p", "myarg=value1", - "-p", "print=boom,boom", - "-l", "key=value", - "-w", "name=test,claimName=pvc3", - "-s=svc1"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"start\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" + - "TaskRun started: taskrun-1\n\nIn order to track the TaskRun progress run:\ntkn taskrun logs taskrun-1 -f -n ns\n", - }, - { - name: "Start with --last option", - command: []string{"start", "clustertask-1", "--last"}, - dynamic: seeds[1].dynamicClient, - input: seeds[1].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"start\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" + - "TaskRun started: taskrun-2\n\nIn order to track the TaskRun progress run:\ntkn taskrun logs taskrun-2 -f -n ns\n", - }, - { - name: "Start with --use-taskrun option", - command: []string{"start", "clustertask-1", "--use-taskrun", "taskrun-123"}, - dynamic: seeds[6].dynamicClient, - input: seeds[6].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"start\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" + - "TaskRun started: taskrun-4\n\nIn order to track the TaskRun progress run:\ntkn taskrun logs taskrun-4 -f -n ns\n", - }, - { - name: "Invalid param format", - command: []string{"start", "clustertask-1", - "-p", "myarg value1", - "-p", "print=boom,boom", - "-l", "key=value", - "-w", "name=test,claimName=pvc3", - "-s=svc1"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "invalid input format for param parameter: myarg value1", - }, - { - name: "Invalid label format", - command: []string{"start", "clustertask-1", - "-p", "myarg=value1", - "-p", "print=boom,boom", - "-l", "key value", - "-w", "name=test,claimName=pvc3", - "-s=svc1"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "invalid input format for label parameter: key value", - }, - { - name: "Param not in spec", - command: []string{"start", "clustertask-1", - "-p", "myar=value1", - "-p", "myarg=value1", - "-p", "print=boom,boom", - "-l", "key=value", - "-w", "name=test,claimName=pvc3", - "-s=svc1"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "param 'myar' not present in spec", - }, - { - name: "Dry run with invalid output", - command: []string{"start", "clustertask-1", - "-p", "myarg=value1", - "-l", "key=value", - "-s=svc1", - "--dry-run", - "--output=invalid", - }, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "output format specified is invalid but must be yaml or json", - }, - { - name: "Dry run with no output v1beta1", - command: []string{"start", "clustertask-2", - "-p", "myarg=value1", - "-l", "key=value", - "-s=svc1", - "--dry-run", - }, - dynamic: seeds[3].dynamicClient, - input: seeds[3].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, - { - name: "Dry run with --last", - command: []string{"start", "clustertask-1", - "-l", "key=value", - "-s=svc1", - "--dry-run", - "--last", - }, - dynamic: seeds[1].dynamicClient, - input: seeds[1].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, - { - name: "Dry run with --timeout v1beta1", - command: []string{"start", "clustertask-2", - "-p", "myarg=value1", - "-l", "key=value", - "-s=svc1", - "--dry-run", - "--timeout", "5s", - }, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, - { - name: "Dry run with invalid --timeout v1beta1", - command: []string{"start", "clustertask-2", - "-p", "myarg=value1", - "-l", "key=value", - "-s=svc1", - "--dry-run", - "--timeout", "5d", - }, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: true, - hasPrefix: true, - want: `time: unknown unit`, - }, - { - name: "Dry run with PodTemplate", - command: []string{"start", "clustertask-2", - "-p", "myarg=value1", - "-p", "print=boom", - "-l", "key=value", - "-l", "key=value", - "-s=svc1", - "--dry-run", - "--pod-template", "./testdata/podtemplate.yaml", - }, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, - { - name: "Dry Run with --use-param-defaults and specified params", - command: []string{"start", "clustertask-3", - "-p", "myarg=value1", - "-p", "print=boom", - "-l", "key=value", - "-w", "name=test,emptyDir=", - "-s=svc1", - "--dry-run", - "--use-param-defaults"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, - { - name: "Dry Run with --use-param-defaults and no specified params", - command: []string{"start", "clustertask-3", - "-l", "key=value", - "-w", "name=test,emptyDir=", - "-s=svc1", - "--dry-run", - "--use-param-defaults"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, - { - name: "Dry Run with --use-param-defaults and --last", - command: []string{"start", "clustertask-3", - "-l", "key=value", - "-w", "name=test,emptyDir=", - "-s=svc1", - "--dry-run", - "--use-param-defaults", - "--last"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "cannot use --last or --use-taskrun options with --use-param-defaults option", - }, - { - name: "Dry Run with --use-param-defaults and --use-taskrun", - command: []string{"start", "clustertask-3", - "-l", "key=value", - "-w", "name=test,emptyDir=", - "-s=svc1", - "--dry-run", - "--use-param-defaults", - "--use-taskrun", "dummy-taskrun"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "cannot use --last or --use-taskrun options with --use-param-defaults option", - }, - { - name: "Dry Run with --prefix-name v1beta1", - command: []string{"start", "clustertask-3", - "-p", "myarg=value1", - "-p", "print=boom", - "-l", "key=value", - "-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", - "-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, - }, - { - name: "Start clustertask with skip-optional-workspaces flag", - command: []string{"start", "clustertask-4", - "--skip-optional-workspace", - "-s=svc1"}, - dynamic: seeds[7].dynamicClient, - input: seeds[7].pipelineClient, - inputStream: nil, - wantError: false, - want: "Command \"start\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" + - "TaskRun started: taskrun-5\n\nIn order to track the TaskRun progress run:\ntkn taskrun logs taskrun-5 -f -n ns\n", - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - p := &test.Params{Tekton: tp.input.Pipeline, Kube: tp.input.Kube, Dynamic: tp.dynamic} - p.SetNamespace("ns") - clustertask := Command(p) - if tp.inputStream != nil { - clustertask.SetIn(tp.inputStream) - } - - got, err := test.ExecuteCommand(clustertask, tp.command...) - if tp.wantError { - if err == nil { - t.Errorf("Error expected here") - } - - if tp.hasPrefix { - test.AssertOutputPrefix(t, tp.want, err.Error()) - } else { - test.AssertOutput(t, tp.want, err.Error()) - } - } else { - if err != nil { - t.Errorf("Unexpected error") - } - if tp.goldenFile { - golden.Assert(t, got, strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-")) - } else { - test.AssertOutput(t, tp.want, got) - } - } - }) - } -} - -func Test_start_use_taskrun_cancelled_status(t *testing.T) { - ctasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - }, - Spec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "myarg", - Type: v1beta1.ParamTypeString, - }, - { - Name: "print", - Type: v1beta1.ParamTypeArray, - }, - }, - Steps: []v1beta1.Step{ - { - Name: "hello", - Image: "busybox", - }, - { - - Name: "exit", - Image: "busybox", - }, - }, - }, - }, - } - - timeoutDuration, _ := time.ParseDuration("10s") - trName := "ct-run" - taskruns := []*v1beta1.TaskRun{ - { - - ObjectMeta: metav1.ObjectMeta{ - Name: trName, - Labels: map[string]string{"tekton.dev/clustertask": "clustertask"}, - Namespace: "ns", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "clustertask", - Kind: v1beta1.ClusterTaskKind, - }, - ServiceAccountName: "serviceaccount", - Timeout: &metav1.Duration{Duration: timeoutDuration}, - Status: v1beta1.TaskRunSpecStatus(v1beta1.TaskRunSpecStatusCancelled), - }, - }, - } - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - seedData, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, ClusterTasks: ctasks, TaskRuns: taskruns}) - objs := []runtime.Object{ctasks[0], taskruns[0]} - trName2 := trName + "-2" - tdc := newDynamicClientOpt(versionB1, trName2, objs...) - - cs := pipelinev1beta1test.Clients{ - Pipeline: seedData.Pipeline, - Kube: seedData.Kube, - } - cs.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"clustertask", "taskrun"}) - dc, _ := tdc.Client( - cb.UnstructuredV1beta1CT(ctasks[0], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - clustertask := Command(p) - got, _ := test.ExecuteCommand(clustertask, "start", "clustertask", "--use-taskrun", trName, "-n", "ns") - - expected := "Command \"start\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nTaskRun started: ct-run-2\n\nIn order to track the TaskRun progress run:\ntkn taskrun logs ct-run-2 -f -n ns\n" - test.AssertOutput(t, expected, got) - clients, _ := p.Clients() - var tr *v1beta1.TaskRun - if err := actions.GetV1(taskrunGroupResource, clients, trName2, "ns", metav1.GetOptions{}, &tr); err != nil { - t.Errorf("Error listing taskruns %s", err.Error()) - } - - test.AssertOutput(t, "serviceaccount", tr.Spec.ServiceAccountName) - test.AssertOutput(t, timeoutDuration, tr.Spec.Timeout.Duration) - // Assert that new TaskRun does not contain cancelled status of previous run - test.AssertOutput(t, v1beta1.TaskRunSpecStatus(""), tr.Spec.Status) -} - -func Test_start_clustertask_last_override_timeout(t *testing.T) { - ctasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "clustertask", - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{ - { - - Name: "hello", - Image: "busybox", - }, - { - - Name: "exit", - Image: "busybox", - }, - }, - }, - }, - } - - // Add timeout to last TaskRun for ClusterTask - timeoutDuration, _ := time.ParseDuration("10s") - trName := "ct-run" - taskruns := []*v1beta1.TaskRun{ - { - - ObjectMeta: metav1.ObjectMeta{ - Name: trName, - Labels: map[string]string{"tekton.dev/clusterTask": "clustertask"}, - Namespace: "ns", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "clustertask", - Kind: v1beta1.ClusterTaskKind, - }, - Timeout: &metav1.Duration{Duration: timeoutDuration}, - }, - }, - } - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - seedData, _ := test.SeedV1beta1TestData(t, test.Data{Namespaces: ns, ClusterTasks: ctasks, TaskRuns: taskruns}) - objs := []runtime.Object{ctasks[0], taskruns[0]} - trName2 := trName + "-2" - tdc := newDynamicClientOpt(versionB1, trName2, objs...) - - cs := pipelinev1beta1test.Clients{ - Pipeline: seedData.Pipeline, - Kube: seedData.Kube, - } - cs.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"clustertask", "taskrun"}) - dc, _ := tdc.Client( - cb.UnstructuredV1beta1CT(ctasks[0], versionB1), - cb.UnstructuredV1beta1TR(taskruns[0], versionB1), - ) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - clustertask := Command(p) - // Specify new timeout value to override previous value - got, err := test.ExecuteCommand(clustertask, "start", "clustertask", "--use-taskrun", trName, "--timeout", "1s", "-n", "ns") - if err != nil { - t.Errorf("Error listing taskruns %s", err.Error()) - } - - expected := "Command \"start\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nTaskRun started: ct-run-2\n\nIn order to track the TaskRun progress run:\ntkn taskrun logs ct-run-2 -f -n ns\n" - test.AssertOutput(t, expected, got) - clients, _ := p.Clients() - var tr *v1beta1.TaskRun - if err := actions.GetV1(taskrunGroupResource, clients, trName2, "ns", metav1.GetOptions{}, &tr); err != nil { - t.Errorf("Error listing taskruns %s", err.Error()) - } - - // Assert newly started TaskRun has new timeout value - timeoutDuration, _ = time.ParseDuration("1s") - test.AssertOutput(t, timeoutDuration, tr.Spec.Timeout.Duration) -} diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Results.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Results.golden deleted file mode 100644 index 740a84aaf7..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Results.golden +++ /dev/null @@ -1,14 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: clustertask-1 -Description: a clustertest description - -Results - - NAME DESCRIPTION - result-1 This is a descripti... - result-2 This is a descripti... - result-3 - -Steps - - hello diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Workspaces.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Workspaces.golden deleted file mode 100644 index 8e45d3b157..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_With_Workspaces.golden +++ /dev/null @@ -1,12 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: clustertask-1 -Description: a clustertest description - -Workspaces - - NAME DESCRIPTION - test test workspace - -Steps - - hello diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneClusterTaskPresent.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneClusterTaskPresent.golden deleted file mode 100644 index 30bd3bd983..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneClusterTaskPresent.golden +++ /dev/null @@ -1,2 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: task-1 diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneV1beta1ClusterTaskPresent.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneV1beta1ClusterTaskPresent.golden deleted file mode 100644 index 30bd3bd983..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_WithoutNameIfOnlyOneV1beta1ClusterTaskPresent.golden +++ /dev/null @@ -1,2 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: task-1 diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_with_annotations.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_with_annotations.golden deleted file mode 100644 index 91d843b193..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskDescribe_with_annotations.golden +++ /dev/null @@ -1,4 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: clustertask-1 -Annotations: - tekton.dev/tags=testing diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskListNoHeadersv1beta1.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskListNoHeadersv1beta1.golden deleted file mode 100644 index a141a40306..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskListNoHeadersv1beta1.golden +++ /dev/null @@ -1,3 +0,0 @@ -Command "list" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -avocados 20 seconds ago -guavas 1 minute ago diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasksv1beta1.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasksv1beta1.golden deleted file mode 100644 index 5640ab041f..0000000000 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasksv1beta1.golden +++ /dev/null @@ -1,7 +0,0 @@ -Command "list" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -NAME DESCRIPTION AGE -apple a clustertask to te... 3 weeks ago -avocados 20 seconds ago -guavas 1 minute ago -mango 3 weeks ago -pineapple a test clustertask 3 weeks ago diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_missing_param_default_one_of_everything.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_missing_param_default_one_of_everything.golden deleted file mode 100644 index f8a96e3ee4..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_missing_param_default_one_of_everything.golden +++ /dev/null @@ -1,18 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: clustertask-one-everything -Description: a test description - -Params - - NAME TYPE DESCRIPTION DEFAULT VALUE - myarg string --- - -Steps - - hello - -Taskruns - -NAME STARTED DURATION STATUS -taskrun-2 10 minutes ago 27m0s Succeeded - diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_with_name_only.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_with_name_only.golden deleted file mode 100644 index 57248e8e06..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_clustertask_with_name_only.golden +++ /dev/null @@ -1,2 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: clustertask-justname diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_full_clustertask_multiple_taskruns.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_full_clustertask_multiple_taskruns.golden deleted file mode 100644 index 2483f83c91..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTaskDescribe-Describe_full_clustertask_multiple_taskruns.golden +++ /dev/null @@ -1,20 +0,0 @@ -Command "describe" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -Name: clustertask-full - -Params - - NAME TYPE DESCRIPTION DEFAULT VALUE - myarg string param type is string default - print array param type is array [booms booms booms] - -Steps - - hello - exit - -Taskruns - -NAME STARTED DURATION STATUS -taskrun-1 10 minutes ago 27m0s Succeeded -taskrun-3 12 minutes ago --- Running - diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_and_--last_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_and_--last_v1beta1.golden deleted file mode 100644 index e1e50f90b4..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_and_--last_v1beta1.golden +++ /dev/null @@ -1,26 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -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 - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-1 - workspaces: - - emptyDir: {} - name: test -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_v1beta1.golden deleted file mode 100644 index f6b43dea42..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--prefix-name_v1beta1.golden +++ /dev/null @@ -1,24 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: customname- - labels: - key: value -spec: - params: - - name: myarg - value: value1 - - name: print - value: - - boom - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-3 - workspaces: - - emptyDir: {} - name: test -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_no_specified_params.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_no_specified_params.golden deleted file mode 100644 index e390cd91f6..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_no_specified_params.golden +++ /dev/null @@ -1,18 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: clustertask-3-run- - labels: - key: value -spec: - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-3 - workspaces: - - emptyDir: {} - name: test -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_specified_params.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_specified_params.golden deleted file mode 100644 index 12d785c7ea..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_Run_with_--use-param-defaults_and_specified_params.golden +++ /dev/null @@ -1,24 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: clustertask-3-run- - labels: - key: value -spec: - params: - - name: myarg - value: value1 - - name: print - value: - - boom - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-3 - workspaces: - - emptyDir: {} - name: test -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden deleted file mode 100644 index d7ec249000..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden +++ /dev/null @@ -1,26 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: taskrun-123- - labels: - key: value -spec: - params: - - name: myarg - value: value - - name: print - value: - - booms - - booms - - booms - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-1 - workspaces: - - emptyDir: {} - name: test -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--timeout_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--timeout_v1beta1.golden deleted file mode 100644 index 7c72a72a9e..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--timeout_v1beta1.golden +++ /dev/null @@ -1,19 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: clustertask-2-run- - labels: - key: value -spec: - params: - - name: myarg - value: value1 - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-2 - timeout: 5s -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_PodTemplate.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_PodTemplate.golden deleted file mode 100644 index a5175017c5..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_PodTemplate.golden +++ /dev/null @@ -1,26 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: clustertask-2-run- - labels: - key: value -spec: - params: - - name: myarg - value: value1 - - name: print - value: - - boom - podTemplate: - schedulerName: SchedulerName - securityContext: - runAsNonRoot: true - runAsUser: 1001 - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-2 -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden deleted file mode 100644 index e8ef241a5c..0000000000 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden +++ /dev/null @@ -1,18 +0,0 @@ -Command "start" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases. -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - creationTimestamp: null - generateName: clustertask-2-run- - labels: - key: value -spec: - params: - - name: myarg - value: value1 - serviceAccountName: svc1 - taskRef: - kind: ClusterTask - name: clustertask-2 -status: - podName: "" diff --git a/pkg/cmd/clustertask/testdata/podtemplate.yaml b/pkg/cmd/clustertask/testdata/podtemplate.yaml deleted file mode 100644 index 9317310a73..0000000000 --- a/pkg/cmd/clustertask/testdata/podtemplate.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2020 The Tekton Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -schedulerName: SchedulerName -securityContext: - runAsNonRoot: true - runAsUser: 1001 \ No newline at end of file diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index cef1aedac7..e61d38c2f7 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -24,7 +24,6 @@ import ( "github.com/tektoncd/cli/pkg/cli/prerun" "github.com/tektoncd/cli/pkg/cmd/bundle" "github.com/tektoncd/cli/pkg/cmd/chain" - "github.com/tektoncd/cli/pkg/cmd/clustertask" "github.com/tektoncd/cli/pkg/cmd/clustertriggerbinding" "github.com/tektoncd/cli/pkg/cmd/completion" "github.com/tektoncd/cli/pkg/cmd/customrun" @@ -104,7 +103,6 @@ func Root(p cli.Params) *cobra.Command { cmd.AddCommand( bundle.Command(p), chain.Command(p), - clustertask.Command(p), clustertriggerbinding.Command(p), completion.Command(), eventlistener.Command(p), diff --git a/pkg/cmd/task/create.go b/pkg/cmd/task/create.go deleted file mode 100644 index dd79a90dc2..0000000000 --- a/pkg/cmd/task/create.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright © 2021 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package task - -import ( - "errors" - "fmt" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/clustertask" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/task" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type createOptions struct { - From string -} - -func createCommand(p cli.Params) *cobra.Command { - opts := &createOptions{} - eg := `Create a Task from ClusterTask 'foo' in namespace 'ns': - tkn task create --from foo -or - tkn task create foobar --from=foo -n ns` - - c := &cobra.Command{ - Use: "create", - ValidArgsFunction: formatted.ParentCompletion, - Short: "Create a Task from ClusterTask", - Example: eg, - Annotations: map[string]string{ - "commandType": "main", - }, - SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { - s := &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - if opts.From == "" { - return errors.New("--from flag not passed") - } - - if len(args) != 0 { - return createTaskFromClusterTask(s, p, args[0], opts.From) - } - return createTaskFromClusterTask(s, p, "", opts.From) - - }, - } - c.Flags().StringVarP(&opts.From, "from", "", "", "Create a ClusterTask from Task in a particular namespace") - c.Deprecated = "ClusterTasks are deprecated, this command will be removed in future releases." - return c -} - -func createTaskFromClusterTask(s *cli.Stream, p cli.Params, tname, ctname string) error { - - cs, err := p.Clients() - if err != nil { - return fmt.Errorf("failed to create tekton client") - } - - if tname == "" { - tname = ctname - } - - ns := p.Namespace() - - t, _ := task.Get(cs, tname, metav1.GetOptions{}, ns) - - if t != nil { - return fmt.Errorf(errTaskAlreadyPresent, tname, ns) - } - - ct, err := clustertask.Get(cs, ctname, metav1.GetOptions{}) - if err != nil { - return fmt.Errorf("ClusterTask %s does not exist", ctname) - } - - newT, err := task.Create(cs, clustertaskToTask(ct, tname), metav1.CreateOptions{}, p.Namespace()) - if err != nil { - return err - } - - fmt.Fprintf(s.Out, "Task %s created from ClusterTask %s in namespace %s\n", newT.Name, ct.Name, p.Namespace()) - - return nil -} - -func clustertaskToTask(ct *v1beta1.ClusterTask, tName string) *v1beta1.Task { - t := &v1beta1.Task{} - - // Copy required Metadata from Task to ClusterTask - t.ObjectMeta = metav1.ObjectMeta{ - Name: tName, - Labels: ct.Labels, - Annotations: ct.Annotations, - OwnerReferences: ct.OwnerReferences, - } - t.TypeMeta = metav1.TypeMeta{ - APIVersion: ct.APIVersion, - Kind: "Task", - } - // Copy the Specs from ClusterTask to Task - t.Spec = ct.Spec - - return t -} diff --git a/pkg/cmd/task/create_test.go b/pkg/cmd/task/create_test.go deleted file mode 100644 index 6f6f8410c5..0000000000 --- a/pkg/cmd/task/create_test.go +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright © 2021 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package task - -import ( - "testing" - - "github.com/tektoncd/cli/pkg/test" - cb "github.com/tektoncd/cli/pkg/test/builder" - testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestCreate_ClusterTaskNotExist(t *testing.T) { - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ct-1", - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertask to test description", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - p.SetNamespace("default") - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "task", "--from", "ct-2") - if err == nil { - t.Errorf("Expected error got nil") - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: ClusterTask ct-2 does not exist\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate(t *testing.T) { - ctasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ct-1", - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertask to test description", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(ctasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: ctasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - p.SetNamespace("default") - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "t-1", "--from", "ct-1") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nTask t-1 created from ClusterTask ct-1 in namespace default\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate_InNamespace(t *testing.T) { - ctasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ct-1", - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertask", - }, - }, - } - - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(ctasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: ctasks, Namespaces: namespaces}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "--from", "ct-1", "-n", "ns") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nTask ct-1 created from ClusterTask ct-1 in namespace ns\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate_WithoutFlag(t *testing.T) { - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ct-1", - }, - Spec: v1beta1.TaskSpec{ - Description: "a clustertask to test description", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1CT(clustertasks[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - cs, _ := test.SeedV1beta1TestData(t, test.Data{ClusterTasks: clustertasks}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "clustertask"}) - - clustertask := Command(p) - - out, err := test.ExecuteCommand(clustertask, "create", "ct-1") - if err == nil { - t.Errorf("Expected error got nil") - } - expected := "Command \"create\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\nError: --from flag not passed\n" - test.AssertOutput(t, expected, out) -} - -func TestCreate_ClusterTaskToTask(t *testing.T) { - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ctask-1", - }, - }, - } - ctask := clustertaskToTask(clustertasks[0], "ctask-1") - test.AssertOutput(t, "Task", ctask.Kind) -} diff --git a/pkg/cmd/task/delete.go b/pkg/cmd/task/delete.go index 69ca6fcc64..15059defd5 100644 --- a/pkg/cmd/task/delete.go +++ b/pkg/cmd/task/delete.go @@ -154,7 +154,7 @@ func taskRunLister(cs *cli.Clients, ns string) func(string) ([]string, error) { return nil, err } - // this is required as the same label is getting added for both Task and ClusterTask + // this is required as the same label is getting added for Task taskRuns.Items = task.FilterByRef(taskRuns.Items, "Task") var names []string for _, tr := range taskRuns.Items { diff --git a/pkg/cmd/task/delete_test.go b/pkg/cmd/task/delete_test.go index 53f5b8f5b6..f28d8e6bd9 100644 --- a/pkg/cmd/task/delete_test.go +++ b/pkg/cmd/task/delete_test.go @@ -106,32 +106,6 @@ func TestTaskDelete_v1beta1(t *testing.T) { }, }, }, - // ClusterTask is provided in the TaskRef of TaskRun, to verify - // TaskRun created by ClusterTask is not getting deleted while deleting - // Task with `--trs` flag and name of Task and ClusterTask is same. - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "task-run-3", - Labels: map[string]string{"tekton.dev/task": "task"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, } seeds := make([]clients, 0) @@ -156,7 +130,6 @@ func TestTaskDelete_v1beta1(t *testing.T) { cb.UnstructuredV1beta1T(tdata[1], version), cb.UnstructuredV1beta1TR(trdata[0], version), cb.UnstructuredV1beta1TR(trdata[1], version), - cb.UnstructuredV1beta1TR(trdata[2], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -419,9 +392,6 @@ func TestTaskDelete(t *testing.T) { }, }, }, - // ClusterTask is provided in the TaskRef of TaskRun, to verify - // TaskRun created by ClusterTask is not getting deleted while deleting - // Task with `--trs` flag and name of Task and ClusterTask is same. { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", diff --git a/pkg/cmd/task/describe.go b/pkg/cmd/task/describe.go index ba7752bb6c..6e4539c563 100644 --- a/pkg/cmd/task/describe.go +++ b/pkg/cmd/task/describe.go @@ -198,7 +198,7 @@ func printTaskDescription(s *cli.Stream, p cli.Params, tname string) error { return fmt.Errorf("failed to get TaskRuns for Task %s: %v", tname, err) } - // this is required as the same label is getting added for both task and ClusterTask + // this is required as the same label is getting added for task taskRuns.Items = task.FilterByRef(taskRuns.Items, "Task") trsort.SortByStartTime(taskRuns.Items) diff --git a/pkg/cmd/task/describe_test.go b/pkg/cmd/task/describe_test.go index dd32b6d6a5..048a2c6224 100644 --- a/pkg/cmd/task/describe_test.go +++ b/pkg/cmd/task/describe_test.go @@ -812,33 +812,6 @@ func TestTaskDescribe_Full_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr-3", - Labels: map[string]string{"tekton.dev/task": "task-1"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task-1", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionFalse, - Reason: v1beta1.TaskRunReasonFailed.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now()}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, - }, - }, - }, } namespaces := []*corev1.Namespace{ @@ -855,7 +828,6 @@ func TestTaskDescribe_Full_v1beta1(t *testing.T) { cb.UnstructuredV1beta1T(tasks[0], version), cb.UnstructuredV1beta1TR(taskRuns[0], version), cb.UnstructuredV1beta1TR(taskRuns[1], version), - cb.UnstructuredV1beta1TR(taskRuns[2], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) diff --git a/pkg/cmd/task/start.go b/pkg/cmd/task/start.go index 8b9e2d903e..6586dbbb95 100644 --- a/pkg/cmd/task/start.go +++ b/pkg/cmd/task/start.go @@ -52,9 +52,8 @@ import ( ) var ( - errNoTask = errors.New("missing Task name") - errInvalidTask = "Task name %s does not exist in namespace %s" - errTaskAlreadyPresent = "Task with name %s already exists in namespace %s" + errNoTask = errors.New("missing Task name") + errInvalidTask = "Task name %s does not exist in namespace %s" ) type startOptions struct { diff --git a/pkg/cmd/task/task.go b/pkg/cmd/task/task.go index 3e46d79deb..e25812dcb5 100644 --- a/pkg/cmd/task/task.go +++ b/pkg/cmd/task/task.go @@ -43,7 +43,6 @@ func Command(p cli.Params) *cobra.Command { listCommand(p), logCommand(p), startCommand(p), - createCommand(p), signCommand(), verifyCommand(), ) diff --git a/pkg/cmd/taskrun/delete.go b/pkg/cmd/taskrun/delete.go index 222bb67f0d..aded57b77b 100644 --- a/pkg/cmd/taskrun/delete.go +++ b/pkg/cmd/taskrun/delete.go @@ -36,8 +36,7 @@ import ( ) type deleteOptions struct { - ClusterTaskName string - TaskName string + TaskName string } // trExists validates that the arguments are valid TaskRun names @@ -93,14 +92,7 @@ or Err: cmd.OutOrStderr(), } - if deleteOpts.TaskName != "" && deleteOpts.ClusterTaskName != "" { - return fmt.Errorf("cannot use --task and --clustertask option together") - } - - if deleteOpts.ClusterTaskName != "" { - opts.ParentResource = "ClusterTask" - opts.ParentResourceName = deleteOpts.ClusterTaskName - } else { + if deleteOpts.TaskName != "" { opts.ParentResource = "Task" opts.ParentResourceName = deleteOpts.TaskName } @@ -143,7 +135,6 @@ or f.AddFlags(c) c.Flags().BoolVarP(&opts.ForceDelete, "force", "f", false, "Whether to force deletion (default: false)") c.Flags().StringVarP(&deleteOpts.TaskName, "task", "t", "", "The name of a Task whose TaskRuns should be deleted (does not delete the task)") - c.Flags().StringVarP(&deleteOpts.ClusterTaskName, "clustertask", "", "", "The name of a ClusterTask whose TaskRuns should be deleted (does not delete the ClusterTask)") c.Flags().BoolVarP(&opts.DeleteAllNs, "all", "", false, "Delete all TaskRuns in a namespace (default: false)") c.Flags().IntVarP(&opts.Keep, "keep", "", 0, "Keep n most recent number of TaskRuns") c.Flags().IntVarP(&opts.KeepSince, "keep-since", "", 0, "When deleting all TaskRuns keep the ones that has been completed since n minutes") @@ -203,12 +194,8 @@ func deleteTaskRuns(s *cli.Stream, p cli.Params, trNames []string, opts *options return errors.New(err) }) - // Create a LabelSelector to filter the TaskRuns which are associated with particular - // Task or ClusterTask + // Create a LabelSelector to filter the TaskRuns which are associated with particular Task resourceType := "task" - if opts.ParentResource == "ClusterTask" { - resourceType = "clusterTask" - } labelSelector := fmt.Sprintf("tekton.dev/%s=%s", resourceType, opts.ParentResourceName) // Compute the total no of TaskRuns which we need to delete @@ -219,7 +206,7 @@ func deleteTaskRuns(s *cli.Stream, p cli.Params, trNames []string, opts *options numberOfDeletedTr = len(trToDelete) numberOfKeptTr = len(trToKeep) - // Delete the TaskRuns associated with a Task or ClusterTask + // Delete the TaskRuns associated with a Task d.WithRelated("TaskRun", taskRunLister(p, opts.Keep, opts.KeepSince, opts.ParentResource, cs, opts.IgnoreRunning, opts.IgnoreRunningPipelinerun), func(taskRunName string) error { return actions.Delete(taskrunGroupResource, cs.Dynamic, cs.Tekton.Discovery(), taskRunName, p.Namespace(), metav1.DeleteOptions{}) }) @@ -288,9 +275,6 @@ func deleteTaskRuns(s *cli.Stream, p cli.Params, trNames []string, opts *options func taskRunLister(p cli.Params, keep, since int, kind string, cs *cli.Clients, ignoreRunning, ignoreRunningOwner bool) func(string) ([]string, error) { return func(taskName string) ([]string, error) { label := "task" - if kind == "ClusterTask" { - label = "clusterTask" - } labelSelector := fmt.Sprintf("tekton.dev/%s=%s", label, taskName) trToDelete, _, err := allTaskRunNames(cs, keep, since, ignoreRunning, ignoreRunningOwner, labelSelector, p.Namespace(), kind) diff --git a/pkg/cmd/taskrun/delete_test.go b/pkg/cmd/taskrun/delete_test.go index 6d54efea15..061853d43d 100644 --- a/pkg/cmd/taskrun/delete_test.go +++ b/pkg/cmd/taskrun/delete_test.go @@ -54,14 +54,6 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { }, } - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - }, - }, - } - trdata := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ @@ -147,148 +139,6 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-4", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: clock.Now().Add(10 * time.Minute), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-5", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: clock.Now().Add(10 * time.Minute), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-6", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: clock.Now().Add(10 * time.Minute), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-7", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - // Use real time for testing keep-since - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-8", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - // Use real time for testing keep-since and keep together - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, { ObjectMeta: metav1.ObjectMeta{ Name: "tr0-9", @@ -370,84 +220,6 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-12", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: nil, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: v1beta1.TaskRunReasonStarted.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-13", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: nil, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: v1beta1.TaskRunReasonRunning.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-14", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: nil, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: "ExceededResourceQuota", - }, - }, - }, - }, - }, } type clients struct { @@ -458,26 +230,17 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { seeds := make([]clients, 0) for i := 0; i < 17; i++ { trs := trdata - cs, _ := test.SeedV1beta1TestData(t, test.Data{TaskRuns: trs, Tasks: tasks, ClusterTasks: clustertasks, Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, test.Data{TaskRuns: trs, Tasks: tasks, Namespaces: ns}) cs.Pipeline.Resources = cb.APIResourceList(versionv1beta1, []string{"taskrun"}) tdc := testDynamic.Options{} dc, err := tdc.Client( cb.UnstructuredV1beta1T(tasks[0], versionv1beta1), - cb.UnstructuredV1beta1CT(clustertasks[0], versionv1beta1), cb.UnstructuredV1beta1TR(trdata[0], versionv1beta1), cb.UnstructuredV1beta1TR(trdata[1], versionv1beta1), cb.UnstructuredV1beta1TR(trdata[2], versionv1beta1), cb.UnstructuredV1beta1TR(trdata[3], versionv1beta1), cb.UnstructuredV1beta1TR(trdata[4], versionv1beta1), cb.UnstructuredV1beta1TR(trdata[5], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[6], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[7], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[8], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[9], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[10], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[11], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[12], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[13], versionv1beta1), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -557,15 +320,15 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { wantError: true, want: "taskruns.tekton.dev \"nonexistent\" not found; taskruns.tekton.dev \"nonexistent2\" not found", }, - { - name: "Attempt remove forgetting to include taskrun names", - command: []string{"rm", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "must provide TaskRun name(s) or use --task flag or --all flag to use delete", - }, + // { + // name: "Attempt remove forgetting to include taskrun names", + // command: []string{"rm", "-n", "ns"}, + // dynamic: seeds[2].dynamicClient, + // input: seeds[2].pipelineClient, + // inputStream: nil, + // wantError: true, + // want: "must provide TaskRun name(s) or use --all flag to use delete", + // }, { name: "Remove taskruns of a task", command: []string{"rm", "--task", "random", "-n", "ns"}, @@ -582,7 +345,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { input: seeds[3].pipelineClient, inputStream: strings.NewReader("y"), wantError: false, - want: "Are you sure you want to delete all TaskRuns in namespace \"ns\" (y/n): All 9 TaskRuns(Completed) deleted in namespace \"ns\"\n", + want: "Are you sure you want to delete all TaskRuns in namespace \"ns\" (y/n): All 4 TaskRuns(Completed) deleted in namespace \"ns\"\n", }, { name: "Delete all with -f", @@ -591,7 +354,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { input: seeds[4].pipelineClient, inputStream: nil, wantError: false, - want: "All 9 TaskRuns(Completed) deleted in namespace \"ns\"\n", + want: "All 4 TaskRuns(Completed) deleted in namespace \"ns\"\n", }, { name: "Delete all keeping 2", @@ -622,7 +385,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { }, { name: "Error from using taskrun name with --all", - command: []string{"delete", "tr0-7", "--all", "-n", "ns"}, + command: []string{"delete", "tr0-9", "--all", "-n", "ns"}, dynamic: seeds[5].dynamicClient, input: seeds[5].pipelineClient, inputStream: nil, @@ -631,7 +394,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { }, { name: "Error from deleting TaskRun with non-existing Task", - command: []string{"delete", "tr0-7", "-t", "non-existing-task", "-n", "ns"}, + command: []string{"delete", "tr0-9", "-t", "non-existing-task", "-n", "ns"}, dynamic: seeds[5].dynamicClient, input: seeds[5].pipelineClient, inputStream: nil, @@ -649,49 +412,13 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { }, { name: "Error from using argument with --keep", - command: []string{"rm", "tr0-7", "-n", "ns", "--keep", "2"}, + command: []string{"rm", "tr0-10", "-n", "ns", "--keep", "2"}, dynamic: seeds[5].dynamicClient, input: seeds[5].pipelineClient, inputStream: nil, wantError: true, want: "--keep flag should not have any arguments specified with it", }, - { - name: "Error when using both --task and --clustertask flag together", - command: []string{"rm", "--task", "random", "--clustertask", "random"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: true, - want: "cannot use --task and --clustertask option together", - }, - { - name: "Remove taskruns of a ClusterTask", - command: []string{"rm", "--clustertask", "random", "-n", "ns"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Are you sure you want to delete all TaskRuns related to ClusterTask \"random\" (y/n): All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, - { - name: "Error from deleting TaskRun with non-existing ClusterTask", - command: []string{"delete", "tr0-7", "--clustertask", "non-existing-clustertask", "-n", "ns"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "no TaskRuns associated with ClusterTask \"non-existing-clustertask\"", - }, - { - name: "Remove taskruns of a ClusterTask with --keep", - command: []string{"rm", "--clustertask", "random", "-n", "ns", "--keep", "2"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all TaskRuns related to ClusterTask \"random\" keeping 2 TaskRuns (y/n): All but 2 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, { name: "Delete all Taskruns older than 60mn", command: []string{"delete", "-f", "--all", "--keep-since", "60", "-n", "ns"}, @@ -699,7 +426,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { input: seeds[6].pipelineClient, inputStream: nil, wantError: false, - want: "6 expired Taskruns(Completed) has been deleted in namespace \"ns\", kept 3\n", + want: "3 expired Taskruns(Completed) has been deleted in namespace \"ns\", kept 1\n", }, { name: "Delete all Taskruns older than 60mn associated with random Task", @@ -735,7 +462,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { input: seeds[9].pipelineClient, inputStream: nil, wantError: false, - want: "7 TaskRuns(Completed) has been deleted in namespace \"ns\", kept 2\n", + want: "2 TaskRuns(Completed) has been deleted in namespace \"ns\", kept 2\n", }, { name: "Delete all TaskRuns older than 60mn and keeping 2 TaskRuns associated with random Task", @@ -789,7 +516,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { input: seeds[4].pipelineClient, inputStream: nil, wantError: false, - want: "All 5 TaskRuns deleted in namespace \"ns\"\n", + want: "All 2 TaskRuns deleted in namespace \"ns\"\n", }, { name: "Delete the Task present and give error for non-existent Task", @@ -845,33 +572,6 @@ func TestTaskRunDelete_v1beta1(t *testing.T) { wantError: false, want: "All 6 TaskRuns associated with Task \"random\" deleted in namespace \"ns\"\n", }, - { - name: "Delete all of clustertask with default --ignore-running", - command: []string{"delete", "--clustertask", "random", "-f", "-n", "ns", "--ignore-running"}, - dynamic: seeds[14].dynamicClient, - input: seeds[14].pipelineClient, - inputStream: nil, - wantError: false, - want: "All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all of clustertask with explicit --ignore-running true", - command: []string{"delete", "--clustertask", "random", "-f", "-n", "ns", "--ignore-running=true"}, - dynamic: seeds[15].dynamicClient, - input: seeds[15].pipelineClient, - inputStream: nil, - wantError: false, - want: "All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all of clustertask with --ignore-running false", - command: []string{"delete", "--clustertask", "random", "-f", "-n", "ns", "--ignore-running=false"}, - dynamic: seeds[16].dynamicClient, - input: seeds[16].pipelineClient, - inputStream: nil, - wantError: false, - want: "All 8 TaskRuns associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, } for _, tp := range testParams { @@ -1006,20 +706,21 @@ func TestTaskRunDelete(t *testing.T) { }, { ObjectMeta: metav1.ObjectMeta{ + Name: "tr0-9", Namespace: "ns", - Name: "tr0-4", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, + Labels: map[string]string{"tekton.dev/task": "random"}, }, Spec: v1.TaskRunSpec{ TaskRef: &v1.TaskRef{ Name: "random", - Kind: "ClusterTask", + Kind: v1.NamespacedTaskKind, }, }, Status: v1.TaskRunStatus{ TaskRunStatusFields: v1.TaskRunStatusFields{ CompletionTime: &metav1.Time{ - Time: clock.Now().Add(10 * time.Minute), + // for testing keep and keep-since together with resource name + Time: time.Now(), }, }, Status: duckv1.Status{ @@ -1035,161 +736,18 @@ func TestTaskRunDelete(t *testing.T) { { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", - Name: "tr0-5", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, + Name: "tr0-10", + Labels: map[string]string{"tekton.dev/task": "random"}, }, Spec: v1.TaskRunSpec{ TaskRef: &v1.TaskRef{ Name: "random", - Kind: "ClusterTask", + Kind: v1.NamespacedTaskKind, }, }, Status: v1.TaskRunStatus{ TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: clock.Now().Add(10 * time.Minute), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-6", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: clock.Now().Add(10 * time.Minute), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-7", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTaskKind", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - // Use real time for testing keep-since - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-8", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - // Use real time for testing keep-since and keep together - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr0-9", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: v1.NamespacedTaskKind, - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - // for testing keep and keep-since together with resource name - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-10", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: v1.NamespacedTaskKind, - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: nil, + CompletionTime: nil, }, Status: duckv1.Status{ Conditions: duckv1.Conditions{ @@ -1227,84 +785,6 @@ func TestTaskRunDelete(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-12", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: nil, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: v1.TaskRunReasonStarted.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-13", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: nil, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: v1.TaskRunReasonRunning.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-14", - Labels: map[string]string{"tekton.dev/clusterTask": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: nil, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionUnknown, - Reason: "ExceededResourceQuota", - }, - }, - }, - }, - }, } type clients struct { @@ -1326,14 +806,6 @@ func TestTaskRunDelete(t *testing.T) { cb.UnstructuredTR(trdata[3], version), cb.UnstructuredTR(trdata[4], version), cb.UnstructuredTR(trdata[5], version), - cb.UnstructuredTR(trdata[6], version), - cb.UnstructuredTR(trdata[7], version), - cb.UnstructuredTR(trdata[8], version), - cb.UnstructuredTR(trdata[9], version), - cb.UnstructuredTR(trdata[10], version), - cb.UnstructuredTR(trdata[11], version), - cb.UnstructuredTR(trdata[12], version), - cb.UnstructuredTR(trdata[13], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -1413,15 +885,15 @@ func TestTaskRunDelete(t *testing.T) { wantError: true, want: "taskruns.tekton.dev \"nonexistent\" not found; taskruns.tekton.dev \"nonexistent2\" not found", }, - { - name: "Attempt remove forgetting to include taskrun names", - command: []string{"rm", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "must provide TaskRun name(s) or use --task flag or --all flag to use delete", - }, + // { + // name: "Attempt remove forgetting to include taskrun names", + // command: []string{"rm", "-n", "ns"}, + // dynamic: seeds[2].dynamicClient, + // input: seeds[2].pipelineClient, + // inputStream: nil, + // wantError: true, + // want: "must provide TaskRun name(s) or use --all flag to use delete", + // }, { name: "Remove taskruns of a task", command: []string{"rm", "--task", "random", "-n", "ns"}, @@ -1438,7 +910,7 @@ func TestTaskRunDelete(t *testing.T) { input: seeds[3].pipelineClient, inputStream: strings.NewReader("y"), wantError: false, - want: "Are you sure you want to delete all TaskRuns in namespace \"ns\" (y/n): All 9 TaskRuns(Completed) deleted in namespace \"ns\"\n", + want: "Are you sure you want to delete all TaskRuns in namespace \"ns\" (y/n): All 4 TaskRuns(Completed) deleted in namespace \"ns\"\n", }, { name: "Delete all with -f", @@ -1447,7 +919,7 @@ func TestTaskRunDelete(t *testing.T) { input: seeds[4].pipelineClient, inputStream: nil, wantError: false, - want: "All 9 TaskRuns(Completed) deleted in namespace \"ns\"\n", + want: "All 4 TaskRuns(Completed) deleted in namespace \"ns\"\n", }, { name: "Delete all keeping 2", @@ -1478,7 +950,7 @@ func TestTaskRunDelete(t *testing.T) { }, { name: "Error from using taskrun name with --all", - command: []string{"delete", "tr0-7", "--all", "-n", "ns"}, + command: []string{"delete", "tr0-10", "--all", "-n", "ns"}, dynamic: seeds[5].dynamicClient, input: seeds[5].pipelineClient, inputStream: nil, @@ -1487,7 +959,7 @@ func TestTaskRunDelete(t *testing.T) { }, { name: "Error from deleting TaskRun with non-existing Task", - command: []string{"delete", "tr0-7", "-t", "non-existing-task", "-n", "ns"}, + command: []string{"delete", "tr0-9", "-t", "non-existing-task", "-n", "ns"}, dynamic: seeds[5].dynamicClient, input: seeds[5].pipelineClient, inputStream: nil, @@ -1505,49 +977,13 @@ func TestTaskRunDelete(t *testing.T) { }, { name: "Error from using argument with --keep", - command: []string{"rm", "tr0-7", "-n", "ns", "--keep", "2"}, + command: []string{"rm", "tr0-10", "-n", "ns", "--keep", "2"}, dynamic: seeds[5].dynamicClient, input: seeds[5].pipelineClient, inputStream: nil, wantError: true, want: "--keep flag should not have any arguments specified with it", }, - { - name: "Error when using both --task and --clustertask flag together", - command: []string{"rm", "--task", "random", "--clustertask", "random"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: true, - want: "cannot use --task and --clustertask option together", - }, - { - name: "Remove taskruns of a ClusterTask", - command: []string{"rm", "--clustertask", "random", "-n", "ns"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Are you sure you want to delete all TaskRuns related to ClusterTask \"random\" (y/n): All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, - { - name: "Error from deleting TaskRun with non-existing ClusterTask", - command: []string{"delete", "tr0-7", "--clustertask", "non-existing-clustertask", "-n", "ns"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "no TaskRuns associated with ClusterTask \"non-existing-clustertask\"", - }, - { - name: "Remove taskruns of a ClusterTask with --keep", - command: []string{"rm", "--clustertask", "random", "-n", "ns", "--keep", "2"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all TaskRuns related to ClusterTask \"random\" keeping 2 TaskRuns (y/n): All but 2 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, { name: "Delete all Taskruns older than 60mn", command: []string{"delete", "-f", "--all", "--keep-since", "60", "-n", "ns"}, @@ -1555,7 +991,7 @@ func TestTaskRunDelete(t *testing.T) { input: seeds[6].pipelineClient, inputStream: nil, wantError: false, - want: "6 expired Taskruns(Completed) has been deleted in namespace \"ns\", kept 3\n", + want: "3 expired Taskruns(Completed) has been deleted in namespace \"ns\", kept 1\n", }, { name: "Delete all Taskruns older than 60mn associated with random Task", @@ -1591,7 +1027,7 @@ func TestTaskRunDelete(t *testing.T) { input: seeds[9].pipelineClient, inputStream: nil, wantError: false, - want: "7 TaskRuns(Completed) has been deleted in namespace \"ns\", kept 2\n", + want: "2 TaskRuns(Completed) has been deleted in namespace \"ns\", kept 2\n", }, { name: "Delete all TaskRuns older than 60mn and keeping 2 TaskRuns associated with random Task", @@ -1645,7 +1081,7 @@ func TestTaskRunDelete(t *testing.T) { input: seeds[4].pipelineClient, inputStream: nil, wantError: false, - want: "All 5 TaskRuns deleted in namespace \"ns\"\n", + want: "All 2 TaskRuns deleted in namespace \"ns\"\n", }, { name: "Delete the Task present and give error for non-existent Task", @@ -1701,33 +1137,6 @@ func TestTaskRunDelete(t *testing.T) { wantError: false, want: "All 6 TaskRuns associated with Task \"random\" deleted in namespace \"ns\"\n", }, - { - name: "Delete all of clustertask with default --ignore-running", - command: []string{"delete", "--clustertask", "random", "-f", "-n", "ns", "--ignore-running"}, - dynamic: seeds[14].dynamicClient, - input: seeds[14].pipelineClient, - inputStream: nil, - wantError: false, - want: "All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all of clustertask with explicit --ignore-running true", - command: []string{"delete", "--clustertask", "random", "-f", "-n", "ns", "--ignore-running=true"}, - dynamic: seeds[15].dynamicClient, - input: seeds[15].pipelineClient, - inputStream: nil, - wantError: false, - want: "All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all of clustertask with --ignore-running false", - command: []string{"delete", "--clustertask", "random", "-f", "-n", "ns", "--ignore-running=false"}, - dynamic: seeds[16].dynamicClient, - input: seeds[16].pipelineClient, - inputStream: nil, - wantError: false, - want: "All 8 TaskRuns associated with ClusterTask \"random\" deleted in namespace \"ns\"\n", - }, } for _, tp := range testParams { @@ -1756,488 +1165,6 @@ func TestTaskRunDelete(t *testing.T) { } } -func Test_ClusterTask_TaskRuns_Not_Deleted_With_Task_Option_v1beta1(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - Namespace: "ns", - }, - }, - } - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - }, - }, - } - - trdata := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-1", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.NamespacedTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-2", - Labels: map[string]string{ - // TaskRun associated with ClusterTask will - // have both task and clusterTask labels: - // https://github.com/tektoncd/pipeline/issues/2533 - "tekton.dev/clusterTask": "random", - "tekton.dev/task": "random", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - } - - trs := trdata - cs, _ := test.SeedV1beta1TestData(t, test.Data{TaskRuns: trs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionv1beta1, []string{"taskrun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1T(tasks[0], versionv1beta1), - cb.UnstructuredV1beta1CT(clustertasks[0], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[0], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[1], versionv1beta1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dc} - taskrun := Command(p) - // Run tkn taskrun delete --task random to delete on kind Task random's TaskRuns - _, err = test.ExecuteCommand(taskrun, "delete", "--task", "random", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - - // Expect TaskRun from kind ClusterTask random remains after deletion - expected := `NAME STARTED DURATION STATUS -tr0-2 --- --- Succeeded -` - // Run list command to confirm TaskRun still present - out, err := test.ExecuteCommand(taskrun, "list", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - test.AssertOutput(t, expected, out) -} - -func Test_ClusterTask_TaskRuns_Not_Deleted_With_Task_Option(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - tasks := []*v1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - Namespace: "ns", - }, - }, - } - - trdata := []*v1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-1", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: v1.NamespacedTaskKind, - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-2", - Labels: map[string]string{ - // TaskRun associated with ClusterTask will - // have both task and clusterTask labels: - // https://github.com/tektoncd/pipeline/issues/2533 - "tekton.dev/clusterTask": "random", - "tekton.dev/task": "random", - }, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - } - - trs := trdata - cs, _ := test.SeedTestData(t, pipelinetest.Data{TaskRuns: trs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionv1beta1, []string{"taskrun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredT(tasks[0], versionv1beta1), - cb.UnstructuredTR(trdata[0], versionv1beta1), - cb.UnstructuredTR(trdata[1], versionv1beta1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dc} - taskrun := Command(p) - // Run tkn taskrun delete --task random to delete on kind Task random's TaskRuns - _, err = test.ExecuteCommand(taskrun, "delete", "--task", "random", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - - // Expect TaskRun from kind ClusterTask random remains after deletion - expected := `NAME STARTED DURATION STATUS -tr0-2 --- --- Succeeded -` - // Run list command to confirm TaskRun still present - out, err := test.ExecuteCommand(taskrun, "list", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - test.AssertOutput(t, expected, out) -} - -func Test_Task_TaskRuns_Not_Deleted_With_ClusterTask_Option_v1beta1(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - tasks := []*v1beta1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - Namespace: "ns", - }, - }, - } - - clustertasks := []*v1beta1.ClusterTask{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - }, - }, - } - - trdata := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-1", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.NamespacedTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-2", - Labels: map[string]string{ - // TaskRun associated with ClusterTask will - // have both task and clusterTask labels: - // https://github.com/tektoncd/pipeline/issues/2533 - "tekton.dev/clusterTask": "random", - "tekton.dev/task": "random", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - } - - trs := trdata - cs, _ := test.SeedV1beta1TestData(t, test.Data{TaskRuns: trs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionv1beta1, []string{"taskrun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1T(tasks[0], versionv1beta1), - cb.UnstructuredV1beta1CT(clustertasks[0], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[0], versionv1beta1), - cb.UnstructuredV1beta1TR(trdata[1], versionv1beta1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dc} - taskrun := Command(p) - // Run tkn taskrun delete --task random to delete on kind Task random's TaskRuns - _, err = test.ExecuteCommand(taskrun, "delete", "--clustertask", "random", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - - // Expect TaskRun from kind ClusterTask random remains after deletion - expected := `NAME STARTED DURATION STATUS -tr0-1 --- --- Succeeded -` - // Run list command to confirm TaskRun still present - out, err := test.ExecuteCommand(taskrun, "list", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - test.AssertOutput(t, expected, out) -} - -func Test_Task_TaskRuns_Not_Deleted_With_ClusterTask_Option(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - tasks := []*v1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "random", - Namespace: "ns", - }, - }, - } - - trdata := []*v1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-1", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: v1.NamespacedTaskKind, - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ns", - Name: "tr0-2", - Labels: map[string]string{ - // TaskRun associated with ClusterTask will - // have both task and clusterTask labels: - // https://github.com/tektoncd/pipeline/issues/2533 - "tekton.dev/clusterTask": "random", - "tekton.dev/task": "random", - }, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - CompletionTime: &metav1.Time{ - Time: time.Now(), - }, - }, - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - } - - trs := trdata - cs, _ := test.SeedTestData(t, pipelinetest.Data{TaskRuns: trs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"taskrun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredT(tasks[0], version), - cb.UnstructuredTR(trdata[0], version), - cb.UnstructuredTR(trdata[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Dynamic: dc} - taskrun := Command(p) - // Run tkn taskrun delete --task random to delete on kind Task random's TaskRuns - _, err = test.ExecuteCommand(taskrun, "delete", "--clustertask", "random", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - - // Expect TaskRun from kind ClusterTask random remains after deletion - expected := `NAME STARTED DURATION STATUS -tr0-1 --- --- Succeeded -` - // Run list command to confirm TaskRun still present - out, err := test.ExecuteCommand(taskrun, "list", "-n", "ns") - if err != nil { - t.Errorf("no error expected but received error: %v", err) - } - test.AssertOutput(t, expected, out) -} - func Test_TaskRuns_Delete_With_Running_PipelineRun_v1beta1(t *testing.T) { clock := test.FakeClock() diff --git a/pkg/cmd/taskrun/list.go b/pkg/cmd/taskrun/list.go index 33d9992e79..b7840d8ac0 100644 --- a/pkg/cmd/taskrun/list.go +++ b/pkg/cmd/taskrun/list.go @@ -193,7 +193,7 @@ func list(p cli.Params, task string, limit int, labelselector string, allnamespa return nil, err } - // this is required as the same label is getting added for both task and ClusterTask + // this is required as the same label is getting added for task if task != "" { trs.Items = taskpkg.FilterByRef(trs.Items, string(v1.NamespacedTaskKind)) } diff --git a/pkg/cmd/taskrun/list_test.go b/pkg/cmd/taskrun/list_test.go index 91ebb154ac..d8b7f587aa 100644 --- a/pkg/cmd/taskrun/list_test.go +++ b/pkg/cmd/taskrun/list_test.go @@ -167,29 +167,6 @@ func TestListTaskRuns_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "tr4-1", - Labels: map[string]string{"tekton.dev/task": "bar", "pot": "honey"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "bar", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionFalse, - Reason: v1beta1.TaskRunReasonFailed.String(), - }, - }, - }, - }, - }, } trsMultipleNs := []*v1beta1.TaskRun{ @@ -239,29 +216,6 @@ func TestListTaskRuns_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "lacher", - Name: "tr5-1", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "random", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, } ns := []*corev1.Namespace{ @@ -283,10 +237,8 @@ func TestListTaskRuns_v1beta1(t *testing.T) { cb.UnstructuredV1beta1TR(trs[2], versionv1beta1), cb.UnstructuredV1beta1TR(trs[3], versionv1beta1), cb.UnstructuredV1beta1TR(trs[4], versionv1beta1), - cb.UnstructuredV1beta1TR(trs[5], versionv1beta1), cb.UnstructuredV1beta1TR(trsMultipleNs[0], versionv1beta1), cb.UnstructuredV1beta1TR(trsMultipleNs[1], versionv1beta1), - cb.UnstructuredV1beta1TR(trsMultipleNs[2], versionv1beta1), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -295,7 +247,6 @@ func TestListTaskRuns_v1beta1(t *testing.T) { dc2, err := tdc2.Client( cb.UnstructuredV1beta1TR(trsMultipleNs[0], versionv1beta1), cb.UnstructuredV1beta1TR(trsMultipleNs[1], versionv1beta1), - cb.UnstructuredV1beta1TR(trsMultipleNs[2], versionv1beta1), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -609,29 +560,6 @@ func TestListTaskRuns(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "tr4-1", - Labels: map[string]string{"tekton.dev/task": "bar", "pot": "honey"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "bar", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionFalse, - Reason: v1.TaskRunReasonFailed.String(), - }, - }, - }, - }, - }, } trsMultipleNs := []*v1.TaskRun{ @@ -681,29 +609,6 @@ func TestListTaskRuns(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "lacher", - Name: "tr5-1", - Labels: map[string]string{"tekton.dev/task": "random"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "random", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - }, - }, } ns := []*corev1.Namespace{ @@ -725,10 +630,10 @@ func TestListTaskRuns(t *testing.T) { cb.UnstructuredTR(trs[2], version), cb.UnstructuredTR(trs[3], version), cb.UnstructuredTR(trs[4], version), - cb.UnstructuredTR(trs[5], version), + // cb.UnstructuredTR(trs[5], version), cb.UnstructuredTR(trsMultipleNs[0], version), cb.UnstructuredTR(trsMultipleNs[1], version), - cb.UnstructuredTR(trsMultipleNs[2], version), + // cb.UnstructuredTR(trsMultipleNs[2], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -737,7 +642,7 @@ func TestListTaskRuns(t *testing.T) { dc2, err := tdc2.Client( cb.UnstructuredTR(trsMultipleNs[0], version), cb.UnstructuredTR(trsMultipleNs[1], version), - cb.UnstructuredTR(trsMultipleNs[2], version), + // cb.UnstructuredTR(trsMultipleNs[2], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-all_in_namespace.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-all_in_namespace.golden index 1dd3d53157..19d6b3162d 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-all_in_namespace.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-all_in_namespace.golden @@ -1,7 +1,6 @@ NAME STARTED DURATION STATUS tr0-1 --- --- Succeeded tr3-1 --- --- Failed -tr4-1 --- --- Failed tr2-2 59 minutes ago 1m0s Failed tr1-1 1 hour ago 1m0s Succeeded tr2-1 1 hour ago --- Running diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden index c3079a92ed..e091c84edf 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden @@ -1,6 +1,5 @@ taskrun.tekton.dev/tr0-1 taskrun.tekton.dev/tr3-1 -taskrun.tekton.dev/tr4-1 taskrun.tekton.dev/tr2-2 taskrun.tekton.dev/tr1-1 taskrun.tekton.dev/tr2-1 diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label.golden index 77817ffe9d..0794a70777 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label.golden @@ -1,3 +1,2 @@ NAME STARTED DURATION STATUS tr3-1 --- --- Failed -tr4-1 --- --- Failed diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label_with_in_query.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label_with_in_query.golden index ab06a9d8d2..6ef703dfde 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label_with_in_query.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-filter_taskruns_by_label_with_in_query.golden @@ -1,4 +1,3 @@ NAME STARTED DURATION STATUS tr3-1 --- --- Failed -tr4-1 --- --- Failed tr2-2 59 minutes ago 1m0s Failed diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-limit_taskruns_greater_than_maximum_case.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-limit_taskruns_greater_than_maximum_case.golden index 1dd3d53157..19d6b3162d 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-limit_taskruns_greater_than_maximum_case.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-limit_taskruns_greater_than_maximum_case.golden @@ -1,7 +1,6 @@ NAME STARTED DURATION STATUS tr0-1 --- --- Succeeded tr3-1 --- --- Failed -tr4-1 --- --- Failed tr2-2 59 minutes ago 1m0s Failed tr1-1 1 hour ago 1m0s Succeeded tr2-1 1 hour ago --- Running diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_by_template.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_by_template.golden index d25a8e820b..6f4e57dbc6 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_by_template.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_by_template.golden @@ -1,6 +1,5 @@ tr0-1 tr3-1 -tr4-1 tr2-2 tr1-1 tr2-1 diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse.golden index 5780ec6ff3..7da5765267 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse.golden @@ -2,6 +2,5 @@ NAME STARTED DURATION STATUS tr2-1 1 hour ago --- Running tr1-1 1 hour ago 1m0s Succeeded tr2-2 59 minutes ago 1m0s Failed -tr4-1 --- --- Failed tr3-1 --- --- Failed tr0-1 --- --- Succeeded diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse_with_output_flag.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse_with_output_flag.golden index 94a151f725..2725fa1a8a 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse_with_output_flag.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_in_reverse_with_output_flag.golden @@ -1,6 +1,5 @@ tr2-1 tr1-1 tr2-2 -tr4-1 tr3-1 tr0-1 diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces.golden index 6763f06f65..24ba423004 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces.golden @@ -1,4 +1,3 @@ NAMESPACE NAME STARTED DURATION STATUS lacher tr4-2 --- --- Succeeded -lacher tr5-1 --- --- Succeeded tout tr4-1 --- --- Succeeded diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces_without_headers.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces_without_headers.golden index 1fbfa7235f..334a2513df 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces_without_headers.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-print_taskruns_in_all_namespaces_without_headers.golden @@ -1,3 +1,2 @@ lacher tr4-2 --- --- Succeeded -lacher tr5-1 --- --- Succeeded tout tr4-1 --- --- Succeeded diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-all_in_namespace.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-all_in_namespace.golden index 1dd3d53157..19d6b3162d 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-all_in_namespace.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-all_in_namespace.golden @@ -1,7 +1,6 @@ NAME STARTED DURATION STATUS tr0-1 --- --- Succeeded tr3-1 --- --- Failed -tr4-1 --- --- Failed tr2-2 59 minutes ago 1m0s Failed tr1-1 1 hour ago 1m0s Succeeded tr2-1 1 hour ago --- Running diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-by_output_as_name.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-by_output_as_name.golden index c3079a92ed..e091c84edf 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-by_output_as_name.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-by_output_as_name.golden @@ -1,6 +1,5 @@ taskrun.tekton.dev/tr0-1 taskrun.tekton.dev/tr3-1 -taskrun.tekton.dev/tr4-1 taskrun.tekton.dev/tr2-2 taskrun.tekton.dev/tr1-1 taskrun.tekton.dev/tr2-1 diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label.golden index 77817ffe9d..0794a70777 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label.golden @@ -1,3 +1,2 @@ NAME STARTED DURATION STATUS tr3-1 --- --- Failed -tr4-1 --- --- Failed diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label_with_in_query.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label_with_in_query.golden index ab06a9d8d2..6ef703dfde 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label_with_in_query.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-filter_taskruns_by_label_with_in_query.golden @@ -1,4 +1,3 @@ NAME STARTED DURATION STATUS tr3-1 --- --- Failed -tr4-1 --- --- Failed tr2-2 59 minutes ago 1m0s Failed diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-limit_taskruns_greater_than_maximum_case.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-limit_taskruns_greater_than_maximum_case.golden index 1dd3d53157..19d6b3162d 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-limit_taskruns_greater_than_maximum_case.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-limit_taskruns_greater_than_maximum_case.golden @@ -1,7 +1,6 @@ NAME STARTED DURATION STATUS tr0-1 --- --- Succeeded tr3-1 --- --- Failed -tr4-1 --- --- Failed tr2-2 59 minutes ago 1m0s Failed tr1-1 1 hour ago 1m0s Succeeded tr2-1 1 hour ago --- Running diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_by_template.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_by_template.golden index d25a8e820b..6f4e57dbc6 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_by_template.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_by_template.golden @@ -1,6 +1,5 @@ tr0-1 tr3-1 -tr4-1 tr2-2 tr1-1 tr2-1 diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse.golden index 5780ec6ff3..7da5765267 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse.golden @@ -2,6 +2,5 @@ NAME STARTED DURATION STATUS tr2-1 1 hour ago --- Running tr1-1 1 hour ago 1m0s Succeeded tr2-2 59 minutes ago 1m0s Failed -tr4-1 --- --- Failed tr3-1 --- --- Failed tr0-1 --- --- Succeeded diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse_with_output_flag.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse_with_output_flag.golden index 94a151f725..2725fa1a8a 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse_with_output_flag.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_in_reverse_with_output_flag.golden @@ -1,6 +1,5 @@ tr2-1 tr1-1 tr2-2 -tr4-1 tr3-1 tr0-1 diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces.golden index 6763f06f65..24ba423004 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces.golden @@ -1,4 +1,3 @@ NAMESPACE NAME STARTED DURATION STATUS lacher tr4-2 --- --- Succeeded -lacher tr5-1 --- --- Succeeded tout tr4-1 --- --- Succeeded diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces_without_headers.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces_without_headers.golden index 1fbfa7235f..334a2513df 100644 --- a/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces_without_headers.golden +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns_v1beta1-print_taskruns_in_all_namespaces_without_headers.golden @@ -1,3 +1,2 @@ lacher tr4-2 --- --- Succeeded -lacher tr5-1 --- --- Succeeded tout tr4-1 --- --- Succeeded diff --git a/pkg/cmd/testdata/TestPluginList.golden b/pkg/cmd/testdata/TestPluginList.golden index d97cca9cb0..0e6176306a 100644 --- a/pkg/cmd/testdata/TestPluginList.golden +++ b/pkg/cmd/testdata/TestPluginList.golden @@ -8,7 +8,6 @@ tkn [command] Available Commands: bundle* Manage Tekton Bundles (experimental) chain Manage Chains - clustertask Manage ClusterTasks clustertriggerbinding Manage ClusterTriggerBindings customrun Manage CustomRuns eventlistener Manage EventListeners diff --git a/pkg/options/describe.go b/pkg/options/describe.go index f6f75c2675..721841f9e6 100644 --- a/pkg/options/describe.go +++ b/pkg/options/describe.go @@ -33,7 +33,6 @@ type DescribeOptions struct { Params cli.Params PipelineName string PipelineRunName string - ClusterTaskName string TaskName string TaskrunName string Tasks []string @@ -89,8 +88,6 @@ func (opts *DescribeOptions) Ask(resource string, options []string) error { opts.PipelineName = ans case ResourceNamePipelineRun: opts.PipelineRunName = strings.Fields(ans)[0] - case ResourceNameClusterTask: - opts.ClusterTaskName = ans case ResourceNameTask: opts.TaskName = ans case ResourceNameTaskRun: diff --git a/pkg/options/describe_test.go b/pkg/options/describe_test.go index e7f89df449..f69f3bb45a 100644 --- a/pkg/options/describe_test.go +++ b/pkg/options/describe_test.go @@ -65,55 +65,49 @@ func TestDescribeOptions_ValidateOpts(t *testing.T) { } func TestDescribeOptions_Ask(t *testing.T) { - options := []string{ + pipelineOptions := []string{ "pipeline1", "pipeline2", "pipeline3", } - options2 := []string{ + pipelineRunOptions := []string{ "sample-pipeline-run1 started 1 minutes ago", "sample-pipeline-run2 started 2 minutes ago", "sample-pipeline-run3 started 3 minutes ago", } - options3 := []string{ + taskOptions := []string{ "task1", "task2", "task3", } - options4 := []string{ + taskRunOptions := []string{ "sample-task-run1 started 1 minutes ago", "sample-task-run2 started 2 minutes ago", "sample-task-run3 started 3 minutes ago", } - options6 := []string{ - "clustertask1", - "clustertask2", - "clustertask3", - } - - options7 := []string{ + eventListenerOptions := []string{ "eventlistener1", "eventlistener2", "eventlistener3", } - options8 := []string{ + triggerTemplateOptions := []string{ "triggertemplate1", "triggertemplate2", "triggertemplate3", } - options9 := []string{ + triggerBindingOptions := []string{ "triggerbinding1", "triggerbinding2", "triggerbinding3", } - options10 := []string{ + clusterTriggerBindingOptions := []string{ "clustertriggerbinding1", "clustertriggerbinding2", "clustertriggerbinding3", @@ -135,19 +129,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select pipelinerun:"); err != nil { return err } - if _, err := c.SendLine(options2[0]); err != nil { + if _, err := c.SendLine(pipelineRunOptions[0]); err != nil { return err } return nil }, }, - options: options2, + options: pipelineRunOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "sample-pipeline-run1", TaskName: "", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -163,19 +156,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select pipelinerun:"); err != nil { return err } - if _, err := c.SendLine(options2[2]); err != nil { + if _, err := c.SendLine(pipelineRunOptions[2]); err != nil { return err } return nil }, }, - options: options2, + options: pipelineRunOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "sample-pipeline-run3", TaskName: "", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -191,19 +183,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select taskrun:"); err != nil { return err } - if _, err := c.SendLine(options4[0]); err != nil { + if _, err := c.SendLine(taskRunOptions[0]); err != nil { return err } return nil }, }, - options: options4, + options: taskRunOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "", TaskrunName: "sample-task-run1", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -219,19 +210,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select taskrun:"); err != nil { return err } - if _, err := c.SendLine(options4[2]); err != nil { + if _, err := c.SendLine(taskRunOptions[2]); err != nil { return err } return nil }, }, - options: options4, + options: taskRunOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "", TaskrunName: "sample-task-run3", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -247,19 +237,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select task:"); err != nil { return err } - if _, err := c.SendLine(options3[0]); err != nil { + if _, err := c.SendLine(taskOptions[0]); err != nil { return err } return nil }, }, - options: options3, + options: taskOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "task1", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -275,19 +264,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select task:"); err != nil { return err } - if _, err := c.SendLine(options3[2]); err != nil { + if _, err := c.SendLine(taskOptions[2]); err != nil { return err } return nil }, }, - options: options3, + options: taskOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "task3", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -303,19 +291,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select pipeline:"); err != nil { return err } - if _, err := c.SendLine(options[0]); err != nil { + if _, err := c.SendLine(pipelineOptions[0]); err != nil { return err } return nil }, }, - options: options, + options: pipelineOptions, want: DescribeOptions{ PipelineName: "pipeline1", PipelineRunName: "", TaskName: "", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -331,80 +318,24 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select pipeline:"); err != nil { return err } - if _, err := c.SendLine(options[2]); err != nil { + if _, err := c.SendLine(pipelineOptions[2]); err != nil { return err } return nil }, }, - options: options, + options: pipelineOptions, want: DescribeOptions{ PipelineName: "pipeline3", PipelineRunName: "", TaskName: "", TaskrunName: "", - ClusterTaskName: "", - TriggerTemplateName: "", - TriggerBindingName: "", - ClusterTriggerBindingName: "", - EventListenerName: "", - }, - }, - { - name: "select clustertask name", - resource: ResourceNameClusterTask, - prompt: prompt.Prompt{ - CmdArgs: []string{}, - Procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Select clustertask:"); err != nil { - return err - } - if _, err := c.SendLine(options6[0]); err != nil { - return err - } - return nil - }, - }, - options: options6, - want: DescribeOptions{ - PipelineName: "", - PipelineRunName: "", - TaskName: "", - TaskrunName: "", - ClusterTaskName: "clustertask1", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "", EventListenerName: "", }, }, - { - name: "select clustertask name option 3", - resource: ResourceNameClusterTask, - prompt: prompt.Prompt{ - CmdArgs: []string{}, - Procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Select clustertask:"); err != nil { - return err - } - if _, err := c.SendLine(options6[2]); err != nil { - return err - } - return nil - }, - }, - options: options6, - want: DescribeOptions{ - PipelineName: "", - PipelineRunName: "", - TaskName: "", - TaskrunName: "", - ClusterTaskName: "clustertask3", - TriggerTemplateName: "", - ClusterTriggerBindingName: "", - EventListenerName: "", - }, - }, { name: "select triggertemplate name option 3", resource: ResourceNameTriggerTemplate, @@ -414,19 +345,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select triggertemplate:"); err != nil { return err } - if _, err := c.SendLine(options8[2]); err != nil { + if _, err := c.SendLine(triggerTemplateOptions[2]); err != nil { return err } return nil }, }, - options: options8, + options: triggerTemplateOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "triggertemplate3", TriggerBindingName: "", ClusterTriggerBindingName: "", @@ -442,19 +372,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select triggerbinding:"); err != nil { return err } - if _, err := c.SendLine(options9[2]); err != nil { + if _, err := c.SendLine(triggerBindingOptions[2]); err != nil { return err } return nil }, }, - options: options9, + options: triggerBindingOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "triggerbinding3", ClusterTriggerBindingName: "", @@ -470,19 +399,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select clustertriggerbinding:"); err != nil { return err } - if _, err := c.SendLine(options10[2]); err != nil { + if _, err := c.SendLine(clusterTriggerBindingOptions[2]); err != nil { return err } return nil }, }, - options: options10, + options: clusterTriggerBindingOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "", TaskrunName: "", - ClusterTaskName: "", TriggerTemplateName: "", TriggerBindingName: "", ClusterTriggerBindingName: "clustertriggerbinding3", @@ -498,19 +426,18 @@ func TestDescribeOptions_Ask(t *testing.T) { if _, err := c.ExpectString("Select eventlistener:"); err != nil { return err } - if _, err := c.SendLine(options7[2]); err != nil { + if _, err := c.SendLine(eventListenerOptions[2]); err != nil { return err } return nil }, }, - options: options7, + options: eventListenerOptions, want: DescribeOptions{ PipelineName: "", PipelineRunName: "", TaskName: "", TaskrunName: "", - ClusterTaskName: "", EventListenerName: "eventlistener3", }, }, @@ -547,9 +474,6 @@ func TestDescribeOptions_Ask(t *testing.T) { if opts.ClusterTriggerBindingName != tp.want.ClusterTriggerBindingName { t.Errorf("Unexpected ClusterTriggerBinding Name") } - if opts.ClusterTaskName != tp.want.ClusterTaskName { - t.Errorf("Unexpected ClusterTask Name") - } if opts.EventListenerName != tp.want.EventListenerName { t.Errorf("Unexpected EventListener Name") } diff --git a/pkg/options/logs.go b/pkg/options/logs.go index 8e353570b6..19090eb04c 100644 --- a/pkg/options/logs.go +++ b/pkg/options/logs.go @@ -38,7 +38,6 @@ type LogOptions struct { PipelineName string PipelineRunName string TaskName string - ClusterTaskName string TaskrunName string Stream *cli.Stream Streamer stream.NewStreamerFunc @@ -100,8 +99,6 @@ func (opts *LogOptions) Ask(resource string, options []string) error { opts.PipelineRunName = strings.Fields(ans)[0] case ResourceNameTask: opts.TaskName = ans - case ResourceNameClusterTask: - opts.ClusterTaskName = ans case ResourceNameTaskRun: opts.TaskrunName = strings.Fields(ans)[0] } @@ -161,8 +158,6 @@ func (opts *LogOptions) FuzzyAsk(resource string, options []string) error { opts.PipelineRunName = strings.Fields(ans)[0] case ResourceNameTask: opts.TaskName = ans - case ResourceNameClusterTask: - opts.ClusterTaskName = ans case ResourceNameTaskRun: opts.TaskrunName = strings.Fields(ans)[0] } diff --git a/pkg/options/logs_test.go b/pkg/options/logs_test.go index f62c624c5e..b6e56697ff 100644 --- a/pkg/options/logs_test.go +++ b/pkg/options/logs_test.go @@ -86,12 +86,6 @@ func TestLogOptions_Ask(t *testing.T) { "sample-task-run2 started 2 minutes ago", "sample-task-run3 started 3 minutes ago", } - options5 := []string{ - "clustertask1", - "clustertask2", - "clustertask3", - } - testParams := []struct { name string resource string @@ -119,7 +113,6 @@ func TestLogOptions_Ask(t *testing.T) { PipelineName: "pipeline1", PipelineRunName: "", TaskName: "", - ClusterTaskName: "", TaskrunName: "", }, }, @@ -143,7 +136,6 @@ func TestLogOptions_Ask(t *testing.T) { PipelineName: "", PipelineRunName: "sample-pipeline-run1", TaskName: "", - ClusterTaskName: "", TaskrunName: "", }, }, @@ -167,7 +159,6 @@ func TestLogOptions_Ask(t *testing.T) { PipelineName: "", PipelineRunName: "", TaskName: "task1", - ClusterTaskName: "", TaskrunName: "", }, }, @@ -191,34 +182,9 @@ func TestLogOptions_Ask(t *testing.T) { PipelineName: "", PipelineRunName: "", TaskName: "", - ClusterTaskName: "", TaskrunName: "sample-task-run1", }, }, - { - name: "select clustertask name", - resource: ResourceNameClusterTask, - prompt: prompt.Prompt{ - CmdArgs: []string{}, - Procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Select clustertask:"); err != nil { - return err - } - if _, err := c.SendLine(options5[0]); err != nil { - return err - } - return nil - }, - }, - options: options5, - want: LogOptions{ - PipelineName: "", - PipelineRunName: "", - TaskName: "", - ClusterTaskName: "clustertask1", - TaskrunName: "", - }, - }, } for _, tp := range testParams { @@ -240,9 +206,6 @@ func TestLogOptions_Ask(t *testing.T) { if opts.TaskrunName != tp.want.TaskrunName { t.Errorf("Unexpected TaskRun Name") } - if opts.ClusterTaskName != tp.want.ClusterTaskName { - t.Errorf("Unexpected ClusterTask Name") - } }) } } diff --git a/pkg/options/resource_names.go b/pkg/options/resource_names.go index d94cfc589f..ae017cc5ce 100644 --- a/pkg/options/resource_names.go +++ b/pkg/options/resource_names.go @@ -5,7 +5,6 @@ const ( ResourceNamePipelineRun = "pipelinerun" ResourceNameTask = "task" ResourceNameTaskRun = "taskrun" - ResourceNameClusterTask = "clustertask" ResourceNameTriggerTemplate = "triggertemplate" ResourceNameTriggerBinding = "triggerbinding" ResourceNameClusterTriggerBinding = "clustertriggerbinding" diff --git a/pkg/options/start.go b/pkg/options/start.go index c6836dc051..e3453e5f2f 100644 --- a/pkg/options/start.go +++ b/pkg/options/start.go @@ -201,132 +201,6 @@ func (intOpts *InteractiveOpts) TaskWorkspaces(task *v1beta1.Task) error { return nil } -func (intOpts *InteractiveOpts) ClusterTaskParams(clustertask *v1beta1.ClusterTask, skipParams map[string]string, useParamDefaults bool) error { - for _, param := range clustertask.Spec.Params { - if param.Default == nil && useParamDefaults || !useParamDefaults { - if _, toSkip := skipParams[param.Name]; toSkip { - continue - } - var ans, ques, defaultValue string - ques = fmt.Sprintf("Value for param `%s` of type `%s`?", param.Name, param.Type) - input := &survey.Input{} - if param.Default != nil { - if param.Type == "string" { - defaultValue = param.Default.StringVal - } - if param.Type == "array" { - defaultValue = strings.Join(param.Default.ArrayVal, ",") - } - if param.Type == "object" { - defaultValue = fmt.Sprintf("%+v", param.Default.ObjectVal) - } - ques += fmt.Sprintf(" (Default is `%s`)", defaultValue) - input.Default = defaultValue - } - input.Message = ques - - var qs = []*survey.Question{ - { - Name: "clustertask param", - Prompt: input, - }, - } - - if err := survey.Ask(qs, &ans, intOpts.AskOpts); err != nil { - return err - } - - intOpts.Params = append(intOpts.Params, param.Name+"="+ans) - } - - } - return nil -} - -func (intOpts *InteractiveOpts) ClusterTaskWorkspaces(clustertask *v1beta1.ClusterTask) error { - for _, ws := range clustertask.Spec.Workspaces { - if ws.Optional && intOpts.SkipOptionalWorkspace { - continue - } - if ws.Optional { - isOptional, err := askParam(fmt.Sprintf("Do you want to give specifications for the optional workspace `%s`: (y/N)", ws.Name), intOpts.AskOpts) - if err != nil { - return err - } - if strings.ToLower(isOptional) == "n" { - continue - } - } - fmt.Fprintf(intOpts.Stream.Out, "Please give specifications for the workspace: %s \n", ws.Name) - name, err := askParam("Name for the workspace:", intOpts.AskOpts) - if err != nil { - return err - } - workspace := "name=" + name - subPath, err := askParam("Value of the Sub Path:", intOpts.AskOpts, " ") - if err != nil { - return err - } - if subPath != " " { - workspace = workspace + ",subPath=" + subPath - } - - var kind string - var qs = []*survey.Question{ - { - Name: "workspace param", - Prompt: &survey.Select{ - Message: "Type of the Workspace:", - Options: []string{"config", "emptyDir", "secret", "pvc"}, - Default: "emptyDir", - }, - }, - } - if err := survey.Ask(qs, &kind, intOpts.AskOpts); err != nil { - return err - } - switch kind { - case "pvc": - claimName, err := askParam("Value of Claim Name:", intOpts.AskOpts) - if err != nil { - return err - } - workspace = workspace + ",claimName=" + claimName - case "emptyDir": - kind, err := askParam("Type of EmptyDir:", intOpts.AskOpts, "") - if err != nil { - return err - } - workspace = workspace + ",emptyDir=" + kind - case "config": - config, err := askParam("Name of the configmap:", intOpts.AskOpts) - if err != nil { - return err - } - workspace = workspace + ",config=" + config - items, err := getItems(intOpts.AskOpts) - if err != nil { - return err - } - workspace += items - case "secret": - secret, err := askParam("Name of the secret:", intOpts.AskOpts) - if err != nil { - return err - } - workspace = workspace + ",secret=" + secret - items, err := getItems(intOpts.AskOpts) - if err != nil { - return err - } - workspace += items - } - intOpts.Workspaces = append(intOpts.Workspaces, workspace) - - } - return nil -} - func getItems(askOpts survey.AskOpt) (string, error) { var items string for { diff --git a/pkg/task/tasklastrun.go b/pkg/task/tasklastrun.go index 1357dce72d..25c4d426d1 100644 --- a/pkg/task/tasklastrun.go +++ b/pkg/task/tasklastrun.go @@ -26,7 +26,7 @@ import ( var taskrunGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "taskruns"} -// LastRun returns the name of last taskrun for a given task/clustertask +// LastRun returns the name of last taskrun for a given task func LastRunName(cs *cli.Clients, resourceName, ns, kind string) (string, error) { latest, err := LastRun(cs, resourceName, ns, kind) if err != nil { @@ -35,15 +35,11 @@ func LastRunName(cs *cli.Clients, resourceName, ns, kind string) (string, error) return latest.Name, nil } -// LastRun returns the last taskrun for a given task/clustertask +// LastRun returns the last taskrun for a given task func LastRun(cs *cli.Clients, resourceName, ns, kind string) (*v1.TaskRun, error) { options := metav1.ListOptions{} - // change the label value to clusterTask if the resource is ClusterTask label := "task" - if kind == "ClusterTask" { - label = "clusterTask" - } if resourceName != "" { options = metav1.ListOptions{ @@ -74,7 +70,7 @@ func LastRun(cs *cli.Clients, resourceName, ns, kind string) (*v1.TaskRun, error return &latest, nil } -// this will filter the taskrun which have reference to Task or ClusterTask +// this will filter the taskrun which have reference to Task func FilterByRef(taskruns []v1.TaskRun, kind string) []v1.TaskRun { var filtered []v1.TaskRun for _, taskrun := range taskruns { diff --git a/pkg/task/tasklastrun_test.go b/pkg/task/tasklastrun_test.go index e029ea2913..48c6fde023 100644 --- a/pkg/task/tasklastrun_test.go +++ b/pkg/task/tasklastrun_test.go @@ -98,34 +98,6 @@ func TestTaskrunLatestName_two_run_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, } cs, _ := test.SeedV1beta1TestData(t, test.Data{ TaskRuns: taskruns, @@ -135,7 +107,6 @@ func TestTaskrunLatestName_two_run_v1beta1(t *testing.T) { dc, _ := tdc.Client( cb.UnstructuredV1beta1TR(taskruns[0], "v1beta1"), cb.UnstructuredV1beta1TR(taskruns[1], "v1beta1"), - cb.UnstructuredV1beta1TR(taskruns[2], "v1beta1"), ) p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Dynamic: dc} client, err := p.Clients() @@ -220,34 +191,6 @@ func TestTaskrunLatest_two_run_v1beta1(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, } cs, _ := test.SeedV1beta1TestData(t, test.Data{ TaskRuns: taskruns, @@ -257,7 +200,6 @@ func TestTaskrunLatest_two_run_v1beta1(t *testing.T) { dc, _ := tdc.Client( cb.UnstructuredV1beta1TR(taskruns[0], "v1beta1"), cb.UnstructuredV1beta1TR(taskruns[1], "v1beta1"), - cb.UnstructuredV1beta1TR(taskruns[2], "v1beta1"), ) p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Dynamic: dc} client, err := p.Clients() @@ -295,128 +237,6 @@ func TestTaskrunLatest_no_run_v1beta1(t *testing.T) { test.AssertOutput(t, expected, err.Error()) } -func TestTaskrunLatestForClusterTask_two_run_v1beta1(t *testing.T) { - clock := test.FakeClock() - - var ( - firstRunCreated = clock.Now().Add(10 * time.Minute) - firstRunStarted = firstRunCreated.Add(2 * time.Second) - firstRunCompleted = firstRunStarted.Add(10 * time.Minute) - - secondRunCreated = firstRunCreated.Add(1 * time.Minute) - secondRunStarted = secondRunCreated.Add(2 * time.Second) - secondRunCompleted = secondRunStarted.Add(5 * time.Minute) - ) - taskruns := []*v1beta1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-1", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: firstRunCreated}, - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: firstRunStarted}, - CompletionTime: &metav1.Time{Time: firstRunCompleted}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-2", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - Labels: map[string]string{"tekton.dev/clusterTask": "task", "tekton.dev/task": "task"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.ClusterTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - Labels: map[string]string{"tekton.dev/task": "task"}, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task", - Kind: v1beta1.NamespacedTaskKind, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, test.Data{ - TaskRuns: taskruns, - }) - cs.Pipeline.Resources = cb.APIResourceList("v1beta1", []string{"taskrun"}) - tdc := testDynamic.Options{} - dc, _ := tdc.Client( - cb.UnstructuredV1beta1TR(taskruns[0], "v1beta1"), - cb.UnstructuredV1beta1TR(taskruns[1], "v1beta1"), - cb.UnstructuredV1beta1TR(taskruns[2], "v1beta1"), - ) - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Dynamic: dc} - client, err := p.Clients() - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - lastRun, err := LastRun(client, "task", "ns", "ClusterTask") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - test.AssertOutput(t, "tr-2", lastRun.Name) -} - func TestTaskrunLatestName_two_run(t *testing.T) { clock := test.FakeClock() @@ -486,34 +306,6 @@ func TestTaskrunLatestName_two_run(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "task", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{ TaskRuns: taskruns, @@ -523,7 +315,6 @@ func TestTaskrunLatestName_two_run(t *testing.T) { dc, _ := tdc.Client( cb.UnstructuredTR(taskruns[0], "v1"), cb.UnstructuredTR(taskruns[1], "v1"), - cb.UnstructuredTR(taskruns[2], "v1"), ) p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Dynamic: dc} client, err := p.Clients() @@ -608,34 +399,6 @@ func TestTaskrunLatest_two_run(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "task", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{ TaskRuns: taskruns, @@ -645,7 +408,6 @@ func TestTaskrunLatest_two_run(t *testing.T) { dc, _ := tdc.Client( cb.UnstructuredTR(taskruns[0], "v1"), cb.UnstructuredTR(taskruns[1], "v1"), - cb.UnstructuredTR(taskruns[2], "v1"), ) p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Dynamic: dc} client, err := p.Clients() @@ -683,128 +445,6 @@ func TestTaskrunLatest_no_run(t *testing.T) { test.AssertOutput(t, expected, err.Error()) } -func TestTaskrunLatestForClusterTask_two_run(t *testing.T) { - clock := test.FakeClock() - - var ( - firstRunCreated = clock.Now().Add(10 * time.Minute) - firstRunStarted = firstRunCreated.Add(2 * time.Second) - firstRunCompleted = firstRunStarted.Add(10 * time.Minute) - - secondRunCreated = firstRunCreated.Add(1 * time.Minute) - secondRunStarted = secondRunCreated.Add(2 * time.Second) - secondRunCompleted = secondRunStarted.Add(5 * time.Minute) - ) - taskruns := []*v1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-1", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: firstRunCreated}, - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "task", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: firstRunStarted}, - CompletionTime: &metav1.Time{Time: firstRunCompleted}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-2", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - Labels: map[string]string{"tekton.dev/clusterTask": "task", "tekton.dev/task": "task"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "task", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - Labels: map[string]string{"tekton.dev/task": "task"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "task", - Kind: v1.NamespacedTaskKind, - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{ - TaskRuns: taskruns, - }) - cs.Pipeline.Resources = cb.APIResourceList("v1", []string{"taskrun"}) - tdc := testDynamic.Options{} - dc, _ := tdc.Client( - cb.UnstructuredTR(taskruns[0], "v1"), - cb.UnstructuredTR(taskruns[1], "v1"), - cb.UnstructuredTR(taskruns[2], "v1"), - ) - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Dynamic: dc} - client, err := p.Clients() - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - lastRun, err := LastRun(client, "task", "ns", "ClusterTask") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - test.AssertOutput(t, "tr-2", lastRun.Name) -} - func TestFilterByRef(t *testing.T) { clock := test.FakeClock() @@ -812,10 +452,6 @@ func TestFilterByRef(t *testing.T) { firstRunCreated = clock.Now().Add(10 * time.Minute) firstRunStarted = firstRunCreated.Add(2 * time.Second) firstRunCompleted = firstRunStarted.Add(10 * time.Minute) - - secondRunCreated = firstRunCreated.Add(1 * time.Minute) - secondRunStarted = secondRunCreated.Add(2 * time.Second) - secondRunCompleted = secondRunStarted.Add(5 * time.Minute) ) taskruns := []v1.TaskRun{ { @@ -846,41 +482,8 @@ func TestFilterByRef(t *testing.T) { }, }, }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-2", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: secondRunCompleted}, - Labels: map[string]string{"tekton.dev/clusterTask": "task"}, - }, - Spec: v1.TaskRunSpec{ - TaskRef: &v1.TaskRef{ - Name: "task", - Kind: "ClusterTask", - }, - }, - Status: v1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1.TaskRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: secondRunStarted}, - CompletionTime: &metav1.Time{Time: secondRunCompleted}, - }, - }, - }, } - filteredClusterTask := FilterByRef(taskruns, "ClusterTask") - - test.AssertOutput(t, "tr-2", filteredClusterTask[0].Name) - filteredTask := FilterByRef(taskruns, "Task") - test.AssertOutput(t, "tr-1", filteredTask[0].Name) } diff --git a/pkg/test/builder/unstructured.go b/pkg/test/builder/unstructured.go index f413523894..a0a3538df9 100644 --- a/pkg/test/builder/unstructured.go +++ b/pkg/test/builder/unstructured.go @@ -103,15 +103,6 @@ func UnstructuredV1beta1T(task *v1beta1.Task, version string) *unstructured.Unst } } -func UnstructuredV1beta1CT(clustertask *v1beta1.ClusterTask, version string) *unstructured.Unstructured { - clustertask.APIVersion = "tekton.dev/" + version - clustertask.Kind = "clustertask" - object, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(clustertask) - return &unstructured.Unstructured{ - Object: object, - } -} - func UnstructuredV1beta1TT(triggertemplate *triggersv1beta1.TriggerTemplate, version string) *unstructured.Unstructured { triggertemplate.APIVersion = "triggers.tekton.dev/" + version triggertemplate.Kind = "TriggerTemplate" diff --git a/pkg/test/controller.go b/pkg/test/controller.go index ef5e575393..daa509266f 100644 --- a/pkg/test/controller.go +++ b/pkg/test/controller.go @@ -22,7 +22,6 @@ import ( fakepipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake" informersv1beta1 "github.com/tektoncd/pipeline/pkg/client/informers/externalversions/pipeline/v1beta1" fakepipelineclient "github.com/tektoncd/pipeline/pkg/client/injection/client/fake" - fakeclustertaskinformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1beta1/clustertask/fake" fakepipelineinformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1beta1/pipeline/fake" fakepipelineruninformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1beta1/pipelinerun/fake" faketaskinformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1beta1/task/fake" @@ -41,7 +40,6 @@ type Data struct { Pipelines []*v1beta1.Pipeline TaskRuns []*v1beta1.TaskRun Tasks []*v1beta1.Task - ClusterTasks []*v1beta1.ClusterTask Namespaces []*corev1.Namespace Pods []*corev1.Pod } @@ -58,7 +56,6 @@ type Informers struct { Pipeline informersv1beta1.PipelineInformer TaskRun informersv1beta1.TaskRunInformer Task informersv1beta1.TaskInformer - ClusterTask informersv1beta1.ClusterTaskInformer Pod coreinformers.PodInformer } @@ -79,7 +76,6 @@ func seedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers Pipeline: fakepipelineinformer.Get(ctx), TaskRun: faketaskruninformer.Get(ctx), Task: faketaskinformer.Get(ctx), - ClusterTask: fakeclustertaskinformer.Get(ctx), Pod: fakefilteredpodinformer.Get(ctx, v1beta1.ManagedByLabelKey), } @@ -114,13 +110,6 @@ func seedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers t.Fatal(err) } } - c.Pipeline.PrependReactor("*", "clustertasks", test.AddToInformer(t, i.ClusterTask.Informer().GetIndexer())) - for _, cta := range d.ClusterTasks { - cta := cta.DeepCopy() // Avoid assumptions that the informer's copy is modified. - if _, err := c.Pipeline.TektonV1beta1().ClusterTasks().Create(ctx, cta, metav1.CreateOptions{}); err != nil { - t.Fatal(err) - } - } c.Kube.PrependReactor("*", "pods", test.AddToInformer(t, i.Pod.Informer().GetIndexer())) for _, p := range d.Pods { p := p.DeepCopy() // Avoid assumptions that the informer's copy is modified. diff --git a/pkg/test/dynamic/clientset/tekton.go b/pkg/test/dynamic/clientset/tekton.go index f3a851134e..756aa629b7 100644 --- a/pkg/test/dynamic/clientset/tekton.go +++ b/pkg/test/dynamic/clientset/tekton.go @@ -22,7 +22,7 @@ import ( ) var allowedTektonTypes = map[string][]string{ - "v1beta1": {"pipelineruns", "taskruns", "pipelines", "clustertasks", "tasks", "conditions", "customruns"}, + "v1beta1": {"pipelineruns", "taskruns", "pipelines", "tasks", "conditions", "customruns"}, "v1": {"pipelineruns", "taskruns", "pipelines", "tasks"}, } diff --git a/pkg/test/dynamic/dynamictestclient.go b/pkg/test/dynamic/dynamictestclient.go index 1e2559609c..47f9b9d405 100644 --- a/pkg/test/dynamic/dynamictestclient.go +++ b/pkg/test/dynamic/dynamictestclient.go @@ -44,7 +44,6 @@ func (opt *Options) Client(objects ...runtime.Object) (dynamic.Interface, error) dynamicClient := fake.NewSimpleDynamicClientWithCustomListKinds( runtime.NewScheme(), map[schema.GroupVersionResource]string{ - {Group: "tekton.dev", Version: "v1beta1", Resource: "clustertasks"}: "ClusterTaskList", {Group: "tekton.dev", Version: "v1beta1", Resource: "tasks"}: "TaskList", {Group: "tekton.dev", Version: "v1beta1", Resource: "taskruns"}: "TaskRunList", {Group: "tekton.dev", Version: "v1beta1", Resource: "customruns"}: "CustomRunList", diff --git a/test/README.md b/test/README.md index acf3ad6abe..a5a23bd420 100644 --- a/test/README.md +++ b/test/README.md @@ -20,32 +20,28 @@ make test-unit 3. Next install Tekton Triggers in the cluster, see [Install Triggers](https://github.com/tektoncd/triggers/blob/main/docs/install.md#installation) -Set environment variable `TEST_CLUSTERTASK_LIST_EMPTY` to any value if tests are run in an environment which contains `clustertasks`. - -```shell -export TEST_CLUSTERTASK_LIST_EMPTY=empty -``` - Set `SYSTEM_NAMESPACE` variable to appropriate value (say tekton-pipelines) based on the namespace where Tekton Pipelines system components reside within the Kubernetes cluster. -```shell +```shell export SYSTEM_NAMESPACE= (eg: export SYSTEM_NAMESPACE=tekton-pipelines) ``` ### Running End to end tests live in [this](../test/e2e/) directory. By default `go test` will not run [the end to end tests](#end-to-end-tests), -it need `-tags=e2e` to be enabled in order to run these tests, hence you must provide `go` with `-tags=e2e`. +it need `-tags=e2e` to be enabled in order to run these tests, hence you must provide `go` with `-tags=e2e`. ```shell go build -o tkn github.com/tektoncd/cli/cmd/tkn -export TEST_CLIENT_BINARY=/tkn ( eg: export TEST_CLIENT_BINARY=$PWD/tkn ) +export TEST_CLIENT_BINARY=/tkn ( eg: export TEST_CLIENT_BINARY=$PWD/tkn ) ``` + By default the tests run against your current kubeconfig context: ```shell go test -v -count=1 -tags=e2e -timeout=20m ./test/e2e/... ``` + You can change the kubeconfig context and other settings with [the flags](#flags). ```shell @@ -85,14 +81,15 @@ the `-run` flag with `go test` go test -v ./test/... -tags=e2e -run ^TestPipelinesE2E ``` -### Prerequisite to run make check and make generated +### Prerequisite to run make check and make generated -Ensure that golangci-lint and yamllint are installed on your development machine. If not then install them following [golangci-lint](https://golangci-lint.run/usage/install/) and [yamllint](https://yamllint.readthedocs.io/en/stable/quickstart.html). +Ensure that golangci-lint and yamllint are installed on your development machine. If not then install them following [golangci-lint](https://golangci-lint.run/welcome/install/) and [yamllint](https://github.com/adrienverge/yamllint/). Next step will be to run + ```bash -# For linting the golang and YAML files +# For linting the golang and YAML files make check # To check diff in goldenfile and [docs](https://github.com/tektoncd/cli/tree/main/docs), update and autogenerate them make generated -``` \ No newline at end of file +``` diff --git a/test/builder/builder.go b/test/builder/builder.go index 1f550c917b..0d17e1f3f9 100644 --- a/test/builder/builder.go +++ b/test/builder/builder.go @@ -35,7 +35,6 @@ import ( taskrunpkg "github.com/tektoncd/cli/pkg/taskrun/sort" "github.com/tektoncd/cli/test/framework" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -49,14 +48,6 @@ func GetTask(c *framework.Clients, name string) *v1.Task { return task } -func GetClusterTask(c *framework.Clients, name string) *v1beta1.ClusterTask { - clustertask, err := c.ClusterTaskClient.Get(context.Background(), name, metav1.GetOptions{}) - if err != nil { - log.Fatalf("Couldn't get expected clustertask %s", err) - } - return clustertask -} - func GetTaskList(c *framework.Clients) *v1.TaskList { tasklist, err := c.TaskClient.List(context.Background(), metav1.ListOptions{}) @@ -68,14 +59,6 @@ func GetTaskList(c *framework.Clients) *v1.TaskList { return tasklist } -func GetClusterTaskList(c *framework.Clients) *v1beta1.ClusterTaskList { - clustertasklist, err := c.ClusterTaskClient.List(context.Background(), metav1.ListOptions{}) - if err != nil { - log.Fatalf("Couldn't get expected clustertasklist %s", err) - } - return clustertasklist -} - func GetTaskRun(c *framework.Clients, name string) *v1.TaskRun { taskRun, err := c.TaskRunClient.Get(context.Background(), name, metav1.GetOptions{}) @@ -171,11 +154,6 @@ func GetTaskRunListWithTaskName(c *framework.Clients, tname string, sortByStartT return GetTaskRunListByLabel(c, sortByStartTime, label) } -func GetTaskRunListWithClusterTaskName(c *framework.Clients, ctname string, sortByStartTime bool) *v1.TaskRunList { - label := fmt.Sprintf("tekton.dev/clusterTask=%s", ctname) - return GetTaskRunListByLabel(c, sortByStartTime, label) -} - func GetPipelineRunList(c *framework.Clients) *v1.PipelineRunList { pipelineRunList, err := c.PipelineRunClient.List(context.Background(), metav1.ListOptions{}) @@ -243,18 +221,6 @@ func ListResourceNamesForJSONPath(obj interface{}) string { return emptyMsg } - for _, r := range obj.Items { - fmt.Fprintf(w, body, - r.Name, - ) - } - w.Flush() - return tmplBytes.String() - case *v1beta1.ClusterTaskList: - if len(obj.Items) == 0 { - return emptyMsg - } - for _, r := range obj.Items { fmt.Fprintf(w, body, r.Name, @@ -307,41 +273,6 @@ func ListAllTasksOutput(t *testing.T, cs *framework.Clients, td map[int]interfac return tmplBytes.String() } -func ListAllClusterTasksOutput(t *testing.T, cs *framework.Clients, td map[int]interface{}) string { - t.Helper() - const ( - emptyMsg = "No clustertasks found" - header = "NAME\tDESCRIPTION\tAGE" - body = "%s\t%s\t%s\n" - ) - - clock := clockwork.NewFakeClockAt(time.Now()) - - clustertask := GetClusterTaskListWithTestData(t, cs, td) - - var tmplBytes bytes.Buffer - w := tabwriter.NewWriter(&tmplBytes, 0, 5, 3, ' ', tabwriter.TabIndent) - - if len(clustertask.Items) == 0 { - fmt.Fprintln(w, emptyMsg) - w.Flush() - return tmplBytes.String() - } - fmt.Fprintln(w, header) - - clusterTasks := clustertask.Items - - for idx := range clusterTasks { - fmt.Fprintf(w, body, - clusterTasks[idx].Name, - formatted.FormatDesc(clusterTasks[idx].Spec.Description), - formatted.Age(&clusterTasks[idx].CreationTimestamp, clock), - ) - } - w.Flush() - return tmplBytes.String() -} - func GetTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1.TaskList { t.Helper() @@ -368,32 +299,6 @@ func GetTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]inte return tasklist } -func GetClusterTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1beta1.ClusterTaskList { - t.Helper() - - clustertasklist := GetClusterTaskList(c) - - if len(clustertasklist.Items) != len(td) { - t.Errorf("Length of task list and Testdata provided not matching") - } - if len(clustertasklist.Items) == 0 { - return clustertasklist - } - for i, clustertask := range td { - switch clustertask := clustertask.(type) { - case *TaskData: - clustertasklist.Items[i].Name = clustertask.Name - default: - t.Error("Test Data Format Didn't Match please do check Test Data which you passing") - } - } - - if changelog := cmp.Diff(clustertasklist, GetClusterTaskList(c)); changelog != "" { - t.Logf("Changes occurred while performing diff operation %+v", changelog) - } - return clustertasklist -} - type TaskRunData struct { Name string Status string diff --git a/test/e2e/clustertask/start_test.go b/test/e2e/clustertask/start_test.go deleted file mode 100644 index d2537b5b74..0000000000 --- a/test/e2e/clustertask/start_test.go +++ /dev/null @@ -1,391 +0,0 @@ -//go:build e2e -// +build e2e - -// Copyright © 2020 The Tekton Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clustertask - -import ( - "fmt" - "os" - "regexp" - "strings" - "testing" - "time" - - "github.com/AlecAivazis/survey/v2/terminal" - "github.com/Netflix/go-expect" - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/cli/test/builder" - "github.com/tektoncd/cli/test/cli" - "github.com/tektoncd/cli/test/framework" - "github.com/tektoncd/cli/test/helper" - "github.com/tektoncd/cli/test/wait" - "gotest.tools/v3/assert" - is "gotest.tools/v3/assert/cmp" - "gotest.tools/v3/icmd" - knativetest "knative.dev/pkg/test" -) - -func TestClusterTaskInteractiveStartE2E(t *testing.T) { - t.Parallel() - c, namespace := framework.Setup(t) - knativetest.CleanupOnInterrupt(func() { framework.TearDown(t, c, namespace) }, t.Logf) - defer framework.TearDown(t, c, namespace) - - kubectl := cli.NewKubectl(namespace) - tkn, err := cli.NewTknRunner(namespace) - assert.NilError(t, err) - // Set environment variable TEST_CLUSTERTASK_LIST_EMPTY to any value to skip "No ClusterTasks found" test - if os.Getenv("TEST_CLUSTERTASK_LIST_EMPTY") == "" { - t.Run("Get list of ClusterTasks when none present", func(t *testing.T) { - res := tkn.Run(t, "clustertask", "list") - expected := "No ClusterTasks found\n" - expectedErr := "Command \"list\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" - res.Assert(t, icmd.Expected{ - ExitCode: 0, - Err: expectedErr, - Out: expected, - }) - }) - } - t.Logf("Creating clustertask read-clustertask") - res := kubectl.MustSucceed(t, "create", "-f", helper.GetResourcePath("read-file-clustertask.yaml")) - regex := regexp.MustCompile(`read-clustertask-[a-z0-9]+`) - clusterTaskName := regex.FindString(res.Stdout()) - - t.Run("Get list of ClusterTasks", func(t *testing.T) { - res := tkn.Run(t, "clustertask", "list") - if os.Getenv("TEST_CLUSTERTASK_LIST_EMPTY") == "" { - expected := builder.ListAllClusterTasksOutput(t, c, map[int]interface{}{ - 0: &builder.TaskData{ - Name: clusterTaskName, - }, - }) - expectedErr := "Command \"list\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" - res.Assert(t, icmd.Expected{ - ExitCode: 0, - Err: expectedErr, - Out: expected, - }) - } else { - assert.Assert(t, strings.Contains(res.Stdout(), clusterTaskName)) - } - }) - - t.Run("Start ClusterTask with flags", func(t *testing.T) { - res := tkn.MustSucceed(t, "clustertask", "start", clusterTaskName, - "-p=message=e2e-test", - "-p=heading=start", - "-w=name=write-allowed,emptyDir=", - "--showlog") - - vars := make(map[string]interface{}) - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name - vars["Taskrun"] = taskRunGeneratedName - expected := helper.ProcessString(`(TaskRun started: {{.Taskrun}} -Waiting for logs to be available... -.*)`, vars) - assert.Assert(t, is.Regexp(expected, res.Stdout())) - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceeded"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Run("Start ClusterTask interactively", func(t *testing.T) { - tkn.RunInteractiveTests(t, &cli.Prompt{ - CmdArgs: []string{"clustertask", "start", clusterTaskName, "-w=name=write-allowed,emptyDir="}, - Procedure: func(c *expect.Console) error { - if _, err := c.ExpectString("Value for param `message` of type `string`? (Default is `hello`)"); err != nil { - return err - } - - if _, err := c.ExpectString("hello"); err != nil { - return err - } - if _, err := c.SendLine("test-e2e"); err != nil { - return err - } - if _, err := c.ExpectString("Value for param `heading` of type `string`?"); err != nil { - return err - } - - if _, err := c.SendLine("start"); err != nil { - return err - } - if _, err := c.ExpectEOF(); err != nil { - return err - } - - c.Close() - return nil - }, - }) - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Run("Start ClusterTask with --use-param-defaults and all the params having default", func(t *testing.T) { - tkn.MustSucceed(t, "clustertask", "start", clusterTaskName, - "--use-param-defaults", - "-p=heading=start", - "-w=name=write-allowed,emptyDir=", - "--showlog") - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Run("Start ClusterTask passing --param for some params and some params are not passed", func(t *testing.T) { - tkn.RunInteractiveTests(t, &cli.Prompt{ - CmdArgs: []string{ - "clustertask", "start", clusterTaskName, - "-w=name=write-allowed,emptyDir=", - "--param=message=test-e2e", - "--showlog", - }, - Procedure: func(c *expect.Console) error { - if _, err := c.ExpectString("Value for param `heading` of type `string`?"); err != nil { - return err - } - - if _, err := c.SendLine("start"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - c.Close() - return nil - }, - }) - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Run("Start ClusterTask with --use-param-defaults and some of the params not having default", func(t *testing.T) { - tkn.RunInteractiveTests(t, &cli.Prompt{ - CmdArgs: []string{ - "clustertask", "start", clusterTaskName, - "-w=name=write-allowed,emptyDir=", - "--use-param-defaults", - "--showlog", - }, - Procedure: func(c *expect.Console) error { - if _, err := c.ExpectString("Value for param `heading` of type `string`?"); err != nil { - return err - } - - if _, err := c.SendLine("start"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - c.Close() - return nil - }, - }) - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Run("Start ClusterTask with --pod-template", func(t *testing.T) { - if tkn.CheckVersion(t, "Pipeline", "v0.10.2") { - t.Skip("Skip test as pipeline v0.10 doesn't support certain PodTemplate properties") - } - - tkn.MustSucceed(t, "clustertask", "start", clusterTaskName, - "-p=message=e2e-test", - "-p=heading=start", - "-w=name=write-allowed,emptyDir=", - "--showlog", - "--pod-template="+helper.GetResourcePath("/podtemplate/podtemplate.yaml")) - - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceeded"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Run("Start TaskRun using tkn ct start with --last option", func(t *testing.T) { - // Get last TaskRun for read-clustertask - lastTaskRun := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0] - - // Start TaskRun using --last - tkn.MustSucceed(t, "ct", "start", clusterTaskName, - "--last", - "--showlog") - - // Sleep to make make sure TaskRun is created/running - time.Sleep(1 * time.Second) - - // Get name of most recent TaskRun and wait for it to succeed - taskRunUsingLast := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0] - if err := wait.ForTaskRunState(c, taskRunUsingLast.Name, wait.TaskRunSucceed(taskRunUsingLast.Name), "TaskRunSucceeded"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - - // Expect that previous TaskRun spec will match most recent TaskRun spec - expected := lastTaskRun.Spec - got := taskRunUsingLast.Spec - if d := cmp.Diff(got, expected); d != "" { - t.Fatalf("-got, +want: %v", d) - } - }) - - t.Run("Start TaskRun using tkn ct start with --use-taskrun option", func(t *testing.T) { - // Get last TaskRun for read-clustertask - lastTaskRun := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0] - - // Start TaskRun using --use-taskrun - tkn.MustSucceed(t, "ct", "start", clusterTaskName, - "--use-taskrun", - lastTaskRun.Name, - "--showlog") - - // Sleep to make make sure TaskRun is created/running - time.Sleep(1 * time.Second) - - // Get name of most recent TaskRun and wait for it to succeed - taskRunUsingParticularTaskRun := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0] - if err := wait.ForTaskRunState(c, taskRunUsingParticularTaskRun.Name, wait.TaskRunSucceed(taskRunUsingParticularTaskRun.Name), "TaskRunSucceeded"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - - // Expect that selected TaskRun spec will match most recent TaskRun spec - expected := lastTaskRun.Spec - got := taskRunUsingParticularTaskRun.Spec - if d := cmp.Diff(got, expected); d != "" { - t.Fatalf("-got, +want: %v", d) - } - }) - - t.Logf("Creating clustertask clustertask-optional-ws") - res = kubectl.MustSucceed(t, "create", "-f", helper.GetResourcePath("clustertask-with-optional-workspace.yaml")) - regex = regexp.MustCompile(`clustertask-optional-ws-[a-z0-9]+`) - clusterTaskName2 := regex.FindString(res.Stdout()) - - t.Run("Start ClusterTask interactively with optional workspace (yes)", func(t *testing.T) { - tkn.RunInteractiveTests(t, &cli.Prompt{ - CmdArgs: []string{"clustertask", "start", clusterTaskName2}, - Procedure: func(c *expect.Console) error { - if _, err := c.ExpectString("Do you want to give specifications for the optional workspace `read-allowed`: (y/N)"); err != nil { - return err - } - - if _, err := c.SendLine("y"); err != nil { - return err - } - - if _, err := c.ExpectString("Please give specifications for the workspace: read-allowed"); err != nil { - return err - } - - if _, err := c.ExpectString("Name for the workspace: "); err != nil { - return err - } - - if _, err := c.SendLine("read-allowed"); err != nil { - return err - } - - if _, err := c.ExpectString("Value of the Sub Path: "); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Type of the Workspace:"); err != nil { - return err - } - - if _, err := c.SendLine("emptyDir"); err != nil { - return err - } - - if _, err := c.ExpectString("Type of EmptyDir: "); err != nil { - return err - } - - if _, err := c.SendLine(""); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - c.Close() - return nil - }, - }) - taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName2, true).Items[0].Name - if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil { - t.Errorf("Error waiting for TaskRun to Succeed: %s", err) - } - }) - - t.Logf("Deleting clustertask %s", clusterTaskName) - t.Run(fmt.Sprintf("Delete clustertask %s", clusterTaskName), func(t *testing.T) { - res := tkn.MustSucceed(t, "clustertask", "delete", clusterTaskName, "-f") - expected := fmt.Sprintf("ClusterTasks deleted: \"%s\"", clusterTaskName) - expectedErr := "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" - res.Assert(t, icmd.Expected{ - Err: expectedErr, - Out: expected, - }) - - // Check if clustertask %s got deleted - res = tkn.Run(t, "clustertask", "list") - assert.Assert(t, !strings.Contains(res.Stdout(), clusterTaskName)) - }) - - t.Logf("Deleting clustertask %s", clusterTaskName2) - t.Run(fmt.Sprintf("Delete clustertask %s", clusterTaskName2), func(t *testing.T) { - res := tkn.MustSucceed(t, "clustertask", "delete", clusterTaskName2, "-f") - expected := fmt.Sprintf("ClusterTasks deleted: \"%s\"", clusterTaskName2) - expectedErr := "Command \"delete\" is deprecated, ClusterTasks are deprecated, this command will be removed in future releases.\n" - res.Assert(t, icmd.Expected{ - Err: expectedErr, - Out: expected, - }) - - // Check if clustertask %s got deleted - res = tkn.Run(t, "clustertask", "list") - assert.Assert(t, !strings.Contains(res.Stdout(), clusterTaskName2)) - }) -} diff --git a/test/framework/clients.go b/test/framework/clients.go index 818c665a3e..3be45423fb 100644 --- a/test/framework/clients.go +++ b/test/framework/clients.go @@ -19,7 +19,6 @@ import ( "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" v1 "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1" "k8s.io/client-go/kubernetes" knativetest "knative.dev/pkg/test" ) @@ -29,7 +28,6 @@ type Clients struct { KubeClient kubernetes.Interface PipelineClient v1.PipelineInterface TaskClient v1.TaskInterface - ClusterTaskClient v1beta1.ClusterTaskInterface TaskRunClient v1.TaskRunInterface PipelineRunClient v1.PipelineRunInterface } @@ -60,7 +58,6 @@ func NewClients(configPath, clusterName, namespace string) *Clients { c.PipelineClient = cs.TektonV1().Pipelines(namespace) c.TaskClient = cs.TektonV1().Tasks(namespace) - c.ClusterTaskClient = cs.TektonV1beta1().ClusterTasks() c.TaskRunClient = cs.TektonV1().TaskRuns(namespace) c.PipelineRunClient = cs.TektonV1().PipelineRuns(namespace) return c diff --git a/test/resources/clustertask-with-optional-workspace.yaml b/test/resources/clustertask-with-optional-workspace.yaml deleted file mode 100644 index 9132c9e7b4..0000000000 --- a/test/resources/clustertask-with-optional-workspace.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2021 The Tekton Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -metadata: - generateName: clustertask-optional-ws- -spec: - steps: - - name: list-files - image: ubuntu - script: | - #!/bin/bash - - [ "$(workspaces.read-allowed.bound)" == "true" ] && \ - ls $(workspaces.read-allowed.path) - workspaces: - - name: read-allowed - optional: true diff --git a/test/resources/read-file-clustertask.yaml b/test/resources/read-file-clustertask.yaml deleted file mode 100644 index cd54e67806..0000000000 --- a/test/resources/read-file-clustertask.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2020 The Tekton Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -metadata: - generateName: read-clustertask- -spec: - params: - - name: message - default: "hello" - - name: heading - steps: - - name: write-allowed - image: ubuntu - script: echo $(params.heading);echo $(params.message) > $(workspaces.write-allowed.path)/foo - - name: read-allowed - image: ubuntu - script: cat $(workspaces.write-allowed.path)/foo | grep $(params.message) - workspaces: - - name: write-allowed - description: | - The folder where we write the message to. If no workspace - is provided then the message will not be written. - mountPath: /custom/path/relative/to/root