Skip to content
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

[release-v0.50.x] Make sure we use the correct namespace for remote Pipeline validation #7023

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/reconciler/pipelinerun/resources/pipelineref.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ import (
"k8s.io/client-go/kubernetes"
)

var ErrReferencedPipelineValidationFailed = errors.New("validation failed for referenced Pipeline")
var ErrCouldntValidatePipelineRetryable = errors.New("retryable error validating referenced Pipeline")
var ErrCouldntValidatePipelinePermanent = errors.New("permanent error validating referenced Pipeline")
var (
ErrReferencedPipelineValidationFailed = errors.New("validation failed for referenced Pipeline")
ErrCouldntValidatePipelineRetryable = errors.New("retryable error validating referenced Pipeline")
ErrCouldntValidatePipelinePermanent = errors.New("permanent error validating referenced Pipeline")
)

// GetPipelineFunc is a factory function that will use the given PipelineRef to return a valid GetPipeline function that
// looks up the pipeline. It uses as context a k8s client, tekton client, namespace, and service account name to return
Expand Down Expand Up @@ -150,6 +152,7 @@ func readRuntimeObjectAsPipeline(ctx context.Context, namespace string, obj runt
// TODO(#6592): Decouple API versioning from feature versioning
dryRunObj := obj.DeepCopy()
dryRunObj.Name = uuid.NewString() // Use a randomized name for the Pipeline in case there is already another Pipeline of the same name
dryRunObj.Namespace = namespace // Make sure the namespace is the same as the PipelineRun
if _, err := tekton.TektonV1beta1().Pipelines(namespace).Create(ctx, dryRunObj, metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}}); err != nil {
return nil, nil, handleDryRunCreateErr(err, obj.Name)
}
Expand All @@ -169,6 +172,7 @@ func readRuntimeObjectAsPipeline(ctx context.Context, namespace string, obj runt
// without actually creating the Pipeline on the cluster
dryRunObj := obj.DeepCopy()
dryRunObj.Name = uuid.NewString() // Use a randomized name for the Pipeline in case there is already another Pipeline of the same name
dryRunObj.Namespace = namespace // Make sure the namespace is the same as the PipelineRun
if _, err := tekton.TektonV1().Pipelines(namespace).Create(ctx, dryRunObj, metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}}); err != nil {
return nil, nil, handleDryRunCreateErr(err, obj.Name)
}
Expand Down
26 changes: 25 additions & 1 deletion pkg/reconciler/pipelinerun/resources/pipelineref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ var (
unsignedV1Pipeline = &v1.Pipeline{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1",
Kind: "Pipeline"},
Kind: "Pipeline",
},
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline",
Namespace: "trusted-resources",
Expand Down Expand Up @@ -313,6 +314,14 @@ func TestGetPipelineFunc_RemoteResolution(t *testing.T) {
pipelineYAMLStringWithoutDefaults,
}, "\n"),
wantPipeline: parse.MustParseV1Pipeline(t, pipelineYAMLStringWithoutDefaults),
}, {
name: "v1 remote pipeline with different namespace",
pipelineYAML: strings.Join([]string{
"kind: Pipeline",
"apiVersion: tekton.dev/v1",
pipelineYAMLStringNamespaceFoo,
}, "\n"),
wantPipeline: parse.MustParseV1Pipeline(t, pipelineYAMLStringNamespaceFoo),
}}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -1303,6 +1312,21 @@ spec:
type: ""
`

var pipelineYAMLStringNamespaceFoo = `
metadata:
name: foo
namespace: foo
spec:
tasks:
- name: task1
taskSpec:
steps:
- name: step1
image: ubuntu
script: |
echo "hello world!"
`

func getSignedV1Pipeline(unsigned *v1.Pipeline, signer signature.Signer, name string) (*v1.Pipeline, error) {
signed := unsigned.DeepCopy()
signed.Name = name
Expand Down