Skip to content

Commit

Permalink
propagating params to beta
Browse files Browse the repository at this point in the history
Propagated Parameters was deployed as an alpha feature in release v0.36.0. This PR promotes it to beta by removing the constraints applied under the alpha feature. This PR addresses issue tektoncd#4955.
  • Loading branch information
chitrangpatel authored and JeromeJu committed Oct 24, 2022
1 parent d7f56dc commit d659d64
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 77 deletions.
4 changes: 2 additions & 2 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ go through the complexity of checking each `Pipeline` and providing only the req

#### Propagated Parameters

**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))**

When using an inlined spec, parameters from the parent `PipelineRun` will be
propagated to any inlined specs without needing to be explicitly defined. This
allows authors to simplify specs by automatically propagating top-level
Expand Down Expand Up @@ -668,6 +666,8 @@ status:

##### Object Parameters

**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))**

When using an inlined spec, object parameters from the parent `PipelineRun` will also be
propagated to any inlined specs without needing to be explicitly defined. This
allows authors to simplify specs by automatically propagating top-level
Expand Down
2 changes: 0 additions & 2 deletions docs/taskruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ spec:

#### Propagated Parameters

**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))**

When using an inlined `taskSpec`, parameters from the parent `TaskRun` will be
available to the `Task` without needing to be explicitly defined.

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestTaskSpecValidatePropagatedParamsAndWorkspaces(t *testing.T) {
Workspaces: tt.fields.Workspaces,
Results: tt.fields.Results,
}
ctx := config.EnableAlphaAPIFields(context.Background())
ctx := config.EnableBetaAPIFields(context.Background())
ts.SetDefaults(ctx)
ctx = config.SkipValidationDueToPropagatedParametersAndWorkspaces(ctx, true)
if err := ts.Validate(ctx); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/pipeline/v1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestTaskRun_Invalidate(t *testing.T) {
Message: `non-existent variable in "$(params.task-words[*])"`,
Paths: []string{"spec.steps[0].args[0]"},
},
wc: config.EnableAlphaAPIFields,
wc: config.EnableBetaAPIFields,
}, {
name: "propagating object params not provided but used by step",
taskRun: &v1.TaskRun{
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
wc: config.EnableBetaAPIFields,
}, {
name: "propagating object params from taskrun to steps",
taskRun: &v1.TaskRun{
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
wc: config.EnableBetaAPIFields,
}, {
name: "propagating object params with one declared in taskspec and other provided by taskrun",
taskRun: &v1.TaskRun{
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
wc: config.EnableBetaAPIFields,
}, {
name: "propagating partial object params with multiple keys",
taskRun: &v1.TaskRun{
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
wc: config.EnableBetaAPIFields,
}, {
name: "object params without propagation",
taskRun: &v1.TaskRun{
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestTaskSpecValidatePropagatedParamsAndWorkspaces(t *testing.T) {
Workspaces: tt.fields.Workspaces,
Results: tt.fields.Results,
}
ctx := config.EnableAlphaAPIFields(context.Background())
ctx := context.Background()
ts.SetDefaults(ctx)
ctx = config.SkipValidationDueToPropagatedParametersAndWorkspaces(ctx, true)
if err := ts.Validate(ctx); err != nil {
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/pipeline/v1beta1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func TestTaskRun_Invalidate(t *testing.T) {
Message: `non-existent variable in "$(params.task-words[*])"`,
Paths: []string{"spec.steps[0].args[0]"},
},
wc: config.EnableAlphaAPIFields,
}, {
name: "propagating object params not provided but used by step",
taskRun: &v1beta1.TaskRun{
Expand Down Expand Up @@ -167,7 +166,6 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
}, {
name: "propagating object params with taskrun",
taskRun: &v1beta1.TaskRun{
Expand Down Expand Up @@ -255,7 +253,6 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
}, {
name: "propagating object params with one declared in taskspec and other provided by taskrun",
taskRun: &v1beta1.TaskRun{
Expand Down Expand Up @@ -324,7 +321,6 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
}, {
name: "propagating partial object params with multiple keys",
taskRun: &v1beta1.TaskRun{
Expand Down Expand Up @@ -386,7 +382,6 @@ func TestTaskRun_Validate(t *testing.T) {
},
},
},
wc: config.EnableAlphaAPIFields,
}, {
name: "object params without propagation",
taskRun: &v1beta1.TaskRun{
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get

// Apply parameter substitution from the PipelineRun
pipelineSpec = resources.ApplyParameters(ctx, pipelineSpec, pr)
pipelineSpec = resources.ApplyContexts(ctx, pipelineSpec, pipelineMeta.Name, pr)
pipelineSpec = resources.ApplyWorkspaces(ctx, pipelineSpec, pr)
pipelineSpec = resources.ApplyContexts(pipelineSpec, pipelineMeta.Name, pr)
pipelineSpec = resources.ApplyWorkspaces(pipelineSpec, pr)
// Update pipelinespec of pipelinerun's status field
pr.Status.PipelineSpec = pipelineSpec

Expand Down
20 changes: 10 additions & 10 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ApplyParameters(ctx context.Context, p *v1beta1.PipelineSpec, pr *v1beta1.P
objectReplacements[k] = v
}

return ApplyReplacements(ctx, p, stringReplacements, arrayReplacements, objectReplacements)
return ApplyReplacements(p, stringReplacements, arrayReplacements, objectReplacements)
}

func paramsFromPipelineRun(ctx context.Context, pr *v1beta1.PipelineRun) (map[string]string, map[string][]string, map[string]map[string]string) {
Expand Down Expand Up @@ -151,8 +151,8 @@ func getContextReplacements(pipelineName string, pr *v1beta1.PipelineRun) map[st

// ApplyContexts applies the substitution from $(context.(pipelineRun|pipeline).*) with the specified values.
// Currently supports only name substitution. Uses "" as a default if name is not specified.
func ApplyContexts(ctx context.Context, spec *v1beta1.PipelineSpec, pipelineName string, pr *v1beta1.PipelineRun) *v1beta1.PipelineSpec {
return ApplyReplacements(ctx, spec, getContextReplacements(pipelineName, pr), map[string][]string{}, map[string]map[string]string{})
func ApplyContexts(spec *v1beta1.PipelineSpec, pipelineName string, pr *v1beta1.PipelineRun) *v1beta1.PipelineSpec {
return ApplyReplacements(spec, getContextReplacements(pipelineName, pr), map[string][]string{}, map[string]map[string]string{})
}

// ApplyPipelineTaskContexts applies the substitution from $(context.pipelineTask.*) with the specified values.
Expand Down Expand Up @@ -207,7 +207,7 @@ func ApplyPipelineTaskStateContext(state PipelineRunState, replacements map[stri

// ApplyWorkspaces replaces workspace variables in the given pipeline spec with their
// concrete values.
func ApplyWorkspaces(ctx context.Context, p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) *v1beta1.PipelineSpec {
func ApplyWorkspaces(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) *v1beta1.PipelineSpec {
p = p.DeepCopy()
replacements := map[string]string{}
for _, declaredWorkspace := range p.Workspaces {
Expand All @@ -218,11 +218,11 @@ func ApplyWorkspaces(ctx context.Context, p *v1beta1.PipelineSpec, pr *v1beta1.P
key := fmt.Sprintf("workspaces.%s.bound", boundWorkspace.Name)
replacements[key] = "true"
}
return ApplyReplacements(ctx, p, replacements, map[string][]string{}, map[string]map[string]string{})
return ApplyReplacements(p, replacements, map[string][]string{}, map[string]map[string]string{})
}

// ApplyReplacements replaces placeholders for declared parameters with the specified replacements.
func ApplyReplacements(ctx context.Context, p *v1beta1.PipelineSpec, replacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) *v1beta1.PipelineSpec {
func ApplyReplacements(p *v1beta1.PipelineSpec, replacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) *v1beta1.PipelineSpec {
p = p.DeepCopy()

for i := range p.Tasks {
Expand All @@ -237,7 +237,7 @@ func ApplyReplacements(ctx context.Context, p *v1beta1.PipelineSpec, replacement
if p.Tasks[i].TaskRef != nil && p.Tasks[i].TaskRef.Params != nil {
p.Tasks[i].TaskRef.Params = replaceParamValues(p.Tasks[i].TaskRef.Params, replacements, arrayReplacements, objectReplacements)
}
p.Tasks[i], replacements, arrayReplacements, objectReplacements = propagateParams(ctx, p.Tasks[i], replacements, arrayReplacements, objectReplacements)
p.Tasks[i], replacements, arrayReplacements, objectReplacements = propagateParams(p.Tasks[i], replacements, arrayReplacements, objectReplacements)
}

for i := range p.Finally {
Expand All @@ -252,14 +252,14 @@ func ApplyReplacements(ctx context.Context, p *v1beta1.PipelineSpec, replacement
if p.Finally[i].TaskRef != nil && p.Finally[i].TaskRef.Params != nil {
p.Finally[i].TaskRef.Params = replaceParamValues(p.Finally[i].TaskRef.Params, replacements, arrayReplacements, objectReplacements)
}
p.Finally[i], replacements, arrayReplacements, objectReplacements = propagateParams(ctx, p.Finally[i], replacements, arrayReplacements, objectReplacements)
p.Finally[i], replacements, arrayReplacements, objectReplacements = propagateParams(p.Finally[i], replacements, arrayReplacements, objectReplacements)
}

return p
}

func propagateParams(ctx context.Context, t v1beta1.PipelineTask, replacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) (v1beta1.PipelineTask, map[string]string, map[string][]string, map[string]map[string]string) {
if t.TaskSpec != nil && config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha" {
func propagateParams(t v1beta1.PipelineTask, replacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) (v1beta1.PipelineTask, map[string]string, map[string][]string, map[string]map[string]string) {
if t.TaskSpec != nil {
// check if there are task parameters defined that match the params at pipeline level
if len(t.Params) > 0 {
for _, par := range t.Params {
Expand Down
Loading

0 comments on commit d659d64

Please sign in to comment.