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

Fix context.background() in workspaceBinding validation #5101

Merged
merged 1 commit into from
Jul 7, 2022
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
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1
return nil, nil, controller.NewPermanentError(err)
}

if err := workspace.ValidateBindings(taskSpec.Workspaces, tr.Spec.Workspaces); err != nil {
if err := workspace.ValidateBindings(ctx, taskSpec.Workspaces, tr.Spec.Workspaces); err != nil {
logger.Errorf("TaskRun %q workspaces are invalid: %v", tr.Name, err)
tr.Status.MarkResourceFailed(podconvert.ReasonFailedValidation, err)
return nil, nil, controller.NewPermanentError(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/workspace/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (

// ValidateBindings will return an error if the bound workspaces in binds don't satisfy the declared
// workspaces in decls.
func ValidateBindings(decls []v1beta1.WorkspaceDeclaration, binds []v1beta1.WorkspaceBinding) error {
func ValidateBindings(ctx context.Context, decls []v1beta1.WorkspaceDeclaration, binds []v1beta1.WorkspaceBinding) error {
// This will also be validated at webhook time but in case the webhook isn't invoked for some
// reason we'll invoke the same validation here.
for _, b := range binds {
if err := b.Validate(context.Background()); err != nil {
if err := b.Validate(ctx); err != nil {
return fmt.Errorf("binding %q is invalid: %v", b.Name, err)
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/workspace/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package workspace

import (
"context"
"errors"
"testing"

Expand Down Expand Up @@ -76,7 +77,7 @@ func TestValidateBindingsValid(t *testing.T) {
bindings: []v1beta1.WorkspaceBinding{},
}} {
t.Run(tc.name, func(t *testing.T) {
if err := ValidateBindings(tc.declarations, tc.bindings); err != nil {
if err := ValidateBindings(context.Background(), tc.declarations, tc.bindings); err != nil {
t.Errorf("didnt expect error for valid bindings but got: %v", err)
}
})
Expand Down Expand Up @@ -143,7 +144,7 @@ func TestValidateBindingsInvalid(t *testing.T) {
}},
}} {
t.Run(tc.name, func(t *testing.T) {
if err := ValidateBindings(tc.declarations, tc.bindings); err == nil {
if err := ValidateBindings(context.Background(), tc.declarations, tc.bindings); err == nil {
t.Errorf("expected error for invalid bindings but didn't get any!")
}
})
Expand Down