-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit is the first step of TEP-0076, to support array and object in resutls we need to add type for TaskResult and TaskRunResult first. Before this commit we don't have the Type for these results.
- Loading branch information
1 parent
919edfe
commit c8f3fb5
Showing
11 changed files
with
181 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import "context" | ||
|
||
// SetDefaults set the default type for TaskResult | ||
func (tr *TaskResult) SetDefaults(ctx context.Context) { | ||
if tr != nil && tr.Type == "" { | ||
// ResultsTypeString is the default value | ||
tr.Type = ResultsTypeString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
// TaskResult used to describe the results of a task | ||
type TaskResult struct { | ||
// Name the given name | ||
Name string `json:"name"` | ||
|
||
// Type is the user-specified type of the result. The possible type | ||
// is currently "string" and will support "array" in following work. | ||
// +optional | ||
Type ResultsType `json:"type,omitempty"` | ||
|
||
// Description is a human-readable description of the result | ||
// +optional | ||
Description string `json:"description"` | ||
} | ||
|
||
// TaskRunResult used to describe the results of a task | ||
type TaskRunResult struct { | ||
// Name the given name | ||
Name string `json:"name"` | ||
|
||
// Type is the user-specified type of the result. The possible type | ||
// is currently "string" and will support "array" in following work. | ||
// +optional | ||
Type ResultsType `json:"type,omitempty"` | ||
|
||
// Value the given value of the result | ||
Value string `json:"value"` | ||
} | ||
|
||
// ResultsType indicates the type of a result; | ||
// Used to distinguish between a single string and an array of strings. | ||
// Note that there is ResultType used to find out whether a | ||
// PipelineResourceResult is from a task result or not, which is different from | ||
// this ResultsType. | ||
// TODO(#4723): add "array" and "object" support | ||
// TODO(#4723): align ResultsType and ParamType in ArrayOrString | ||
type ResultsType string | ||
|
||
// Valid ResultsType: | ||
const ( | ||
ResultsTypeString ResultsType = "string" | ||
) | ||
|
||
// AllResultsTypes can be used for ResultsTypes validation. | ||
var AllResultsTypes = []ResultsType{ResultsTypeString} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// Validate implements apis.Validatable | ||
func (tr TaskResult) Validate(_ context.Context) *apis.FieldError { | ||
if !resultNameFormatRegex.MatchString(tr.Name) { | ||
return apis.ErrInvalidKeyName(tr.Name, "name", fmt.Sprintf("Name must consist of alphanumeric characters, '-', '_', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my-name', or 'my_name', regex used for validation is '%s')", ResultNameFormat)) | ||
} | ||
// Validate the result type | ||
validType := false | ||
for _, allowedType := range AllResultsTypes { | ||
if tr.Type == allowedType { | ||
validType = true | ||
} | ||
} | ||
if !validType { | ||
return apis.ErrInvalidValue(tr.Type, "type", fmt.Sprintf("type must be string")) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters