-
Notifications
You must be signed in to change notification settings - Fork 253
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
Open
haedaal
wants to merge
9
commits into
tektoncd:main
Choose a base branch
from
haedaal:issue951
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
feb0a01
poc
haedaal bbe9740
make docs
haedaal 1e5023f
Add unittests
haedaal aabe9e6
add e2e test
haedaal 095983a
mirror podtemplate
haedaal 4dba6ad
use --taskrun-spec
haedaal ede2079
fix resource path
haedaal 0663311
add license header
haedaal 5f4ffd5
fix year of license headers
haedaal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_TaskRunSpec.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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: {} |
30 changes: 30 additions & 0 deletions
30
...ipeline/testdata/TestPipelineStart_ExecuteCommand_v1beta1-Dry_Run_with_TaskRunSpec.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 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. | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright © 2023 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 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright © 2023 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 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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 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. | ||
|
||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 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. | ||
|
||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
ecurityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 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. | ||
|
||
- pipelineTaskName: first-create-file | ||
taskPodTemplate: | ||
schedulerName: SchedulerName | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.