Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kind/bug allowExecution evaluation for when expression returns early when CEL is defined #7569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/apis/pipeline/v1/when_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ type WhenExpressions []WhenExpression
// if the Task should be skipped.
func (wes WhenExpressions) AllowsExecution(evaluatedCEL map[string]bool) bool {
for _, we := range wes {
if we.CEL != "" {
return evaluatedCEL[we.CEL]
}
if !we.isTrue() {
if !we.isTrue() || (we.CEL != "" && !evaluatedCEL[we.CEL]) {
return false
}
}
Expand Down
31 changes: 30 additions & 1 deletion pkg/apis/pipeline/v1/when_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,36 @@ func TestAllowsExecution(t *testing.T) {
},
evaluatedCEL: map[string]bool{"'foo'!='foo'": false},
expected: false,
}}
},
{
name: "multiple expressions - 1. CEL is true 2. In Op is false, expect false",
whenExpressions: WhenExpressions{
{
CEL: "'foo'=='foo'",
},
{
Input: "foo",
Operator: selection.In,
Values: []string{"bar"},
},
},
evaluatedCEL: map[string]bool{"'foo'=='foo'": true},
expected: false,
},
{
name: "multiple expressions - 1. CEL is true 2. CEL is false, expect false",
whenExpressions: WhenExpressions{
{
CEL: "'foo'!='foo'",
},
{
CEL: "'xxx'!='xxx'",
},
},
evaluatedCEL: map[string]bool{"'foo'=='foo'": true, "'xxx'!='xxx'": false},
expected: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := tc.whenExpressions.AllowsExecution(tc.evaluatedCEL)
Expand Down
5 changes: 1 addition & 4 deletions pkg/apis/pipeline/v1beta1/when_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ type WhenExpressions []WhenExpression
// if the Task should be skipped.
func (wes WhenExpressions) AllowsExecution(evaluatedCEL map[string]bool) bool {
for _, we := range wes {
if we.CEL != "" {
return evaluatedCEL[we.CEL]
}
if !we.isTrue() {
if !we.isTrue() || (we.CEL != "" && !evaluatedCEL[we.CEL]) {
return false
}
}
Expand Down
31 changes: 30 additions & 1 deletion pkg/apis/pipeline/v1beta1/when_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,36 @@ func TestAllowsExecution(t *testing.T) {
},
evaluatedCEL: map[string]bool{"'foo'!='foo'": false},
expected: false,
}}
},
{
name: "multiple expressions - 1. CEL is true 2. In Op is false, expect false",
whenExpressions: WhenExpressions{
{
CEL: "'foo'=='foo'",
},
{
Input: "foo",
Operator: selection.In,
Values: []string{"bar"},
},
},
evaluatedCEL: map[string]bool{"'foo'=='foo'": true},
expected: false,
},
{
name: "multiple expressions - 1. CEL is true 2. CEL is false, expect false",
whenExpressions: WhenExpressions{
{
CEL: "'foo'!='foo'",
},
{
CEL: "'xxx'!='xxx'",
},
},
evaluatedCEL: map[string]bool{"'foo'=='foo'": true, "'xxx'!='xxx'": false},
expected: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := tc.whenExpressions.AllowsExecution(tc.evaluatedCEL)
Expand Down
Loading