...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "fmt"
20 "reflect"
21
22 "k8s.io/apimachinery/pkg/util/validation/field"
23
24 "github.com/chaos-mesh/chaos-mesh/api/genericwebhook"
25 )
26
27 type IOErrno uint32
28
29 func (in *IOErrno) Validate(root interface{}, path *field.Path) field.ErrorList {
30 allErrs := field.ErrorList{}
31 obj := root.(*IOChaos)
32 if obj.Spec.Action == IoFaults {
33
34 if *in == 0 {
35 allErrs = append(allErrs, field.Invalid(path, in,
36 fmt.Sprintf("action %s: errno 0 is not supported", obj.Spec.Action)))
37 }
38 }
39 return allErrs
40 }
41
42 func init() {
43 genericwebhook.Register("IOErrno", reflect.PtrTo(reflect.TypeOf(IOErrno(0))))
44 }
45