diff --git a/pkg/apis/pipeline/v1beta1/implicit_params_test.go b/pkg/apis/pipeline/v1beta1/implicit_params_test.go new file mode 100644 index 00000000000..769fb080823 --- /dev/null +++ b/pkg/apis/pipeline/v1beta1/implicit_params_test.go @@ -0,0 +1,473 @@ +package v1beta1_test + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/tektoncd/pipeline/pkg/apis/config" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/pkg/apis" +) + +var ( + cmpOptions = []cmp.Option{ + cmpopts.SortSlices(func(x, y v1beta1.ParamSpec) bool { + return x.Name < y.Name + }), + cmpopts.SortSlices(func(x, y v1beta1.Param) bool { + return x.Name < y.Name + }), + cmpopts.SortSlices(func(x, y v1beta1.PipelineTask) bool { + return x.Name < y.Name + }), + } +) + +func TestImplicitParams(t *testing.T) { + // Configure alpha API config. + ctx := context.Background() + cfg := config.FromContextOrDefaults(ctx) + cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} + + ctxs := []struct { + name string + ctx context.Context + }{ + { + name: "direct implicit context", + ctx: v1beta1.WithImplicitParamsEnabled(ctx, true), + }, + { + name: "alpha context", + ctx: config.ToContext(ctx, cfg), + }, + } + + for _, tctx := range ctxs { + t.Run(tctx.name, func(t *testing.T) { + for _, tc := range []struct { + // Expect in and want to be the same type. + in apis.Defaultable + want interface{} + }{ + // This data needs to be inlined to ensure unique copies on each test. + { + in: &v1beta1.PipelineRunSpec{ + Params: []v1beta1.Param{ + { + Name: "foo", + Value: v1beta1.ArrayOrString{ + StringVal: "a", + }, + }, + { + Name: "bar", + Value: v1beta1.ArrayOrString{ + ArrayVal: []string{"b"}, + }, + }, + }, + PipelineSpec: &v1beta1.PipelineSpec{ + Tasks: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{}, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + }, + }, + }, + Finally: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{}, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + }, + }, + }, + }, + }, + want: &v1beta1.PipelineRunSpec{ + ServiceAccountName: config.DefaultServiceAccountValue, + Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, + Params: []v1beta1.Param{ + { + Name: "foo", + Value: v1beta1.ArrayOrString{ + StringVal: "a", + }, + }, + { + Name: "bar", + Value: v1beta1.ArrayOrString{ + ArrayVal: []string{"b"}, + }, + }, + }, + PipelineSpec: &v1beta1.PipelineSpec{ + Tasks: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "foo", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "$(params.foo)", + }, + }, + { + Name: "bar", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeArray, + ArrayVal: []string{"$(params.bar[*])"}, + }, + }, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + Kind: v1beta1.NamespacedTaskKind, + }, + }, + }, + Finally: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "foo", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "$(params.foo)", + }, + }, + { + Name: "bar", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeArray, + ArrayVal: []string{"$(params.bar[*])"}, + }, + }, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + Kind: v1beta1.NamespacedTaskKind, + }, + }, + }, + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + }, + }, + }, + { + in: &v1beta1.TaskRunSpec{ + TaskSpec: &v1beta1.TaskSpec{}, + Params: []v1beta1.Param{ + { + Name: "string-param", + Value: v1beta1.ArrayOrString{ + StringVal: "a", + }, + }, + { + Name: "array-param", + Value: v1beta1.ArrayOrString{ + ArrayVal: []string{"b"}, + }, + }, + }, + }, + want: &v1beta1.TaskRunSpec{ + TaskSpec: &v1beta1.TaskSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "string-param", + Type: v1beta1.ParamTypeString, + }, + { + Name: "array-param", + Type: v1beta1.ParamTypeArray, + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "string-param", + Value: v1beta1.ArrayOrString{ + StringVal: "a", + }, + }, + { + Name: "array-param", + Value: v1beta1.ArrayOrString{ + ArrayVal: []string{"b"}, + }, + }, + }, + ServiceAccountName: config.DefaultServiceAccountValue, + Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, + }, + }, + } { + t.Run(fmt.Sprintf("%T", tc.in), func(t *testing.T) { + tc.in.SetDefaults(tctx.ctx) + + if d := cmp.Diff(tc.want, tc.in, cmpOptions...); d != "" { + t.Error(diff.PrintWantGot(d)) + } + }) + } + }) + } +} + +// Pipelines have different behavior than PipelineRuns/TaskRuns - break this into its own test. +func TestImplicitParams_Pipeline(t *testing.T) { + pipeline := &v1beta1.PipelineSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + Tasks: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{}, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + }, + }, + }, + Finally: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{}, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + }, + }, + }, + } + + ctx := context.Background() + + // When only alpha flag is enabled, this should not apply implicit params. + t.Run("alpha context", func(t *testing.T) { + cfg := config.FromContextOrDefaults(ctx) + cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} + config.ToContext(ctx, cfg) + + p := pipeline.DeepCopy() + p.SetDefaults(ctx) + + want := &v1beta1.PipelineSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + Tasks: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{}, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + Kind: v1beta1.NamespacedTaskKind, + }, + }, + }, + Finally: []v1beta1.PipelineTask{ + { + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{}, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + Kind: v1beta1.NamespacedTaskKind, + }, + }, + }, + } + + if d := cmp.Diff(want, p, cmpOptions...); d != "" { + t.Error(diff.PrintWantGot(d)) + } + }) + + // When the Implicit Param context value is set directly, implicit param + // behavior should be enabled. + t.Run("direct implicit context", func(t *testing.T) { + p := pipeline.DeepCopy() + p.SetDefaults(v1beta1.WithImplicitParamsEnabled(ctx, true)) + + want := &v1beta1.PipelineSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + Tasks: []v1beta1.PipelineTask{ + { + Params: []v1beta1.Param{ + { + Name: "foo", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "$(params.foo)", + }, + }, + { + Name: "bar", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeArray, + ArrayVal: []string{"$(params.bar[*])"}, + }, + }, + }, + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + }, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + Kind: v1beta1.NamespacedTaskKind, + }, + }, + }, + Finally: []v1beta1.PipelineTask{ + { + Params: []v1beta1.Param{ + { + Name: "foo", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "$(params.foo)", + }, + }, + { + Name: "bar", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeArray, + ArrayVal: []string{"$(params.bar[*])"}, + }, + }, + }, + TaskSpec: &v1beta1.EmbeddedTask{ + TaskSpec: v1beta1.TaskSpec{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Type: v1beta1.ParamTypeString, + }, + { + Name: "bar", + Type: v1beta1.ParamTypeArray, + }, + }, + }, + }, + }, + { + TaskRef: &v1beta1.TaskRef{ + Name: "baz", + Kind: v1beta1.NamespacedTaskKind, + }, + }, + }, + } + + if d := cmp.Diff(want, p, cmpOptions...); d != "" { + t.Error(diff.PrintWantGot(d)) + } + }) +} diff --git a/pkg/apis/pipeline/v1beta1/param_context.go b/pkg/apis/pipeline/v1beta1/param_context.go index 4fdf10829f2..96dd8640bc0 100644 --- a/pkg/apis/pipeline/v1beta1/param_context.go +++ b/pkg/apis/pipeline/v1beta1/param_context.go @@ -17,14 +17,26 @@ package v1beta1 import ( "context" "fmt" - - "github.com/tektoncd/pipeline/pkg/apis/config" ) -// paramCtxKey is the unique identifier for referencing param information from +// enableImplicitParamContextKeyType is the unique type for referencing whether +// Implicit Param behavior is enabled for the given request context. +// See [TEP-0023](https://github.com/tektoncd/community/blob/main/teps/0023-implicit-mapping.md). +// +// +k8s:openapi-gen=false +type enableImplicitParamContextKeyType struct{} + +// paramCtxKey is the unique type for referencing param information from // a context.Context. See [context.Context.Value](https://pkg.go.dev/context#Context) // for more details. -var paramCtxKey struct{} +// +// +k8s:openapi-gen=false +type paramCtxKeyType struct{} + +var ( + enableImplicitParamContextKey = enableImplicitParamContextKeyType{} + paramCtxKey = paramCtxKeyType{} +) // paramCtxVal is the data type stored in the param context. // This maps param names -> ParamSpec. @@ -37,7 +49,7 @@ func addContextParams(ctx context.Context, in []Param) context.Context { return ctx } - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != "alpha" { + if !GetImplicitParamsEnabled(ctx) { return ctx } @@ -73,7 +85,7 @@ func addContextParamSpec(ctx context.Context, in []ParamSpec) context.Context { return ctx } - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != "alpha" { + if !GetImplicitParamsEnabled(ctx) { return ctx } @@ -170,3 +182,21 @@ func getContextParamSpecs(ctx context.Context) []ParamSpec { } return out } + +// WithImplicitParamsEnabled enables implicit parameter behavior for the +// request context. If enabled, parameters will propagate down embedded request +// objects (e.g. PipelineRun -> Pipeline -> Task, Pipeline -> Task, +// TaskRun -> Task) during defaulting. +func WithImplicitParamsEnabled(ctx context.Context, v bool) context.Context { + return context.WithValue(ctx, enableImplicitParamContextKey, v) +} + +// GetImplicitParamsEnabled returns whether implicit parameters are enabled for +// the given context. +func GetImplicitParamsEnabled(ctx context.Context) bool { + v := ctx.Value(enableImplicitParamContextKey) + if v == nil { + return false + } + return v.(bool) +} diff --git a/pkg/apis/pipeline/v1beta1/param_context_test.go b/pkg/apis/pipeline/v1beta1/param_context_test.go index 3e821e21d87..006946c29ed 100644 --- a/pkg/apis/pipeline/v1beta1/param_context_test.go +++ b/pkg/apis/pipeline/v1beta1/param_context_test.go @@ -20,13 +20,12 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/tektoncd/pipeline/pkg/apis/config" ) func TestAddContextParams(t *testing.T) { ctx := context.Background() - t.Run("no-alpha", func(t *testing.T) { + t.Run("not-enabled", func(t *testing.T) { ctx := addContextParams(ctx, []Param{{Name: "a"}}) if v := ctx.Value(paramCtxKey); v != nil { t.Errorf("expected no param context values, got %v", v) @@ -34,9 +33,7 @@ func TestAddContextParams(t *testing.T) { }) // Enable Alpha features. - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - ctx = config.ToContext(ctx, cfg) + ctx = WithImplicitParamsEnabled(ctx, true) // These test cases should run sequentially. Each step will modify the // above context. @@ -120,7 +117,7 @@ func TestAddContextParams(t *testing.T) { func TestAddContextParamSpec(t *testing.T) { ctx := context.Background() - t.Run("no-alpha", func(t *testing.T) { + t.Run("not-enabled", func(t *testing.T) { ctx := addContextParamSpec(ctx, []ParamSpec{{Name: "a"}}) if v := ctx.Value(paramCtxKey); v != nil { t.Errorf("expected no param context values, got %v", v) @@ -128,9 +125,7 @@ func TestAddContextParamSpec(t *testing.T) { }) // Enable Alpha features. - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - ctx = config.ToContext(ctx, cfg) + ctx = WithImplicitParamsEnabled(ctx, true) // These test cases should run sequentially. Each step will modify the // above context. @@ -213,7 +208,7 @@ func TestGetContextParams(t *testing.T) { Description: "racecar", }, } - t.Run("no-alpha", func(t *testing.T) { + t.Run("not-enabled", func(t *testing.T) { ctx := addContextParamSpec(ctx, want) if v := getContextParamSpecs(ctx); v != nil { t.Errorf("expected no param context values, got %v", v) @@ -221,9 +216,7 @@ func TestGetContextParams(t *testing.T) { }) // Enable Alpha features. - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - ctx = config.ToContext(ctx, cfg) + ctx = WithImplicitParamsEnabled(ctx, true) ctx = addContextParamSpec(ctx, want) @@ -294,7 +287,7 @@ func TestGetContextParamSpecs(t *testing.T) { Description: "racecar", }, } - t.Run("no-alpha", func(t *testing.T) { + t.Run("not-enabled", func(t *testing.T) { ctx := addContextParamSpec(ctx, want) if v := getContextParamSpecs(ctx); v != nil { t.Errorf("expected no param context values, got %v", v) @@ -302,9 +295,7 @@ func TestGetContextParamSpecs(t *testing.T) { }) // Enable Alpha features. - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - ctx = config.ToContext(ctx, cfg) + ctx = WithImplicitParamsEnabled(ctx, true) ctx = addContextParamSpec(ctx, want) got := getContextParamSpecs(ctx) diff --git a/pkg/apis/pipeline/v1beta1/pipeline_defaults.go b/pkg/apis/pipeline/v1beta1/pipeline_defaults.go index 8d77712f8b1..5fa619370b8 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_defaults.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_defaults.go @@ -19,7 +19,6 @@ package v1beta1 import ( "context" - "github.com/tektoncd/pipeline/pkg/apis/config" "knative.dev/pkg/apis" ) @@ -35,7 +34,7 @@ func (ps *PipelineSpec) SetDefaults(ctx context.Context) { for i := range ps.Params { ps.Params[i].SetDefaults(ctx) } - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + if GetImplicitParamsEnabled(ctx) { ctx = addContextParamSpec(ctx, ps.Params) ps.Params = getContextParamSpecs(ctx) } @@ -50,7 +49,7 @@ func (ps *PipelineSpec) SetDefaults(ctx context.Context) { if pt.TaskSpec != nil { // Only propagate param context to the spec - ref params should // still be explicitly set. - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + if GetImplicitParamsEnabled(ctx) { ctx = addContextParams(ctx, pt.Params) ps.Tasks[i].Params = getContextParams(ctx, pt.Params...) } @@ -66,7 +65,7 @@ func (ps *PipelineSpec) SetDefaults(ctx context.Context) { } } if ft.TaskSpec != nil { - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + if GetImplicitParamsEnabled(ctx) { ctx = addContextParams(ctx, ft.Params) ps.Finally[i].Params = getContextParams(ctx, ft.Params...) } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go b/pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go index 3ea3831b521..4d51326ee4a 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go @@ -34,6 +34,10 @@ func (pr *PipelineRun) SetDefaults(ctx context.Context) { // SetDefaults implements apis.Defaultable func (prs *PipelineRunSpec) SetDefaults(ctx context.Context) { + if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + ctx = WithImplicitParamsEnabled(ctx, true) + } + cfg := config.FromContextOrDefaults(ctx) if prs.Timeout == nil && prs.Timeouts == nil { prs.Timeout = &metav1.Duration{Duration: time.Duration(cfg.Defaults.DefaultTimeoutMinutes) * time.Minute} @@ -52,7 +56,7 @@ func (prs *PipelineRunSpec) SetDefaults(ctx context.Context) { prs.PodTemplate = mergePodTemplateWithDefault(prs.PodTemplate, defaultPodTemplate) if prs.PipelineSpec != nil { - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + if GetImplicitParamsEnabled(ctx) { ctx = addContextParams(ctx, prs.Params) } prs.PipelineSpec.SetDefaults(ctx) diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go index 3daac7b6b49..69f1a17bfde 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go @@ -34,10 +34,9 @@ import ( func TestPipelineRunSpec_SetDefaults(t *testing.T) { cases := []struct { - desc string - prs *v1beta1.PipelineRunSpec - want *v1beta1.PipelineRunSpec - ctxFn func(context.Context) context.Context + desc string + prs *v1beta1.PipelineRunSpec + want *v1beta1.PipelineRunSpec }{ { desc: "timeout is nil", @@ -84,173 +83,10 @@ func TestPipelineRunSpec_SetDefaults(t *testing.T) { }, }, }, - { - desc: "implicit params", - ctxFn: func(ctx context.Context) context.Context { - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - return config.ToContext(ctx, cfg) - }, - prs: &v1beta1.PipelineRunSpec{ - Params: []v1beta1.Param{ - { - Name: "foo", - Value: v1beta1.ArrayOrString{ - StringVal: "a", - }, - }, - { - Name: "bar", - Value: v1beta1.ArrayOrString{ - ArrayVal: []string{"b"}, - }, - }, - }, - PipelineSpec: &v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{ - { - TaskSpec: &v1beta1.EmbeddedTask{ - TaskSpec: v1beta1.TaskSpec{}, - }, - }, - { - TaskRef: &v1beta1.TaskRef{ - Name: "baz", - }, - }, - }, - Finally: []v1beta1.PipelineTask{ - { - TaskSpec: &v1beta1.EmbeddedTask{ - TaskSpec: v1beta1.TaskSpec{}, - }, - }, - { - TaskRef: &v1beta1.TaskRef{ - Name: "baz", - }, - }, - }, - }, - }, - want: &v1beta1.PipelineRunSpec{ - ServiceAccountName: config.DefaultServiceAccountValue, - Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, - Params: []v1beta1.Param{ - { - Name: "foo", - Value: v1beta1.ArrayOrString{ - StringVal: "a", - }, - }, - { - Name: "bar", - Value: v1beta1.ArrayOrString{ - ArrayVal: []string{"b"}, - }, - }, - }, - PipelineSpec: &v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{ - { - TaskSpec: &v1beta1.EmbeddedTask{ - TaskSpec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "foo", - Type: v1beta1.ParamTypeString, - }, - { - Name: "bar", - Type: v1beta1.ParamTypeArray, - }, - }, - }, - }, - Params: []v1beta1.Param{ - { - Name: "foo", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "$(params.foo)", - }, - }, - { - Name: "bar", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"$(params.bar[*])"}, - }, - }, - }, - }, - { - TaskRef: &v1beta1.TaskRef{ - Name: "baz", - Kind: v1beta1.NamespacedTaskKind, - }, - }, - }, - Finally: []v1beta1.PipelineTask{ - { - TaskSpec: &v1beta1.EmbeddedTask{ - TaskSpec: v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ - { - Name: "foo", - Type: v1beta1.ParamTypeString, - }, - { - Name: "bar", - Type: v1beta1.ParamTypeArray, - }, - }, - }, - }, - Params: []v1beta1.Param{ - { - Name: "foo", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "$(params.foo)", - }, - }, - { - Name: "bar", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"$(params.bar[*])"}, - }, - }, - }, - }, - { - TaskRef: &v1beta1.TaskRef{ - Name: "baz", - Kind: v1beta1.NamespacedTaskKind, - }, - }, - }, - Params: []v1beta1.ParamSpec{ - { - Name: "foo", - Type: v1beta1.ParamTypeString, - }, - { - Name: "bar", - Type: v1beta1.ParamTypeArray, - }, - }, - }, - }, - }, } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { ctx := context.Background() - if tc.ctxFn != nil { - ctx = tc.ctxFn(ctx) - } tc.prs.SetDefaults(ctx) sortParamSpecs := func(x, y v1beta1.ParamSpec) bool { diff --git a/pkg/apis/pipeline/v1beta1/task_defaults.go b/pkg/apis/pipeline/v1beta1/task_defaults.go index f56d03deedd..2b1eb4575da 100644 --- a/pkg/apis/pipeline/v1beta1/task_defaults.go +++ b/pkg/apis/pipeline/v1beta1/task_defaults.go @@ -19,7 +19,6 @@ package v1beta1 import ( "context" - "github.com/tektoncd/pipeline/pkg/apis/config" "knative.dev/pkg/apis" ) @@ -35,7 +34,7 @@ func (ts *TaskSpec) SetDefaults(ctx context.Context) { for i := range ts.Params { ts.Params[i].SetDefaults(ctx) } - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + if GetImplicitParamsEnabled(ctx) { ctx = addContextParamSpec(ctx, ts.Params) ts.Params = getContextParamSpecs(ctx) } diff --git a/pkg/apis/pipeline/v1beta1/taskrun_defaults.go b/pkg/apis/pipeline/v1beta1/taskrun_defaults.go index a36d596b303..75f6be0110a 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_defaults.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_defaults.go @@ -48,6 +48,10 @@ func (tr *TaskRun) SetDefaults(ctx context.Context) { // SetDefaults implements apis.Defaultable func (trs *TaskRunSpec) SetDefaults(ctx context.Context) { + if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + ctx = WithImplicitParamsEnabled(ctx, true) + } + cfg := config.FromContextOrDefaults(ctx) if trs.TaskRef != nil && trs.TaskRef.Kind == "" { trs.TaskRef.Kind = NamespacedTaskKind @@ -67,7 +71,7 @@ func (trs *TaskRunSpec) SetDefaults(ctx context.Context) { // If this taskrun has an embedded task, apply the usual task defaults if trs.TaskSpec != nil { - if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" { + if GetImplicitParamsEnabled(ctx) { ctx = addContextParams(ctx, trs.Params) } trs.TaskSpec.SetDefaults(ctx) diff --git a/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go b/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go index a00de5c5b80..4eaab5413ce 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go @@ -38,10 +38,9 @@ var ( func TestTaskRunSpec_SetDefaults(t *testing.T) { cases := []struct { - desc string - trs *v1beta1.TaskRunSpec - want *v1beta1.TaskRunSpec - ctxFn func(context.Context) context.Context + desc string + trs *v1beta1.TaskRunSpec + want *v1beta1.TaskRunSpec }{{ desc: "taskref is nil", trs: &v1beta1.TaskRunSpec{ @@ -118,79 +117,10 @@ func TestTaskRunSpec_SetDefaults(t *testing.T) { ServiceAccountName: config.DefaultServiceAccountValue, Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, }, - }, { - desc: "implicit string param", - ctxFn: func(ctx context.Context) context.Context { - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - return config.ToContext(ctx, cfg) - }, - trs: &v1beta1.TaskRunSpec{ - TaskSpec: &v1beta1.TaskSpec{}, - Params: []v1beta1.Param{{ - Name: "param-name", - Value: v1beta1.ArrayOrString{ - StringVal: "a", - }, - }}, - }, - want: &v1beta1.TaskRunSpec{ - TaskSpec: &v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{{ - Name: "param-name", - Type: v1beta1.ParamTypeString, - }}, - }, - Params: []v1beta1.Param{{ - Name: "param-name", - Value: v1beta1.ArrayOrString{ - StringVal: "a", - }, - }}, - ServiceAccountName: config.DefaultServiceAccountValue, - Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, - }, - }, { - desc: "implicit array param", - ctxFn: func(ctx context.Context) context.Context { - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags = &config.FeatureFlags{EnableAPIFields: "alpha"} - return config.ToContext(ctx, cfg) - }, - trs: &v1beta1.TaskRunSpec{ - TaskSpec: &v1beta1.TaskSpec{}, - Params: []v1beta1.Param{{ - Name: "param-name", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"a"}, - }, - }}, - }, - want: &v1beta1.TaskRunSpec{ - TaskSpec: &v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{{ - Name: "param-name", - Type: v1beta1.ParamTypeArray, - }}, - }, - Params: []v1beta1.Param{{ - Name: "param-name", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeArray, - ArrayVal: []string{"a"}, - }, - }}, - ServiceAccountName: config.DefaultServiceAccountValue, - Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, - }, }} for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { ctx := context.Background() - if tc.ctxFn != nil { - ctx = tc.ctxFn(ctx) - } tc.trs.SetDefaults(ctx) if d := cmp.Diff(tc.want, tc.trs); d != "" { diff --git a/third_party/vendor/golang.org/x/sys/cpu/LICENSE b/third_party/vendor/golang.org/x/sys/cpu/LICENSE deleted file mode 100644 index 6a66aea5eaf..00000000000 --- a/third_party/vendor/golang.org/x/sys/cpu/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.