From f9743f6fe4295651eadc4349fcacb77f4369c76f Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Wed, 3 Jul 2024 12:51:53 +0530 Subject: [PATCH] Perform matrix results validation on only result ref params This will add a check to skip the validation of normal params while doing the validation for resultref params are provided in matrix format --- pkg/apis/pipeline/v1/pipeline_validation.go | 3 + .../pipeline/v1/pipeline_validation_test.go | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/pkg/apis/pipeline/v1/pipeline_validation.go b/pkg/apis/pipeline/v1/pipeline_validation.go index 43e56d102f5..77cfce53da5 100644 --- a/pkg/apis/pipeline/v1/pipeline_validation.go +++ b/pkg/apis/pipeline/v1/pipeline_validation.go @@ -810,6 +810,9 @@ func findAndValidateResultRefsForMatrix(tasks []PipelineTask, taskMapping map[st func validateMatrixedPipelineTaskConsumed(expressions []string, taskMapping map[string]PipelineTask) (resultRefs []*ResultRef, errs *apis.FieldError) { var filteredExpressions []string for _, expression := range expressions { + if !resultref.LooksLikeResultRef(expression) { + continue + } // ie. "tasks..results.[*]" subExpressions := strings.Split(expression, ".") pipelineTask := subExpressions[1] // pipelineTaskName diff --git a/pkg/apis/pipeline/v1/pipeline_validation_test.go b/pkg/apis/pipeline/v1/pipeline_validation_test.go index e2a67368e36..26ef9d54137 100644 --- a/pkg/apis/pipeline/v1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1/pipeline_validation_test.go @@ -175,6 +175,65 @@ func TestPipeline_Validate_Success(t *testing.T) { }}, }, }, + }, { + name: "param with different type of values", + p: &Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinelinename", + }, + Spec: PipelineSpec{ + Params: ParamSpecs{{ + Name: "pipeline-words", + Default: &ParamValue{ + Type: ParamTypeObject, + ObjectVal: map[string]string{"hello": "pipeline"}, + }, + Type: ParamTypeObject, + Properties: map[string]PropertySpec{ + "hello": {Type: ParamTypeString}, + }, + }}, + Tasks: []PipelineTask{{ + Name: "echoit", + TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{ + Steps: []Step{{ + Name: "echo", + Image: "ubuntu", + Command: []string{"echo"}, + Args: []string{"$(params.pipeline-words.hello)"}, + }}, + }}, + Params: Params{ + { + Name: "name", + Value: ParamValue{ + Type: ParamTypeString, + StringVal: "$(params.pipeline-words.hello)", + }, + }, + { + Name: "name2", + Value: ParamValue{ + Type: ParamTypeString, + StringVal: "$(tasks.pipeline-words.results.hello) + $(pipeline-words)", + }, + }, + }, + RunAfter: []string{"pipeline-words"}, + }, + { + Name: "pipeline-words", + TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{ + Steps: []Step{{ + Name: "echo", + Image: "ubuntu", + Command: []string{"echo"}, + Args: []string{"$(params.pipeline-words.hello)"}, + }}, + }}, + }}, + }, + }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {