Skip to content

Commit e98f5d4

Browse files
committedMay 11, 2021
Remove deprecated PascalCase fields in WhenExpressions
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
1 parent b86a9a2 commit e98f5d4

8 files changed

+13
-146
lines changed
 

‎docs/deprecations.md

-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ being deprecated.
2323
| [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 |
2424
| [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 |
2525
| [`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 |
26-
| [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 |
2726
| [The `disable-home-env-overwrite` flag will be removed](https://github.com/tektoncd/pipeline/issues/2013) | [v0.24.0](https://github.com/tektoncd/pipeline/releases/tag/v0.24.0) | Beta | February 10 2022 |
2827
| [The `disable-working-dir-overwrite` flag will be removed](https://github.com/tektoncd/pipeline/issues/1836) | [v0.24.0](https://github.com/tektoncd/pipeline/releases/tag/v0.24.0) | Beta | February 10 2022 |

‎go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/apis/pipeline/v1beta1/openapi_generated.go

-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/apis/pipeline/v1beta1/swagger.json

-16
Original file line numberDiff line numberDiff line change
@@ -2467,22 +2467,6 @@
24672467
"values"
24682468
],
24692469
"properties": {
2470-
"Input": {
2471-
"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",
2472-
"type": "string"
2473-
},
2474-
"Operator": {
2475-
"description": "DeprecatedOperator for backwards compatibility with \u003cv0.17 it represents a DeprecatedInput's relationship to the DeprecatedValues",
2476-
"type": "string"
2477-
},
2478-
"Values": {
2479-
"description": "DeprecatedValues for backwards compatibility with \u003cv0.17 it represents a DeprecatedInput's relationship to the DeprecatedValues",
2480-
"type": "array",
2481-
"items": {
2482-
"type": "string",
2483-
"default": ""
2484-
}
2485-
},
24862470
"input": {
24872471
"description": "Input is the string for guard checking which can be a static input or an output from a parent Task",
24882472
"type": "string",

‎pkg/apis/pipeline/v1beta1/when_types.go

+8-51
Original file line numberDiff line numberDiff line change
@@ -27,68 +27,25 @@ type WhenExpression struct {
2727
// Input is the string for guard checking which can be a static input or an output from a parent Task
2828
Input string `json:"input"`
2929

30-
// DeprecatedInput for backwards compatibility with <v0.17
31-
// it is the string for guard checking which can be a static input or an output from a parent Task
32-
// +optional
33-
DeprecatedInput string `json:"Input,omitempty"`
34-
3530
// Operator that represents an Input's relationship to the values
3631
Operator selection.Operator `json:"operator"`
3732

38-
// DeprecatedOperator for backwards compatibility with <v0.17
39-
// it represents a DeprecatedInput's relationship to the DeprecatedValues
40-
// +optional
41-
DeprecatedOperator selection.Operator `json:"Operator,omitempty"`
42-
4333
// Values is an array of strings, which is compared against the input, for guard checking
4434
// It must be non-empty
4535
Values []string `json:"values"`
46-
47-
// DeprecatedValues for backwards compatibility with <v0.17
48-
// it represents a DeprecatedInput's relationship to the DeprecatedValues
49-
// +optional
50-
DeprecatedValues []string `json:"Values,omitempty"`
51-
}
52-
53-
// GetInput returns the input string for guard checking
54-
// based on DeprecatedInput (<v0.17) and Input
55-
func (we *WhenExpression) GetInput() string {
56-
if we.Input == "" {
57-
return we.DeprecatedInput
58-
}
59-
return we.Input
60-
}
61-
62-
// GetOperator returns the relationship between input and values
63-
// based on DeprecatedOperator (<v0.17) and Operator
64-
func (we *WhenExpression) GetOperator() selection.Operator {
65-
if we.Operator == "" {
66-
return we.DeprecatedOperator
67-
}
68-
return we.Operator
69-
}
70-
71-
// GetValues returns an array of strings which is compared against the input
72-
// based on DeprecatedValues (<v0.17) and Values
73-
func (we *WhenExpression) GetValues() []string {
74-
if we.Values == nil {
75-
return we.DeprecatedValues
76-
}
77-
return we.Values
7836
}
7937

8038
func (we *WhenExpression) isInputInValues() bool {
81-
values := we.GetValues()
82-
for i := range values {
83-
if values[i] == we.GetInput() {
39+
for i := range we.Values {
40+
if we.Values[i] == we.Input {
8441
return true
8542
}
8643
}
8744
return false
8845
}
8946

9047
func (we *WhenExpression) isTrue() bool {
91-
if we.GetOperator() == selection.In {
48+
if we.Operator == selection.In {
9249
return we.isInputInValues()
9350
}
9451
// selection.NotIn
@@ -103,21 +60,21 @@ func (we *WhenExpression) hasVariable() bool {
10360
}
10461

10562
func (we *WhenExpression) applyReplacements(replacements map[string]string) WhenExpression {
106-
replacedInput := substitution.ApplyReplacements(we.GetInput(), replacements)
63+
replacedInput := substitution.ApplyReplacements(we.Input, replacements)
10764

10865
var replacedValues []string
109-
for _, val := range we.GetValues() {
66+
for _, val := range we.Values {
11067
replacedValues = append(replacedValues, substitution.ApplyReplacements(val, replacements))
11168
}
11269

113-
return WhenExpression{Input: replacedInput, Operator: we.GetOperator(), Values: replacedValues}
70+
return WhenExpression{Input: replacedInput, Operator: we.Operator, Values: replacedValues}
11471
}
11572

11673
// GetVarSubstitutionExpressions extracts all the values between "$(" and ")" in a When Expression
11774
func (we *WhenExpression) GetVarSubstitutionExpressions() ([]string, bool) {
11875
var allExpressions []string
119-
allExpressions = append(allExpressions, validateString(we.GetInput())...)
120-
for _, value := range we.GetValues() {
76+
allExpressions = append(allExpressions, validateString(we.Input)...)
77+
for _, value := range we.Values {
12178
allExpressions = append(allExpressions, validateString(value)...)
12279
}
12380
return allExpressions, len(allExpressions) != 0

‎pkg/apis/pipeline/v1beta1/when_validation.go

+5-18
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,13 @@ func (we *WhenExpression) validateWhenExpressionFields() *apis.FieldError {
4848
if equality.Semantic.DeepEqual(we, &WhenExpression{}) || we == nil {
4949
return apis.ErrMissingField(apis.CurrentField)
5050
}
51-
if !sets.NewString(validWhenOperators...).Has(string(we.GetOperator())) {
52-
message := fmt.Sprintf("operator %q is not recognized. valid operators: %s", we.GetOperator(), strings.Join(validWhenOperators, ","))
51+
if !sets.NewString(validWhenOperators...).Has(string(we.Operator)) {
52+
message := fmt.Sprintf("operator %q is not recognized. valid operators: %s", we.Operator, strings.Join(validWhenOperators, ","))
5353
return apis.ErrInvalidValue(message, apis.CurrentField)
5454
}
55-
if len(we.GetValues()) == 0 {
55+
if len(we.Values) == 0 {
5656
return apis.ErrInvalidValue("expecting non-empty values field", apis.CurrentField)
5757
}
58-
return we.validateWhenExpressionsDuplicateFields()
59-
}
60-
61-
func (we *WhenExpression) validateWhenExpressionsDuplicateFields() *apis.FieldError {
62-
if we.Input != "" && we.DeprecatedInput != "" {
63-
return apis.ErrMultipleOneOf("input", "Input")
64-
}
65-
if we.Operator != "" && we.DeprecatedOperator != "" {
66-
return apis.ErrMultipleOneOf("operator", "Operator")
67-
}
68-
if we.Values != nil && we.DeprecatedValues != nil {
69-
return apis.ErrMultipleOneOf("values", "Values")
70-
}
7158
return nil
7259
}
7360

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

9178
func (wes WhenExpressions) validatePipelineParametersVariables(prefix string, paramNames sets.String, arrayParamNames sets.String) (errs *apis.FieldError) {
9279
for idx, we := range wes {
93-
errs = errs.Also(validateStringVariable(we.GetInput(), prefix, paramNames, arrayParamNames).ViaField("input").ViaFieldIndex("when", idx))
94-
for _, val := range we.GetValues() {
80+
errs = errs.Also(validateStringVariable(we.Input, prefix, paramNames, arrayParamNames).ViaField("input").ViaFieldIndex("when", idx))
81+
for _, val := range we.Values {
9582
errs = errs.Also(validateStringVariable(val, prefix, paramNames, arrayParamNames).ViaField("values").ViaFieldIndex("when", idx))
9683
}
9784
}

‎pkg/apis/pipeline/v1beta1/when_validation_test.go

-24
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,6 @@ func TestWhenExpressions_Invalid(t *testing.T) {
9898
Operator: selection.In,
9999
Values: []string{"bar"},
100100
}},
101-
}, {
102-
name: "multiple inputs",
103-
wes: []WhenExpression{{
104-
Input: "foo",
105-
DeprecatedInput: "nay",
106-
Operator: selection.In,
107-
Values: []string{"bar"},
108-
}},
109-
}, {
110-
name: "multiple operators",
111-
wes: []WhenExpression{{
112-
Input: "foo",
113-
Operator: selection.In,
114-
DeprecatedOperator: selection.NotIn,
115-
Values: []string{"bar"},
116-
}},
117-
}, {
118-
name: "multiple values",
119-
wes: []WhenExpression{{
120-
Input: "foo",
121-
Operator: selection.In,
122-
Values: []string{"bar"},
123-
DeprecatedValues: []string{"bar"},
124-
}},
125101
}, {
126102
name: "missing when expression",
127103
wes: []WhenExpression{{}},

‎pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)