...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/podiochaos_types.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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  
    20  // PodIOChaosSpec defines the desired state of IOChaos
    21  type PodIOChaosSpec struct {
    22  	// VolumeMountPath represents the target mount path
    23  	// It must be a root of mount path now.
    24  	// TODO: search the mount parent of any path automatically.
    25  	// TODO: support multiple different volume mount path in one pod
    26  	VolumeMountPath string `json:"volumeMountPath"`
    27  
    28  	// TODO: support multiple different container to inject in one pod
    29  	// +optional
    30  	Container *string `json:"container,omitempty"`
    31  
    32  	// Actions are a list of IOChaos actions
    33  	// +optional
    34  	Actions []IOChaosAction `json:"actions,omitempty"`
    35  }
    36  
    37  // IOChaosAction defines a possible action of IOChaos
    38  type IOChaosAction struct {
    39  	Type IOChaosType `json:"type"`
    40  
    41  	Filter `json:",inline"`
    42  
    43  	// Faults represents the fault to inject
    44  	// +optional
    45  	Faults []IoFault `json:"faults,omitempty"`
    46  
    47  	// Latency represents the latency to inject
    48  	// +optional
    49  	Latency string `json:"latency,omitempty"`
    50  
    51  	// AttrOverride represents the attribution to override
    52  	// +optional
    53  	*AttrOverrideSpec `json:",inline"`
    54  
    55  	// MistakeSpec represents the mistake to inject
    56  	// +optional
    57  	*MistakeSpec `json:"mistake,omitempty"`
    58  
    59  	// Source represents the source of current rules
    60  	Source string `json:"source,omitempty"`
    61  }
    62  
    63  // IOChaosType represents the type of IOChaos Action
    64  type IOChaosType string
    65  
    66  const (
    67  	// IoLatency represents injecting latency for io operation
    68  	IoLatency IOChaosType = "latency"
    69  
    70  	// IoFaults represents injecting faults for io operation
    71  	IoFaults IOChaosType = "fault"
    72  
    73  	// IoAttrOverride represents replacing attribution for io operation
    74  	IoAttrOverride IOChaosType = "attrOverride"
    75  
    76  	// IoMistake represents injecting incorrect read or write for io operation
    77  	IoMistake IOChaosType = "mistake"
    78  )
    79  
    80  // Filter represents a filter of IOChaos action, which will define the
    81  // scope of an IOChaosAction
    82  type Filter struct {
    83  	// Path represents a glob of injecting path
    84  	Path string `json:"path"`
    85  
    86  	// Methods represents the method that the action will inject in
    87  	// +optional
    88  	Methods []IoMethod `json:"methods,omitempty"`
    89  
    90  	// Percent represents the percent probability of injecting this action
    91  	Percent int `json:"percent"`
    92  }
    93  
    94  // IoFault represents the fault to inject and their weight
    95  type IoFault struct {
    96  	Errno  uint32 `json:"errno"`
    97  	Weight int32  `json:"weight"`
    98  }
    99  
   100  // AttrOverrideSpec represents an override of attribution
   101  type AttrOverrideSpec struct {
   102  	//+optional
   103  	Ino *uint64 `json:"ino,omitempty"`
   104  	//+optional
   105  	Size *uint64 `json:"size,omitempty"`
   106  	//+optional
   107  	Blocks *uint64 `json:"blocks,omitempty"`
   108  	//+optional
   109  	Atime *Timespec `json:"atime,omitempty"`
   110  	//+optional
   111  	Mtime *Timespec `json:"mtime,omitempty"`
   112  	//+optional
   113  	Ctime *Timespec `json:"ctime,omitempty"`
   114  	//+optional
   115  	Kind *FileType `json:"kind,omitempty"`
   116  	//+optional
   117  	Perm *uint16 `json:"perm,omitempty"`
   118  	//+optional
   119  	Nlink *uint32 `json:"nlink,omitempty"`
   120  	//+optional
   121  	UID *uint32 `json:"uid,omitempty"`
   122  	//+optional
   123  	GID *uint32 `json:"gid,omitempty"`
   124  	//+optional
   125  	Rdev *uint32 `json:"rdev,omitempty"`
   126  }
   127  
   128  // MistakeSpec represents one type of mistake
   129  type MistakeSpec struct {
   130  	// Filling determines what is filled in the mistake data.
   131  	// +optional
   132  	// +kubebuilder:validation:Enum=zero;random
   133  	Filling FillingType `json:"filling,omitempty"`
   134  
   135  	// There will be [1, MaxOccurrences] segments of wrong data.
   136  	// +optional
   137  	// +kubebuilder:validation:Minimum=1
   138  	MaxOccurrences int64 `json:"maxOccurrences,omitempty"`
   139  
   140  	// Max length of each wrong data segment in bytes
   141  	// +optional
   142  	// +kubebuilder:validation:Minimum=1
   143  	MaxLength int64 `json:"maxLength,omitempty"`
   144  }
   145  
   146  // FillingType represents type of data is filled for incorrectness
   147  type FillingType string
   148  
   149  const (
   150  	// All zero
   151  	Zero FillingType = "zero"
   152  
   153  	// Random octets
   154  	Random FillingType = "random"
   155  )
   156  
   157  // Timespec represents a time
   158  type Timespec struct {
   159  	Sec  int64 `json:"sec"`
   160  	Nsec int64 `json:"nsec"`
   161  }
   162  
   163  // FileType represents type of file
   164  type FileType string
   165  
   166  const (
   167  	NamedPipe   FileType = "namedPipe"
   168  	CharDevice  FileType = "charDevice"
   169  	BlockDevice FileType = "blockDevice"
   170  	Directory   FileType = "directory"
   171  	RegularFile FileType = "regularFile"
   172  	TSymlink    FileType = "symlink"
   173  	Socket      FileType = "socket"
   174  )
   175  
   176  type IoMethod string
   177  
   178  const (
   179  	LookUp      IoMethod = "lookup"
   180  	Forget      IoMethod = "forget"
   181  	GetAttr     IoMethod = "getattr"
   182  	SetAttr     IoMethod = "setattr"
   183  	ReadLink    IoMethod = "readlink"
   184  	Mknod       IoMethod = "mknod"
   185  	Mkdir       IoMethod = "mkdir"
   186  	UnLink      IoMethod = "unlink"
   187  	Rmdir       IoMethod = "rmdir"
   188  	MSymlink    IoMethod = "symlink"
   189  	Rename      IoMethod = "rename"
   190  	Link        IoMethod = "link"
   191  	Open        IoMethod = "open"
   192  	Read        IoMethod = "read"
   193  	Write       IoMethod = "write"
   194  	Flush       IoMethod = "flush"
   195  	Release     IoMethod = "release"
   196  	Fsync       IoMethod = "fsync"
   197  	Opendir     IoMethod = "opendir"
   198  	Readdir     IoMethod = "readdir"
   199  	Releasedir  IoMethod = "releasedir"
   200  	Fsyncdir    IoMethod = "fsyncdir"
   201  	Statfs      IoMethod = "statfs"
   202  	SetXAttr    IoMethod = "setxattr"
   203  	GetXAttr    IoMethod = "getxattr"
   204  	ListXAttr   IoMethod = "listxattr"
   205  	RemoveXAttr IoMethod = "removexattr"
   206  	Access      IoMethod = "access"
   207  	Create      IoMethod = "create"
   208  	GetLk       IoMethod = "getlk"
   209  	SetLk       IoMethod = "setlk"
   210  	Bmap        IoMethod = "bmap"
   211  )
   212  
   213  // +chaos-mesh:base
   214  // +chaos-mesh:webhook:enableUpdate
   215  // +kubebuilder:object:root=true
   216  // +kubebuilder:subresource:status
   217  // PodIOChaos is the Schema for the podiochaos API
   218  type PodIOChaos struct {
   219  	metav1.TypeMeta   `json:",inline"`
   220  	metav1.ObjectMeta `json:"metadata,omitempty"`
   221  
   222  	Spec PodIOChaosSpec `json:"spec,omitempty"`
   223  
   224  	//+optional
   225  	Status PodIOChaosStatus `json:"status,omitempty"`
   226  }
   227  
   228  type PodIOChaosStatus struct {
   229  
   230  	// Pid represents a running toda process id
   231  	// +optional
   232  	Pid int64 `json:"pid,omitempty"`
   233  
   234  	// StartTime represents the start time of a toda process
   235  	// +optional
   236  	StartTime int64 `json:"startTime,omitempty"`
   237  
   238  	// +optional
   239  	FailedMessage string `json:"failedMessage,omitempty"`
   240  
   241  	// +optional
   242  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
   243  }
   244  
   245  // +kubebuilder:object:root=true
   246  
   247  // PodIOChaosList contains a list of PodIOChaos
   248  type PodIOChaosList struct {
   249  	metav1.TypeMeta `json:",inline"`
   250  	metav1.ListMeta `json:"metadata,omitempty"`
   251  	Items           []PodIOChaos `json:"items"`
   252  }
   253