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

Passes pipelines/tasks from bundles through defaulting before execution #4117

Merged
merged 2 commits into from
Jul 27, 2021
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
8 changes: 8 additions & 0 deletions internal/builder/v1alpha1/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func Pipeline(name string, ops ...PipelineOp) *v1alpha1.Pipeline {
return p
}

// PipelineType will add a TypeMeta to the pipeline's definition.
func PipelineType(t *v1alpha1.Pipeline) {
t.TypeMeta = metav1.TypeMeta{
Kind: "Pipeline",
APIVersion: "tekton.dev/v1alpha1",
}
}

// PipelineNamespace sets the namespace on the Pipeline
func PipelineNamespace(namespace string) PipelineOp {
return func(t *v1alpha1.Pipeline) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/pipeline/v1beta1/pipeline_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ limitations under the License.

package v1beta1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

// PipelineObject is implemented by Pipeline and ClusterPipeline
type PipelineObject interface {
apis.Defaultable
PipelineMetadata() metav1.ObjectMeta
PipelineSpec() PipelineSpec
Copy() PipelineObject
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/pipeline/v1beta1/task_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ limitations under the License.

package v1beta1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

// TaskObject is implemented by Task and ClusterTask
type TaskObject interface {
apis.Defaultable
TaskMetadata() metav1.ObjectMeta
TaskSpec() TaskSpec
Copy() TaskObject
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5881,6 +5881,7 @@ func TestReconcile_RemotePipelineRef(t *testing.T) {
Resources: &v1beta1.TaskRunResources{},
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
TaskRef: &v1beta1.TaskRef{
Kind: "Task",
Name: "unit-test-task",
Bundle: ref,
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelineref.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien
return nil, err
}
if pipeline, ok := obj.(v1beta1.PipelineObject); ok {
pipeline.SetDefaults(ctx)
return pipeline, nil
}

if pipeline, ok := obj.(*v1alpha1.Pipeline); ok {
betaPipeline := &v1beta1.Pipeline{}
err := pipeline.ConvertTo(ctx, betaPipeline)
betaPipeline.SetDefaults(ctx)
return betaPipeline, err
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelineref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-containerregistry/pkg/registry"
ta "github.com/tektoncd/pipeline/internal/builder/v1alpha1"
tb "github.com/tektoncd/pipeline/internal/builder/v1beta1"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
Expand Down Expand Up @@ -146,6 +148,31 @@ func TestGetPipelineFunc(t *testing.T) {
Name: "simple",
},
expected: tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"), tb.PipelineSpec(tb.PipelineTask("something", "something"))),
}, {
name: "remote-pipeline-without-defaults",
localPipelines: []runtime.Object{simplePipeline},
remotePipelines: []runtime.Object{
tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"),
tb.PipelineSpec(tb.PipelineTask("something", "something"), tb.PipelineParamSpec("foo", ""))),
dummyPipeline},
ref: &v1beta1.PipelineRef{
Name: "simple",
Bundle: u.Host + "/remote-pipeline-without-defaults",
},
expected: tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"),
tb.PipelineSpec(tb.PipelineTask("something", "something", tb.PipelineTaskRefKind(v1beta1.NamespacedTaskKind)), tb.PipelineParamSpec("foo", v1beta1.ParamTypeString))),
}, {
name: "remote-v1alpha1-pipeline-without-defaults",
localPipelines: []runtime.Object{simplePipeline},
remotePipelines: []runtime.Object{
ta.Pipeline("simple", ta.PipelineType, ta.PipelineNamespace("default"),
ta.PipelineSpec(ta.PipelineTask("something", "something"), ta.PipelineParamSpec("foo", "")))},
ref: &v1alpha1.PipelineRef{
Name: "simple",
Bundle: u.Host + "/remote-v1alpha1-pipeline-without-defaults",
},
expected: tb.Pipeline("simple", tb.PipelineNamespace("default"),
tb.PipelineSpec(tb.PipelineTask("something", "something", tb.PipelineTaskRefKind(v1beta1.NamespacedTaskKind)), tb.PipelineParamSpec("foo", v1beta1.ParamTypeString))),
}}

for _, tc := range testcases {
Expand Down
3 changes: 3 additions & 0 deletions pkg/reconciler/taskrun/resources/taskref.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func GetTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset
// If the resolved object is already a v1beta1.{Cluster}Task, it should be returnable as a
// v1beta1.TaskObject.
if ti, ok := obj.(v1beta1.TaskObject); ok {
ti.SetDefaults(ctx)
return ti, nil
}

Expand All @@ -105,10 +106,12 @@ func GetTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset
case *v1alpha1.Task:
betaTask := &v1beta1.Task{}
err := tt.ConvertTo(ctx, betaTask)
betaTask.SetDefaults(ctx)
return betaTask, err
case *v1alpha1.ClusterTask:
betaTask := &v1beta1.ClusterTask{}
err := tt.ConvertTo(ctx, betaTask)
betaTask.SetDefaults(ctx)
return betaTask, err
}

Expand Down
25 changes: 25 additions & 0 deletions pkg/reconciler/taskrun/resources/taskref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-containerregistry/pkg/registry"
ta "github.com/tektoncd/pipeline/internal/builder/v1alpha1"
tb "github.com/tektoncd/pipeline/internal/builder/v1beta1"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
Expand Down Expand Up @@ -153,6 +154,30 @@ func TestGetTaskFunc(t *testing.T) {
},
expected: tb.Task("simple", tb.TaskType),
expectedKind: v1beta1.NamespacedTaskKind,
}, {
name: "remote-task-without-defaults",
localTasks: []runtime.Object{},
remoteTasks: []runtime.Object{
tb.Task("simple", tb.TaskType, tb.TaskNamespace("default"), tb.TaskSpec(tb.TaskParam("foo", ""), tb.Step("something"))),
},
ref: &v1beta1.TaskRef{
Name: "simple",
Bundle: u.Host + "/remote-task-without-defaults",
},
expected: tb.Task("simple", tb.TaskType, tb.TaskNamespace("default"), tb.TaskSpec(tb.TaskParam("foo", v1beta1.ParamTypeString), tb.Step("something"))),
expectedKind: v1beta1.NamespacedTaskKind,
}, {
name: "remote-v1alpha1-task-without-defaults",
localTasks: []runtime.Object{},
remoteTasks: []runtime.Object{
ta.Task("simple", ta.TaskType, ta.TaskNamespace("default"), ta.TaskSpec(ta.TaskParam("foo", ""), ta.Step("something"))),
},
ref: &v1alpha1.TaskRef{
Name: "simple",
Bundle: u.Host + "/remote-v1alpha1-task-without-defaults",
},
expected: tb.Task("simple", tb.TaskNamespace("default"), tb.TaskSpec(tb.TaskParam("foo", v1alpha1.ParamTypeString), tb.Step("something"))),
expectedKind: v1beta1.NamespacedTaskKind,
}, {
name: "local-task",
localTasks: []runtime.Object{
Expand Down