Skip to content

Commit

Permalink
Remove deprecated PascalCase fields in WhenExpressions
Browse files Browse the repository at this point in the history
This change removes the deprecated PascalCase fields in `WhenExpressions`

The fields in `WhenExpressions` were missing json annotations in
tektoncd#3135 so they were
PascalCase - released in v0.16

The json annotations were added and supported both PascalCase and
lowercase fields for backwards compatibility in
tektoncd#3291 and
tektoncd#3389 - released in v0.17

The PascalCase fields were deprecated in v0.17, with an earliest date of
removal of Jan 07 2021 - https://github.com/tektoncd/pipeline/blob/v0.23.0/docs/deprecations.md
  • Loading branch information
jerop committed May 7, 2021
1 parent 5addfb3 commit 9577024
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 144 deletions.
3 changes: 1 addition & 2 deletions docs/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ being deprecated.
| [Step `workingDir` defaults to `/workspace`](https://github.com/tektoncd/pipeline/issues/1836) | [v0.11.0-rc1](https://github.com/tektoncd/pipeline/releases/tag/v0.11.0-rc1) | Beta | December 4 2020 |
| [The `TaskRun.Status.ResourceResults.ResourceRef` field is deprecated and will be removed.](https://github.com/tektoncd/pipeline/issues/2694) | [v0.14.0](https://github.com/tektoncd/pipeline/releases/tag/v0.14.0) | Beta | April 30 2021 |
| [The `PipelineRun.Spec.ServiceAccountNames` field is deprecated and will be removed.](https://github.com/tektoncd/pipeline/issues/2614) | [v0.15.0](https://github.com/tektoncd/pipeline/releases/tag/v0.15.0) | Beta | May 15 2021 |
| [`Conditions` CRD is deprecated and will be removed. Use `WhenExpressions` instead.](https://github.com/tektoncd/community/blob/main/teps/0007-conditions-beta.md) | [v0.16.0](https://github.com/tektoncd/pipeline/releases/tag/v0.16.0) | Alpha | Nov 02 2020 |
| [The PascalCase fields in WhenExpressions is deprecated and will be removed](https://github.com/tektoncd/pipeline/pull/3389) | [v0.17.2](https://github.com/tektoncd/pipeline/releases/tag/v0.17.2) | Alpha | Jan 07 2021 |
| [`Conditions` CRD is deprecated and will be removed. Use `WhenExpressions` instead.](https://github.com/tektoncd/community/blob/main/teps/0007-conditions-beta.md) | [v0.16.0](https://github.com/tektoncd/pipeline/releases/tag/v0.16.0) | Alpha | Nov 02 2020 |
29 changes: 0 additions & 29 deletions pkg/apis/pipeline/v1beta1/openapi_generated.go

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

16 changes: 0 additions & 16 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2443,22 +2443,6 @@
"values"
],
"properties": {
"Input": {
"description": "DeprecatedInput for backwards compatibility with \u003cv0.17 it is the string for guard checking which can be a static input or an output from a parent Task",
"type": "string"
},
"Operator": {
"description": "DeprecatedOperator for backwards compatibility with \u003cv0.17 it represents a DeprecatedInput's relationship to the DeprecatedValues",
"type": "string"
},
"Values": {
"description": "DeprecatedValues for backwards compatibility with \u003cv0.17 it represents a DeprecatedInput's relationship to the DeprecatedValues",
"type": "array",
"items": {
"type": "string",
"default": ""
}
},
"input": {
"description": "Input is the string for guard checking which can be a static input or an output from a parent Task",
"type": "string",
Expand Down
58 changes: 8 additions & 50 deletions pkg/apis/pipeline/v1beta1/when_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,26 @@ type WhenExpression struct {
// Input is the string for guard checking which can be a static input or an output from a parent Task
Input string `json:"input"`

// DeprecatedInput for backwards compatibility with <v0.17
// it is the string for guard checking which can be a static input or an output from a parent Task
// +optional
DeprecatedInput string `json:"Input,omitempty"`

// Operator that represents an Input's relationship to the values
Operator selection.Operator `json:"operator"`

// DeprecatedOperator for backwards compatibility with <v0.17
// it represents a DeprecatedInput's relationship to the DeprecatedValues
// +optional
DeprecatedOperator selection.Operator `json:"Operator,omitempty"`

// Values is an array of strings, which is compared against the input, for guard checking
// It must be non-empty
Values []string `json:"values"`

// DeprecatedValues for backwards compatibility with <v0.17
// it represents a DeprecatedInput's relationship to the DeprecatedValues
// +optional
DeprecatedValues []string `json:"Values,omitempty"`
}

// GetInput returns the input string for guard checking
// based on DeprecatedInput (<v0.17) and Input
func (we *WhenExpression) GetInput() string {
if we.Input == "" {
return we.DeprecatedInput
}
return we.Input
}

// GetOperator returns the relationship between input and values
// based on DeprecatedOperator (<v0.17) and Operator
func (we *WhenExpression) GetOperator() selection.Operator {
if we.Operator == "" {
return we.DeprecatedOperator
}
return we.Operator
}

// GetValues returns an array of strings which is compared against the input
// based on DeprecatedValues (<v0.17) and Values
func (we *WhenExpression) GetValues() []string {
if we.Values == nil {
return we.DeprecatedValues
}
return we.Values
}

func (we *WhenExpression) isInputInValues() bool {
values := we.GetValues()
for i := range values {
if values[i] == we.GetInput() {
for i := range we.Values {
if we.Values[i] == we.Input {
return true
}
}
return false
}

func (we *WhenExpression) isTrue() bool {
if we.GetOperator() == selection.In {
if we.Operator == selection.In {
return we.isInputInValues()
}
// selection.NotIn
Expand All @@ -103,21 +61,21 @@ func (we *WhenExpression) hasVariable() bool {
}

func (we *WhenExpression) applyReplacements(replacements map[string]string) WhenExpression {
replacedInput := substitution.ApplyReplacements(we.GetInput(), replacements)
replacedInput := substitution.ApplyReplacements(we.Input, replacements)

var replacedValues []string
for _, val := range we.GetValues() {
for _, val := range we.Values {
replacedValues = append(replacedValues, substitution.ApplyReplacements(val, replacements))
}

return WhenExpression{Input: replacedInput, Operator: we.GetOperator(), Values: replacedValues}
return WhenExpression{Input: replacedInput, Operator: we.Operator, Values: replacedValues}
}

// GetVarSubstitutionExpressions extracts all the values between "$(" and ")" in a When Expression
func (we *WhenExpression) GetVarSubstitutionExpressions() ([]string, bool) {
var allExpressions []string
allExpressions = append(allExpressions, validateString(we.GetInput())...)
for _, value := range we.GetValues() {
allExpressions = append(allExpressions, validateString(we.Input)...)
for _, value := range we.Values {
allExpressions = append(allExpressions, validateString(value)...)
}
return allExpressions, len(allExpressions) != 0
Expand Down
23 changes: 5 additions & 18 deletions pkg/apis/pipeline/v1beta1/when_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,13 @@ func (we *WhenExpression) validateWhenExpressionFields() *apis.FieldError {
if equality.Semantic.DeepEqual(we, &WhenExpression{}) || we == nil {
return apis.ErrMissingField(apis.CurrentField)
}
if !sets.NewString(validWhenOperators...).Has(string(we.GetOperator())) {
message := fmt.Sprintf("operator %q is not recognized. valid operators: %s", we.GetOperator(), strings.Join(validWhenOperators, ","))
if !sets.NewString(validWhenOperators...).Has(string(we.Operator)) {
message := fmt.Sprintf("operator %q is not recognized. valid operators: %s", we.Operator, strings.Join(validWhenOperators, ","))
return apis.ErrInvalidValue(message, apis.CurrentField)
}
if len(we.GetValues()) == 0 {
if len(we.Values) == 0 {
return apis.ErrInvalidValue("expecting non-empty values field", apis.CurrentField)
}
return we.validateWhenExpressionsDuplicateFields()
}

func (we *WhenExpression) validateWhenExpressionsDuplicateFields() *apis.FieldError {
if we.Input != "" && we.DeprecatedInput != "" {
return apis.ErrMultipleOneOf("input", "Input")
}
if we.Operator != "" && we.DeprecatedOperator != "" {
return apis.ErrMultipleOneOf("operator", "Operator")
}
if we.Values != nil && we.DeprecatedValues != nil {
return apis.ErrMultipleOneOf("values", "Values")
}
return nil
}

Expand All @@ -90,8 +77,8 @@ func (wes WhenExpressions) validateTaskResultsVariables() *apis.FieldError {

func (wes WhenExpressions) validatePipelineParametersVariables(prefix string, paramNames sets.String, arrayParamNames sets.String) (errs *apis.FieldError) {
for idx, we := range wes {
errs = errs.Also(validateStringVariable(we.GetInput(), prefix, paramNames, arrayParamNames).ViaField("input").ViaFieldIndex("when", idx))
for _, val := range we.GetValues() {
errs = errs.Also(validateStringVariable(we.Input, prefix, paramNames, arrayParamNames).ViaField("input").ViaFieldIndex("when", idx))
for _, val := range we.Values {
errs = errs.Also(validateStringVariable(val, prefix, paramNames, arrayParamNames).ViaField("values").ViaFieldIndex("when", idx))
}
}
Expand Down
24 changes: 0 additions & 24 deletions pkg/apis/pipeline/v1beta1/when_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,6 @@ func TestWhenExpressions_Invalid(t *testing.T) {
Operator: selection.In,
Values: []string{"bar"},
}},
}, {
name: "multiple inputs",
wes: []WhenExpression{{
Input: "foo",
DeprecatedInput: "nay",
Operator: selection.In,
Values: []string{"bar"},
}},
}, {
name: "multiple operators",
wes: []WhenExpression{{
Input: "foo",
Operator: selection.In,
DeprecatedOperator: selection.NotIn,
Values: []string{"bar"},
}},
}, {
name: "multiple values",
wes: []WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"bar"},
DeprecatedValues: []string{"bar"},
}},
}, {
name: "missing when expression",
wes: []WhenExpression{{}},
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

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

0 comments on commit 9577024

Please sign in to comment.