...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/dnschaos_type.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  // DNSChaosAction represents the chaos action about DNS.
    26  type DNSChaosAction string
    27  
    28  const (
    29  	// ErrorAction represents get error when send DNS request.
    30  	ErrorAction DNSChaosAction = "error"
    31  
    32  	// RandomAction represents get random IP when send DNS request.
    33  	RandomAction DNSChaosAction = "random"
    34  )
    35  
    36  // EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
    37  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    38  
    39  // +kubebuilder:object:root=true
    40  // +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
    41  // +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
    42  // +chaos-mesh:experiment
    43  
    44  // DNSChaos is the Schema for the networkchaos API
    45  type DNSChaos struct {
    46  	metav1.TypeMeta   `json:",inline"`
    47  	metav1.ObjectMeta `json:"metadata,omitempty"`
    48  
    49  	// Spec defines the behavior of a pod chaos experiment
    50  	Spec DNSChaosSpec `json:"spec"`
    51  
    52  	// +optional
    53  	// Most recently observed status of the chaos experiment about pods
    54  	Status DNSChaosStatus `json:"status,omitempty"`
    55  }
    56  
    57  var _ InnerObjectWithSelector = (*DNSChaos)(nil)
    58  var _ InnerObject = (*DNSChaos)(nil)
    59  
    60  // DNSChaosSpec defines the desired state of DNSChaos
    61  type DNSChaosSpec struct {
    62  	// Action defines the specific DNS chaos action.
    63  	// Supported action: error, random
    64  	// Default action: error
    65  	// +kubebuilder:validation:Enum=error;random
    66  	Action DNSChaosAction `json:"action"`
    67  
    68  	ContainerSelector `json:",inline"`
    69  
    70  	// Duration represents the duration of the chaos action
    71  	Duration *string `json:"duration,omitempty" webhook:"Duration"`
    72  
    73  	// Choose which domain names to take effect, support the placeholder ? and wildcard *, or the Specified domain name.
    74  	// Note:
    75  	//      1. The wildcard * must be at the end of the string. For example, chaos-*.org is invalid.
    76  	//      2. if the patterns is empty, will take effect on all the domain names.
    77  	// For example:
    78  	// 		The value is ["google.com", "github.*", "chaos-mes?.org"],
    79  	// 		will take effect on "google.com", "github.com" and "chaos-mesh.org"
    80  	// +optional
    81  	DomainNamePatterns []string `json:"patterns,omitempty"`
    82  
    83  	// RemoteCluster represents the remote cluster where the chaos will be deployed
    84  	// +optional
    85  	RemoteCluster string `json:"remoteCluster,omitempty"`
    86  }
    87  
    88  // DNSChaosStatus defines the observed state of DNSChaos
    89  type DNSChaosStatus struct {
    90  	ChaosStatus `json:",inline"`
    91  }
    92  
    93  func (obj *DNSChaos) GetSelectorSpecs() map[string]interface{} {
    94  	return map[string]interface{}{
    95  		".": &obj.Spec.ContainerSelector,
    96  	}
    97  }
    98