...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/podnetworkchaos_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 (
    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:subresource:status
    27  // +chaos-mesh:base
    28  // +chaos-mesh:webhook:enableUpdate
    29  
    30  // PodNetworkChaos is the Schema for the PodNetworkChaos API
    31  type PodNetworkChaos struct {
    32  	metav1.TypeMeta   `json:",inline"`
    33  	metav1.ObjectMeta `json:"metadata,omitempty"`
    34  
    35  	// Spec defines the behavior of a pod chaos experiment
    36  	Spec PodNetworkChaosSpec `json:"spec"`
    37  
    38  	// +optional
    39  	// Most recently observed status of the chaos experiment about pods
    40  	Status PodNetworkChaosStatus `json:"status,omitempty"`
    41  }
    42  
    43  // PodNetworkChaosSpec defines the desired state of PodNetworkChaos
    44  type PodNetworkChaosSpec struct {
    45  	// The ipset on the pod
    46  	// +optional
    47  	IPSets []RawIPSet `json:"ipsets,omitempty"`
    48  
    49  	// The iptables rules on the pod
    50  	// +optional
    51  	Iptables []RawIptables `json:"iptables,omitempty"`
    52  
    53  	// The tc rules on the pod
    54  	// +optional
    55  	TrafficControls []RawTrafficControl `json:"tcs,omitempty"`
    56  }
    57  
    58  // IPSetType represents the type of IP set
    59  type IPSetType string
    60  
    61  const (
    62  	SetIPSet     IPSetType = "list:set"
    63  	NetPortIPSet IPSetType = "hash:net,port"
    64  	NetIPSet     IPSetType = "hash:net"
    65  )
    66  
    67  // RawIPSet represents an ipset on specific pod
    68  type RawIPSet struct {
    69  	// The name of ipset
    70  	Name string `json:"name"`
    71  
    72  	IPSetType IPSetType `json:"ipsetType"`
    73  
    74  	// The contents of ipset.
    75  	// Only available when IPSetType is NetIPSet.
    76  	// +optional
    77  	Cidrs []string `json:"cidrs,omitempty"`
    78  
    79  	// The contents of ipset.
    80  	// Only available when IPSetType is NetPortIPSet.
    81  	// +optional
    82  	CidrAndPorts []CidrAndPort `json:"cidrAndPorts,omitempty"`
    83  
    84  	// The contents of ipset.
    85  	// Only available when IPSetType is SetIPSet.
    86  	// +optional
    87  	SetNames []string `json:"setNames,omitempty"`
    88  
    89  	// The name and namespace of the source network chaos
    90  	RawRuleSource `json:",inline"`
    91  }
    92  
    93  // CidrAndPort represents CIDR and port pair
    94  type CidrAndPort struct {
    95  	Cidr string `json:"cidr"`
    96  
    97  	// +kubebuilder:validation:Minimum=1
    98  	// +kubebuilder:validation:Maximum=65535
    99  	Port uint16 `json:"port"`
   100  }
   101  
   102  // ChainDirection represents the direction of chain
   103  type ChainDirection string
   104  
   105  const (
   106  	// Input means this chain is linked with INPUT chain
   107  	Input ChainDirection = "input"
   108  
   109  	// Output means this chain is linked with OUTPUT chain
   110  	Output ChainDirection = "output"
   111  )
   112  
   113  // RawIptables represents the iptables rules on specific pod
   114  type RawIptables struct {
   115  	// The name of iptables chain
   116  	Name string `json:"name"`
   117  
   118  	// The name of related ipset
   119  	// +optional
   120  	// +nullable
   121  	IPSets []string `json:"ipsets,omitempty"`
   122  
   123  	// The block direction of this iptables rule
   124  	Direction ChainDirection `json:"direction"`
   125  
   126  	// Device represents the network device to be affected.
   127  	// +optional
   128  	Device string `json:"device,omitempty"`
   129  
   130  	RawRuleSource `json:",inline"`
   131  }
   132  
   133  // TcType the type of traffic control
   134  type TcType string
   135  
   136  const (
   137  	// Netem represents netem traffic control
   138  	Netem TcType = "netem"
   139  
   140  	// Bandwidth represents bandwidth shape traffic control
   141  	Bandwidth TcType = "bandwidth"
   142  )
   143  
   144  // RawTrafficControl represents the traffic control chaos on specific pod
   145  type RawTrafficControl struct {
   146  	// The type of traffic control
   147  	Type TcType `json:"type"`
   148  
   149  	TcParameter `json:",inline"`
   150  
   151  	// The name of target ipset
   152  	// +optional
   153  	IPSet string `json:"ipset,omitempty"`
   154  
   155  	// The name and namespace of the source network chaos
   156  	Source string `json:"source"`
   157  
   158  	// Device represents the network device to be affected.
   159  	// +optional
   160  	Device string `json:"device,omitempty"`
   161  }
   162  
   163  // TcParameter represents the parameters for a traffic control chaos
   164  type TcParameter struct {
   165  	// Delay represents the detail about delay action
   166  	// +ui:form:when=action=='delay'
   167  	// +optional
   168  	Delay *DelaySpec `json:"delay,omitempty"`
   169  
   170  	// Loss represents the detail about loss action
   171  	// +ui:form:when=action=='loss'
   172  	// +optional
   173  	Loss *LossSpec `json:"loss,omitempty"`
   174  
   175  	// DuplicateSpec represents the detail about loss action
   176  	// +ui:form:when=action=='duplicate'
   177  	// +optional
   178  	Duplicate *DuplicateSpec `json:"duplicate,omitempty"`
   179  
   180  	// Corrupt represents the detail about corrupt action
   181  	// +ui:form:when=action=='corrupt'
   182  	// +optional
   183  	Corrupt *CorruptSpec `json:"corrupt,omitempty"`
   184  
   185  	// Bandwidth represents the detail about bandwidth control action
   186  	// +ui:form:when=action=='bandwidth'
   187  	// +optional
   188  	Bandwidth *BandwidthSpec `json:"bandwidth,omitempty"`
   189  
   190  	// Rate represents the detail about rate control action
   191  	// +ui:form:when=action=='rate'
   192  	// +optional
   193  	Rate *RateSpec `json:"rate,omitempty"`
   194  }
   195  
   196  // RawRuleSource represents the name and namespace of the source network chaos
   197  type RawRuleSource struct {
   198  	Source string `json:"source"`
   199  }
   200  
   201  // PodNetworkChaosStatus defines the observed state of PodNetworkChaos
   202  type PodNetworkChaosStatus struct {
   203  	FailedMessage string `json:"failedMessage,omitempty"`
   204  
   205  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
   206  }
   207  
   208  // +kubebuilder:object:root=true
   209  
   210  // PodNetworkChaosList contains a list of PodNetworkChaos
   211  type PodNetworkChaosList struct {
   212  	metav1.TypeMeta `json:",inline"`
   213  	metav1.ListMeta `json:"metadata,omitempty"`
   214  	Items           []PodNetworkChaos `json:"items"`
   215  }
   216