diff --git a/pkg/apis/pipeline/v1alpha1/run_validation.go b/pkg/apis/pipeline/v1alpha1/run_validation.go index 8ad179c85b4..2a617e4a554 100644 --- a/pkg/apis/pipeline/v1alpha1/run_validation.go +++ b/pkg/apis/pipeline/v1alpha1/run_validation.go @@ -44,6 +44,9 @@ func (rs *RunSpec) Validate(ctx context.Context) *apis.FieldError { if rs.Ref != nil && rs.Spec != nil { return apis.ErrMultipleOneOf("spec.ref", "spec.spec") } + if rs.Ref == nil && rs.Spec == nil { + return apis.ErrMissingOneOf("spec.ref", "spec.spec") + } if rs.Ref != nil { if rs.Ref.APIVersion == "" { return apis.ErrMissingField("spec.ref.apiVersion") diff --git a/pkg/apis/pipeline/v1alpha1/run_validation_test.go b/pkg/apis/pipeline/v1alpha1/run_validation_test.go index 15c79d1505b..b174004d637 100644 --- a/pkg/apis/pipeline/v1alpha1/run_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/run_validation_test.go @@ -45,16 +45,26 @@ func TestRun_Invalid(t *testing.T) { want: apis.ErrMissingField("spec"), }, { name: "Empty spec", + run: &v1alpha1.Run{ + ObjectMeta: metav1.ObjectMeta{ + Name: "temp", + }, + Spec: v1alpha1.RunSpec{}, + }, + want: apis.ErrMissingField("spec"), + }, { + name: "Both spec and ref missing", run: &v1alpha1.Run{ ObjectMeta: metav1.ObjectMeta{ Name: "temp", }, Spec: v1alpha1.RunSpec{ - Ref: nil, - Spec: nil, + Ref: nil, + Spec: nil, + ServiceAccountName: "test-sa", }, }, - want: apis.ErrMissingField("spec"), + want: apis.ErrMissingOneOf("spec.ref", "spec.spec"), }, { name: "Both Ref and Spec", run: &v1alpha1.Run{