From b7c79100d415e5d361c2a58dcf8fe36af3426c86 Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Date: Tue, 5 May 2020 16:09:03 +0530 Subject: [PATCH] fix task start with file Close #959 This fixes task start with file command. Note: to start a task from file params needs to have its type speficed, in case of existing task in cluster type is appended by the controller. Signed-off-by: Pradeep Kumar --- pkg/cmd/task/start.go | 6 +++ pkg/cmd/task/start_test.go | 34 ++++++++++++ ...nd-Dry_Run_with_--param_-f_v1alpha1.golden | 54 +++++++++++++++++++ ...uteCommand-Dry_Run_with_-f_v1alpha1.golden | 16 ------ ...ry_Run_with_output=json_-f_v1alpha1.golden | 28 ---------- ...ta1-Dry_Run_with_--param_-f_v1beta1.golden | 52 ++++++++++++++++++ pkg/task/task.go | 2 - pkg/taskrun/create.go | 2 - 8 files changed, 146 insertions(+), 48 deletions(-) create mode 100644 pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--param_-f_v1alpha1.golden create mode 100644 pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_--param_-f_v1beta1.golden diff --git a/pkg/cmd/task/start.go b/pkg/cmd/task/start.go index b63193e03..8f6979cbf 100644 --- a/pkg/cmd/task/start.go +++ b/pkg/cmd/task/start.go @@ -266,7 +266,13 @@ func startTask(opt startOptions, args []string) error { if err != nil { return err } + tname = task.ObjectMeta.Name + + if task.Spec.Params != nil { + params.FilterParamsByType(task.Spec.Params) + } + tr.Spec = v1beta1.TaskRunSpec{ TaskSpec: &task.Spec, } diff --git a/pkg/cmd/task/start_test.go b/pkg/cmd/task/start_test.go index 48e334560..b7409dd04 100644 --- a/pkg/cmd/task/start_test.go +++ b/pkg/cmd/task/start_test.go @@ -3862,6 +3862,23 @@ func TestTaskStart_ExecuteCommand(t *testing.T) { wantError: false, goldenFile: true, }, + { + name: "Dry Run with --param -f v1alpha1", + command: []string{"start", + "-f", "./testdata/task-v1alpha1.yaml", + "-n", "ns", + "-s=svc1", + "-i=docker-source=git", + "-o=builtImage=image", + "--dry-run", + "--param=myarg=BomBom", + }, + namespace: "", + dynamic: dc1, + input: cs, + wantError: false, + goldenFile: true, + }, } for _, tp := range testParams { @@ -4062,6 +4079,23 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) { wantError: false, goldenFile: true, }, + { + name: "Dry Run with --param -f v1beta1", + command: []string{"start", + "-f", "./testdata/task-v1beta1.yaml", + "-n", "ns", + "-s=svc1", + "-i=docker-source=git", + "-o=builtImage=image", + "--dry-run", + "--param=myarg=BomBom", + }, + namespace: "", + dynamic: dc, + input: cs, + wantError: false, + goldenFile: true, + }, } for _, tp := range testParams { diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--param_-f_v1alpha1.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--param_-f_v1alpha1.golden new file mode 100644 index 000000000..378698e6d --- /dev/null +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--param_-f_v1alpha1.golden @@ -0,0 +1,54 @@ +apiVersion: tekton.dev/v1alpha1 +kind: TaskRun +metadata: + creationTimestamp: null + generateName: test-task-run- + namespace: ns +spec: + inputs: + params: + - name: myarg + value: BomBom + resources: + - name: docker-source + resourceRef: + name: git + outputs: + resources: + - name: builtImage + resourceRef: + name: image + serviceAccountName: svc1 + taskSpec: + inputs: + params: + - default: /workspace/docker-source/Dockerfile + description: The path to the dockerfile to build + name: pathToDockerFile + type: string + - default: /workspace/docker-source + description: The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts) + name: pathToContext + type: string + resources: + - name: docker-source + type: git + outputs: + resources: + - name: builtImage + type: image + steps: + - args: + - --dockerfile=$(inputs.params.pathToDockerFile) + - --destination=$(outputs.resources.builtImage.url) + - --context=$(inputs.params.pathToContext) + command: + - /kaniko/executor + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker/ + image: gcr.io/kaniko-project/executor:v0.14.0 + name: build-and-push + resources: {} +status: + podName: "" diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f_v1alpha1.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f_v1alpha1.golden index ff2fdce54..f488af48b 100644 --- a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f_v1alpha1.golden +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f_v1alpha1.golden @@ -34,22 +34,6 @@ spec: resources: - name: builtImage type: image - params: - - default: /workspace/docker-source/Dockerfile - description: The path to the dockerfile to build - name: pathToDockerFile - type: string - - default: /workspace/docker-source - description: The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts) - name: pathToContext - type: string - resources: - inputs: - - name: docker-source - type: git - outputs: - - name: builtImage - type: image steps: - args: - --dockerfile=$(inputs.params.pathToDockerFile) diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden index 2433a4a75..9fce85742 100644 --- a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden @@ -9,34 +9,6 @@ "spec": { "serviceAccountName": "svc1", "taskSpec": { - "resources": { - "inputs": [ - { - "name": "docker-source", - "type": "git" - } - ], - "outputs": [ - { - "name": "builtImage", - "type": "image" - } - ] - }, - "params": [ - { - "name": "pathToDockerFile", - "type": "string", - "description": "The path to the dockerfile to build", - "default": "/workspace/docker-source/Dockerfile" - }, - { - "name": "pathToContext", - "type": "string", - "description": "The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)", - "default": "/workspace/docker-source" - } - ], "steps": [ { "name": "build-and-push", diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_--param_-f_v1beta1.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_--param_-f_v1beta1.golden new file mode 100644 index 000000000..80b896aab --- /dev/null +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_--param_-f_v1beta1.golden @@ -0,0 +1,52 @@ +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + creationTimestamp: null + generateName: test-task-run- + namespace: ns +spec: + params: + - name: myarg + value: BomBom + resources: + inputs: + - name: docker-source + resourceRef: + name: git + outputs: + - name: builtImage + resourceRef: + name: image + serviceAccountName: svc1 + taskSpec: + params: + - default: /workspace/docker-source/Dockerfile + description: The path to the dockerfile to build + name: pathToDockerFile + type: string + - default: /workspace/docker-source + description: The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts) + name: pathToContext + type: string + resources: + inputs: + - name: docker-source + type: git + outputs: + - name: builtImage + type: image + steps: + - args: + - --dockerfile=$(inputs.params.pathToDockerFile) + - --destination=$(outputs.resources.builtImage.url) + - --context=$(inputs.params.pathToContext) + command: + - /kaniko/executor + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker/ + image: gcr.io/kaniko-project/executor:v0.14.0 + name: build-and-push + resources: {} +status: + podName: "" diff --git a/pkg/task/task.go b/pkg/task/task.go index ecc243393..e59f6191c 100644 --- a/pkg/task/task.go +++ b/pkg/task/task.go @@ -128,8 +128,6 @@ func SpecConvertDown(spec *v1beta1.TaskSpec) *v1alpha1.TaskSpec { downTaskSpec.Sidecars = spec.Sidecars downTaskSpec.Workspaces = spec.Workspaces downTaskSpec.Results = spec.Results - downTaskSpec.Resources = spec.Resources - downTaskSpec.Params = spec.Params downTaskSpec.Description = spec.Description if spec.Resources != nil { if len(spec.Resources.Inputs) > 0 { diff --git a/pkg/taskrun/create.go b/pkg/taskrun/create.go index 26fe2b10c..fa72b2b08 100644 --- a/pkg/taskrun/create.go +++ b/pkg/taskrun/create.go @@ -36,8 +36,6 @@ func Create(c *cli.Clients, tr *v1beta1.TaskRun, opts metav1.CreateOptions, ns s if err != nil { return nil, err } - v1alpha1TaskRun.Kind = "TaskRun" - v1alpha1TaskRun.APIVersion = "tekton.dev/v1alpha1" return createUnstructured(v1alpha1TaskRun, c, opts, ns) }