...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/blockchaos_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  // +kubebuilder:object:root=true
    21  // +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
    22  // +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
    23  // +chaos-mesh:experiment
    24  
    25  // BlockChaos is the Schema for the blockchaos API
    26  type BlockChaos struct {
    27  	metav1.TypeMeta   `json:",inline"`
    28  	metav1.ObjectMeta `json:"metadata,omitempty"`
    29  
    30  	Spec   BlockChaosSpec   `json:"spec"`
    31  	Status BlockChaosStatus `json:"status,omitempty"`
    32  }
    33  
    34  type BlockChaosAction string
    35  
    36  const (
    37  	BlockDelay BlockChaosAction = "delay"
    38  )
    39  
    40  // BlockChaosSpec is the content of the specification for a BlockChaos
    41  type BlockChaosSpec struct {
    42  	// Action defines the specific block chaos action.
    43  	// Supported action: delay
    44  	// +kubebuilder:validation:Enum=delay
    45  	Action BlockChaosAction `json:"action"`
    46  
    47  	// Delay defines the delay distribution.
    48  	// +optional
    49  	Delay *BlockDelaySpec `json:"delay,omitempty"`
    50  
    51  	ContainerNodeVolumePathSelector `json:",inline"`
    52  
    53  	// Duration represents the duration of the chaos action.
    54  	// +optional
    55  	Duration *string `json:"duration,omitempty" webhook:"Duration"`
    56  
    57  	// RemoteCluster represents the remote cluster where the chaos will be deployed
    58  	// +optional
    59  	RemoteCluster string `json:"remoteCluster,omitempty"`
    60  }
    61  
    62  // BlockDelaySpec describes the block delay specification
    63  type BlockDelaySpec struct {
    64  	// Latency defines the latency of every io request.
    65  	Latency string `json:"latency,omitempty" webhook:"Duration"`
    66  
    67  	// +optional
    68  	Correlation string `json:"correlation,omitempty" default:"0" webhook:"FloatStr"`
    69  
    70  	// +optional
    71  	Jitter string `json:"jitter,omitempty" default:"0ms" webhook:"Duration"`
    72  }
    73  
    74  // ContainerNodeVolumePathSelector is the selector to select a node and a PV on it
    75  type ContainerNodeVolumePathSelector struct {
    76  	ContainerSelector `json:",inline"`
    77  
    78  	VolumeName string `json:"volumeName"`
    79  }
    80  
    81  // BlockChaosStatus represents the status of a BlockChaos
    82  type BlockChaosStatus struct {
    83  	ChaosStatus `json:",inline"`
    84  
    85  	// InjectionIds always specifies the number of injected chaos action
    86  	// +optional
    87  	InjectionIds map[string]int `json:"ids,omitempty"`
    88  }
    89  
    90  func (obj *BlockChaos) GetSelectorSpecs() map[string]interface{} {
    91  	return map[string]interface{}{
    92  		".": &obj.Spec.ContainerNodeVolumePathSelector,
    93  	}
    94  }
    95  
    96  func (obj *BlockChaos) GetCustomStatus() interface{} {
    97  	return &obj.Status.InjectionIds
    98  }
    99