Skip to content

Commit

Permalink
Passes tasks from bundles through defaulting before execution
Browse files Browse the repository at this point in the history
for tasks from yaml webhook does the defaulting but for tasks
fetched from bundles, defaulting was not taking place
due to which validation error use to occur at execution.
This adds the defaulting for tasks fetched from bundles.

Signed-off-by: Shivam Mukhade <[email protected]>
  • Loading branch information
sm43 committed Jul 27, 2021
1 parent 3ddba8b commit 56ed957
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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
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

0 comments on commit 56ed957

Please sign in to comment.