Skip to content

Commit

Permalink
Relax result type validation to avoid nightly build failure
Browse files Browse the repository at this point in the history
This commit fixes the string result type validation, PR tektoncd#4779 adds
result type and asumes that the default type should be string via
mutating webhook. PR tektoncd#4818 adds the validation for this. However,
resources that did already exist in etcd didn't get the default. So this
commit relaxes the validation for empty result type.
  • Loading branch information
Yongxuanzhang committed Jun 28, 2022
1 parent 7d7d96f commit 5b4cb0c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/result_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type TaskResult struct {

// Description is a human-readable description of the result
// +optional
Description string `json:"description"`
Description string `json:"description,omitempty"`
}

// TaskRunResult used to describe the results of a task
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/pipeline/v1beta1/result_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func (tr TaskResult) Validate(ctx context.Context) (errs *apis.FieldError) {
return errs.Also(ValidateEnabledAPIFields(ctx, "results type", config.AlphaAPIFields))
}

// Skip the validation for existing resources without specifying a type and not call the setDefaults
if tr.Type == "" {
return nil
}

// By default the result type is string
if tr.Type != ResultsTypeString {
return apis.ErrInvalidValue(tr.Type, "type", fmt.Sprintf("type must be string"))
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2243,8 +2243,7 @@
"properties": {
"description": {
"description": "Description is a human-readable description of the result",
"type": "string",
"default": ""
"type": "string"
},
"name": {
"description": "Name the given name",
Expand Down
48 changes: 48 additions & 0 deletions pkg/apis/pipeline/v1beta1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,54 @@ func TestTaskSpecValidate(t *testing.T) {
}
}

func TestTaskSpecResultsValidate(t *testing.T) {
type fields struct {
Steps []v1beta1.Step
Results []v1beta1.TaskResult
}
tests := []struct {
name string
fields fields
}{{
name: "valid result type empty",
fields: fields{
Steps: []v1beta1.Step{{
Image: "my-image",
Args: []string{"arg"},
}},
Results: []v1beta1.TaskResult{{
Name: "MY-RESULT",
Description: "my great result",
}},
},
}, {
name: "valid result type string",
fields: fields{
Steps: []v1beta1.Step{{
Image: "my-image",
Args: []string{"arg"},
}},
Results: []v1beta1.TaskResult{{
Name: "MY-RESULT",
Type: "string",
Description: "my great result",
}},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ts := &v1beta1.TaskSpec{
Steps: tt.fields.Steps,
Results: tt.fields.Results,
}
ctx := getContextBasedOnFeatureFlag("stable")
if err := ts.Validate(ctx); err != nil {
t.Errorf("TaskSpec.Validate() = %v", err)
}
})
}
}

func TestTaskSpecValidateError(t *testing.T) {
type fields struct {
Params []v1beta1.ParamSpec
Expand Down

0 comments on commit 5b4cb0c

Please sign in to comment.