@@ -25,8 +25,10 @@ package v1beta1
2525import (
2626 "fmt"
2727
28- " errors"
28+ apierrors "k8s.io/apimachinery/pkg/api/ errors"
2929 "k8s.io/apimachinery/pkg/runtime"
30+ "k8s.io/apimachinery/pkg/runtime/schema"
31+ "k8s.io/apimachinery/pkg/util/validation/field"
3032 ctrl "sigs.k8s.io/controller-runtime"
3133 logf "sigs.k8s.io/controller-runtime/pkg/log"
3234 "sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -62,16 +64,29 @@ var _ webhook.Validator = &Tobiko{}
6264func (r * Tobiko ) ValidateCreate () (admission.Warnings , error ) {
6365 tobikolog .Info ("validate create" , "name" , r .Name )
6466
67+ var allErrs field.ErrorList
6568 var allWarnings admission.Warnings
6669
70+ if len (r .Spec .Workflow ) > 0 && r .Spec .Debug {
71+ allErrs = append (allErrs , & field.Error {
72+ Type : field .ErrorTypeForbidden ,
73+ BadValue : r .Spec .Workflow ,
74+ Detail : fmt .Sprintf (ErrDebug , "Tobiko" ),
75+ })
76+ }
77+
6778 if r .Spec .Privileged {
6879 allWarnings = append (allWarnings , fmt .Sprintf (WarnPrivilegedModeOn , "Tobiko" ))
6980 } else {
7081 allWarnings = append (allWarnings , fmt .Sprintf (WarnPrivilegedModeOff , "Tobiko" ))
7182 }
7283
73- if len (r .Spec .Workflow ) > 0 && r .Spec .Debug {
74- return allWarnings , errors .New ("workflow variable must be empty to run debug mode" )
84+ if len (allErrs ) > 0 {
85+ return allWarnings , apierrors .NewInvalid (
86+ schema.GroupKind {
87+ Group : GroupVersion .WithKind ("Tobiko" ).Group ,
88+ Kind : GroupVersion .WithKind ("Tobiko" ).Kind ,
89+ }, r .GetName (), allErrs )
7590 }
7691
7792 return allWarnings , nil
0 commit comments