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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 ) 21 22 // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 23 // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 24 25 // +kubebuilder:object:root=true 26 // +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action` 27 // +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration` 28 // +chaos-mesh:experiment 29 30 // IOChaos is the Schema for the iochaos API 31 type IOChaos struct { 32 metav1.TypeMeta `json:",inline"` 33 metav1.ObjectMeta `json:"metadata,omitempty"` 34 35 Spec IOChaosSpec `json:"spec,omitempty"` 36 Status IOChaosStatus `json:"status,omitempty"` 37 } 38 39 var _ InnerObjectWithCustomStatus = (*IOChaos)(nil) 40 var _ InnerObjectWithSelector = (*IOChaos)(nil) 41 var _ InnerObject = (*IOChaos)(nil) 42 43 // IOChaosSpec defines the desired state of IOChaos 44 type IOChaosSpec struct { 45 ContainerSelector `json:",inline"` 46 47 // Action defines the specific pod chaos action. 48 // Supported action: latency / fault / attrOverride / mistake 49 // +kubebuilder:validation:Enum=latency;fault;attrOverride;mistake 50 Action IOChaosType `json:"action"` 51 52 // Delay defines the value of I/O chaos action delay. 53 // A delay string is a possibly signed sequence of 54 // decimal numbers, each with optional fraction and a unit suffix, 55 // such as "300ms". 56 // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". 57 // +ui:form:when=action=='latency' 58 // +optional 59 Delay string `json:"delay,omitempty" webhook:"Duration"` 60 61 // Errno defines the error code that returned by I/O action. 62 // refer to: https://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html 63 // +ui:form:when=action=='fault' 64 // +optional 65 Errno uint32 `json:"errno,omitempty" webhook:"IOErrno"` 66 67 // Attr defines the overrided attribution 68 // +ui:form:when=action=='attrOverride' 69 // +optional 70 Attr *AttrOverrideSpec `json:"attr,omitempty"` 71 72 // Mistake defines what types of incorrectness are injected to IO operations 73 // +ui:form:when=action=='mistake' 74 // +optional 75 Mistake *MistakeSpec `json:"mistake,omitempty"` 76 77 // Path defines the path of files for injecting I/O chaos action. 78 // +optional 79 Path string `json:"path,omitempty"` 80 81 // Methods defines the I/O methods for injecting I/O chaos action. 82 // default: all I/O methods. 83 // +optional 84 Methods []IoMethod `json:"methods,omitempty" faker:"ioMethods"` 85 86 // Percent defines the percentage of injection errors and provides a number from 0-100. 87 // default: 100. 88 // +optional 89 // +kubebuilder:default=100 90 Percent int `json:"percent,omitempty" webhook:"Percent"` 91 92 // VolumePath represents the mount path of injected volume 93 VolumePath string `json:"volumePath"` 94 95 // Duration represents the duration of the chaos action. 96 // It is required when the action is `PodFailureAction`. 97 // A duration string is a possibly signed sequence of 98 // decimal numbers, each with optional fraction and a unit suffix, 99 // such as "300ms", "-1.5h" or "2h45m". 100 // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". 101 // +optional 102 Duration *string `json:"duration,omitempty" webhook:"Duration"` 103 104 // RemoteCluster represents the remote cluster where the chaos will be deployed 105 // +optional 106 RemoteCluster string `json:"remoteCluster,omitempty"` 107 } 108 109 // IOChaosStatus defines the observed state of IOChaos 110 type IOChaosStatus struct { 111 ChaosStatus `json:",inline"` 112 113 // Instances always specifies podiochaos generation or empty 114 // +optional 115 Instances map[string]int64 `json:"instances,omitempty"` 116 } 117 118 func (obj *IOChaos) GetSelectorSpecs() map[string]interface{} { 119 return map[string]interface{}{ 120 ".": &obj.Spec.ContainerSelector, 121 } 122 } 123 124 func (obj *IOChaos) GetCustomStatus() interface{} { 125 return &obj.Status.Instances 126 } 127