-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pipeline start supports taskRunSpec argument #1969
base: main
Are you sure you want to change the base?
Changes from 6 commits
feb0a01
bbe9740
1e5023f
aabe9e6
095983a
4dba6ad
ede2079
0663311
5f4ffd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: PipelineRun | ||
metadata: | ||
creationTimestamp: null | ||
generateName: test-pipeline-run- | ||
labels: | ||
jemange: desfrites | ||
namespace: ns | ||
spec: | ||
params: | ||
- name: pipeline-param | ||
value: value1 | ||
- name: rev-param | ||
value: value2 | ||
pipelineRef: | ||
name: test-pipeline | ||
taskRunSpecs: | ||
- pipelineTaskName: unit-test-task | ||
podTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 | ||
taskRunTemplate: | ||
serviceAccountName: svc1 | ||
status: {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Flag --resource has been deprecated, pipelineresources have been deprecated, this flag will be removed soon | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
creationTimestamp: null | ||
generateName: test-pipeline-run- | ||
labels: | ||
jemange: desfrites | ||
namespace: ns | ||
spec: | ||
params: | ||
- name: pipeline-param | ||
value: value1 | ||
- name: rev-param | ||
value: value2 | ||
pipelineRef: | ||
name: test-pipeline | ||
resources: | ||
- name: source | ||
resourceRef: | ||
name: scaffold-git | ||
serviceAccountName: svc1 | ||
taskRunSpecs: | ||
- pipelineTaskName: unit-test-task | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 | ||
status: {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- pipelineTaskName: unit-test-task | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need license header here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ 0663311 |
||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright © 2020 The Tekton Authors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be 2023 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ 5f4ffd5 |
||
// | ||
// 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 pods | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/tektoncd/cli/pkg/file" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
type TaskRunSpec = []v1beta1.PipelineTaskRunSpec | ||
|
||
func ParseTaskRunSpec(httpClient http.Client, taskRunSpecLocation string, validate file.TypeValidator, errorMsg error) (TaskRunSpec, error) { | ||
taskRunSpec := TaskRunSpec{} | ||
b, err := file.LoadFileContent(httpClient, taskRunSpecLocation, validate, errorMsg) | ||
if err != nil { | ||
return taskRunSpec, err | ||
} | ||
|
||
if err := yaml.UnmarshalStrict(b, &taskRunSpec); err != nil { | ||
return taskRunSpec, err | ||
} | ||
|
||
return taskRunSpec, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright © 2020 The Tekton Authors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be 2023 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ 5f4ffd5 |
||
// | ||
// 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 pods | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/tektoncd/cli/pkg/file" | ||
"github.com/tektoncd/cli/pkg/test" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func getTestTaskRunSpec() TaskRunSpec { | ||
runAsNonRoot := true | ||
runAsUser := int64(1001) | ||
|
||
return TaskRunSpec{ | ||
v1beta1.PipelineTaskRunSpec{ | ||
PipelineTaskName: "first-create-file", | ||
TaskPodTemplate: &pod.PodTemplate{ | ||
ImagePullSecrets: nil, | ||
HostNetwork: false, | ||
SchedulerName: "SchedulerName", | ||
SecurityContext: &corev1.PodSecurityContext{ | ||
RunAsNonRoot: &runAsNonRoot, | ||
RunAsUser: &runAsUser, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func TestTaskRunSpec_Local_File(t *testing.T) { | ||
httpClient := *http.DefaultClient | ||
podTemplateLocation := "./testdata/taskrunspec.yaml" | ||
|
||
podTemplate, err := ParseTaskRunSpec(httpClient, podTemplateLocation, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", podTemplateLocation)) | ||
if err != nil { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
|
||
test.AssertOutput(t, getTestTaskRunSpec(), podTemplate) | ||
} | ||
|
||
func TestTaskRunSpec_Local_File_Typo(t *testing.T) { | ||
httpClient := *http.DefaultClient | ||
podTemplateLocation := "./testdata/taskrunspec-typo.yaml" | ||
|
||
_, err := ParseTaskRunSpec(httpClient, podTemplateLocation, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", podTemplateLocation)) | ||
if err == nil { | ||
t.Fatalf("Expected error for local file typo, but error was nil") | ||
} | ||
|
||
expected := `error unmarshaling JSON: while decoding JSON: json: unknown field "ecurityContext"` | ||
test.AssertOutput(t, expected, err.Error()) | ||
} | ||
|
||
func TestTaskRunSpec_Local_File_Not_YAML(t *testing.T) { | ||
httpClient := *http.DefaultClient | ||
podTemplateLocation := "./testdata/taskrunspec-not-yaml" | ||
|
||
_, err := ParseTaskRunSpec(httpClient, podTemplateLocation, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", podTemplateLocation)) | ||
if err == nil { | ||
t.Fatalf("Expected error for local file typo, but error was nil") | ||
} | ||
|
||
expected := "invalid file format for ./testdata/taskrunspec-not-yaml: .yaml or .yml file extension and format required" | ||
test.AssertOutput(t, expected, err.Error()) | ||
} | ||
|
||
func TestTaskRunSpec_Local_File_Not_Found(t *testing.T) { | ||
httpClient := *http.DefaultClient | ||
podTemplateLocation := "./testdata/not-exist.yaml" | ||
|
||
_, err := ParseTaskRunSpec(httpClient, podTemplateLocation, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", podTemplateLocation)) | ||
if err == nil { | ||
t.Fatalf("Expected error for local file typo, but error was nil") | ||
} | ||
|
||
expected := "open ./testdata/not-exist.yaml: no such file or directory" | ||
test.AssertOutput(t, expected, err.Error()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2020 The Tekton Authors. | ||
haedaal marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be 2023 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ 5f4ffd5 |
||
# | ||
# 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. | ||
|
||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2020 The Tekton Authors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be 2023 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ 5f4ffd5 |
||
# | ||
# 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. | ||
|
||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
ecurityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2020 The Tekton Authors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be 2023 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ 5f4ffd5 |
||
# | ||
# 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. | ||
|
||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,23 @@ Waiting for logs to be available... | |
} | ||
}) | ||
|
||
t.Run("Start PipelineRun with --taskrun-spec", func(t *testing.T) { | ||
tkn.MustSucceed(t, "pipeline", "start", tePipelineName, | ||
"-p=filename=output", | ||
"-w=name=shared-data,emptyDir=", | ||
"--taskrun-spec="+helper.GetResourcePath("/taskrunspec/taskrunspec.yaml"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the path seems incorrect here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed @ ede2079 |
||
"--use-param-defaults", | ||
"--showlog") | ||
|
||
time.Sleep(1 * time.Second) | ||
|
||
pipelineRunGeneratedName := builder.GetPipelineRunListWithName(c, tePipelineName, true).Items[0].Name | ||
timeout := 5 * time.Minute | ||
if err := wait.ForPipelineRunState(c, pipelineRunGeneratedName, timeout, wait.PipelineRunSucceed(pipelineRunGeneratedName), "PipelineRunSucceeded"); err != nil { | ||
t.Errorf("Error waiting for PipelineRun to Succeed: %s", err) | ||
} | ||
}) | ||
|
||
t.Run("Cancel finished PipelineRun with tkn pipelinerun cancel", func(t *testing.T) { | ||
// Get last PipelineRun for pipeline-with-workspace | ||
pipelineRunLast := builder.GetPipelineRunListWithName(c, tePipelineName, true).Items[0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I referred #1088 writing this pr, and it's mostly the same but here hardcoded pipelineTaskName maybe seems fragile to future change. maybe ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haedaal what could be the other options ? multiple flags
--tasrun-spec
, one fore each task ? what else ?I think the one is ok, but I won't if there could be other alternative to look into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be we can add a check in parsing to have multiple tasks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vdemeester I feel like there's no better alternatives, as it looks exactly same as k8s spec. I think simplicity is worth a bit of fragility.