diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index ef8eee4f9a0..90f7beb56e6 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -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) diff --git a/pkg/workspace/validate.go b/pkg/workspace/validate.go index 570934aad25..ab9ee42db3f 100644 --- a/pkg/workspace/validate.go +++ b/pkg/workspace/validate.go @@ -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) } } diff --git a/pkg/workspace/validate_test.go b/pkg/workspace/validate_test.go index cd4894d0b8a..0859e6950ae 100644 --- a/pkg/workspace/validate_test.go +++ b/pkg/workspace/validate_test.go @@ -17,6 +17,7 @@ limitations under the License. package workspace import ( + "context" "errors" "testing" @@ -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) } }) @@ -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!") } })