...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/httpchaos_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  // +kubebuilder:object:root=true
    23  // +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
    24  // +chaos-mesh:experiment
    25  
    26  // HTTPChaos is the Schema for the HTTPchaos API
    27  type HTTPChaos struct {
    28  	metav1.TypeMeta   `json:",inline"`
    29  	metav1.ObjectMeta `json:"metadata,omitempty"`
    30  
    31  	Spec   HTTPChaosSpec   `json:"spec,omitempty"`
    32  	Status HTTPChaosStatus `json:"status,omitempty"`
    33  }
    34  
    35  var _ InnerObjectWithCustomStatus = (*HTTPChaos)(nil)
    36  var _ InnerObjectWithSelector = (*HTTPChaos)(nil)
    37  var _ InnerObject = (*HTTPChaos)(nil)
    38  
    39  type HTTPChaosSpec struct {
    40  	PodSelector `json:",inline"`
    41  
    42  	// Target is the object to be selected and injected.
    43  	// +kubebuilder:validation:Enum=Request;Response
    44  	Target PodHttpChaosTarget `json:"target"`
    45  
    46  	PodHttpChaosActions `json:",inline"`
    47  
    48  	// Port represents the target port to be proxy of.
    49  	Port int32 `json:"port,omitempty" webhook:"Port"`
    50  
    51  	// Path is a rule to select target by uri path in http request.
    52  	// +optional
    53  	Path *string `json:"path,omitempty"`
    54  
    55  	// Method is a rule to select target by http method in request.
    56  	// +optional
    57  	Method *string `json:"method,omitempty" webhook:"HTTPMethod"`
    58  
    59  	// Code is a rule to select target by http status code in response.
    60  	// +optional
    61  	Code *int32 `json:"code,omitempty"`
    62  
    63  	// RequestHeaders is a rule to select target by http headers in request.
    64  	// The key-value pairs represent header name and header value pairs.
    65  	// +optional
    66  	RequestHeaders map[string]string `json:"request_headers,omitempty"`
    67  
    68  	// ResponseHeaders is a rule to select target by http headers in response.
    69  	// The key-value pairs represent header name and header value pairs.
    70  	// +optional
    71  	ResponseHeaders map[string]string `json:"response_headers,omitempty"`
    72  
    73  	// TLS is the tls config,
    74  	// will override PodHttpChaos if there are multiple HTTPChaos experiments are applied
    75  	// +optional
    76  	TLS *PodHttpChaosTLS `json:"tls,omitempty"`
    77  
    78  	// Duration represents the duration of the chaos action.
    79  	// +optional
    80  	Duration *string `json:"duration,omitempty" webhook:"Duration"`
    81  
    82  	// RemoteCluster represents the remote cluster where the chaos will be deployed
    83  	// +optional
    84  	RemoteCluster string `json:"remoteCluster,omitempty"`
    85  }
    86  
    87  type HTTPChaosStatus struct {
    88  	ChaosStatus `json:",inline"`
    89  
    90  	// Instances always specifies podhttpchaos generation or empty
    91  	// +optional
    92  	Instances map[string]int64 `json:"instances,omitempty"`
    93  }
    94  
    95  func (obj *HTTPChaos) GetSelectorSpecs() map[string]interface{} {
    96  	return map[string]interface{}{
    97  		".": &obj.Spec.PodSelector,
    98  	}
    99  }
   100  
   101  func (obj *HTTPChaos) GetCustomStatus() interface{} {
   102  	return &obj.Status.Instances
   103  }
   104