...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/iochaos_webhook.go

Documentation: github.com/chaos-mesh/chaos-mesh/api/v1alpha1

     1  // Copyright 2021 Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    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  		// in cannot be nil
    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