...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/workflownode_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  	corev1 "k8s.io/api/core/v1"
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  	"k8s.io/apimachinery/pkg/runtime"
    22  )
    23  
    24  const (
    25  	LabelControlledBy       = "chaos-mesh.org/controlled-by"
    26  	LabelWorkflow           = "chaos-mesh.org/workflow"
    27  	WorkflowAnnotationAbort = "workflow.chaos-mesh.org/abort"
    28  )
    29  
    30  const KindWorkflowNode = "WorkflowNode"
    31  
    32  // +kubebuilder:object:root=true
    33  // +kubebuilder:resource:shortName=wfn
    34  // +kubebuilder:subresource:status
    35  type WorkflowNode struct {
    36  	metav1.TypeMeta   `json:",inline"`
    37  	metav1.ObjectMeta `json:"metadata,omitempty"`
    38  
    39  	// Spec defines the behavior of a node of workflow
    40  	Spec WorkflowNodeSpec `json:"spec"`
    41  
    42  	// +optional
    43  	// Most recently observed status of the workflow node
    44  	Status WorkflowNodeStatus `json:"status,omitempty"`
    45  }
    46  
    47  type WorkflowNodeSpec struct {
    48  	TemplateName string       `json:"templateName"`
    49  	WorkflowName string       `json:"workflowName"`
    50  	Type         TemplateType `json:"type"`
    51  	StartTime    *metav1.Time `json:"startTime"`
    52  	// +optional
    53  	Deadline *metav1.Time `json:"deadline,omitempty"`
    54  	// +optional
    55  	Task *Task `json:"task,omitempty"`
    56  	// +optional
    57  	Children []string `json:"children,omitempty"`
    58  	// +optional
    59  	ConditionalBranches []ConditionalBranch `json:"conditionalBranches,omitempty"`
    60  	// +optional
    61  	*EmbedChaos `json:",inline,omitempty"`
    62  	// +optional
    63  	Schedule *ScheduleSpec `json:"schedule,omitempty"`
    64  	// StatusCheck describe the behavior of StatusCheck. Only used when Type is TypeStatusCheck.
    65  	// +optional
    66  	StatusCheck *StatusCheckSpec `json:"statusCheck,omitempty"`
    67  	// AbortWithStatusCheck describe whether to abort the workflow when the failure threshold of StatusCheck is exceeded.
    68  	// Only used when Type is TypeStatusCheck.
    69  	// +optional
    70  	AbortWithStatusCheck bool `json:"abortWithStatusCheck,omitempty"`
    71  }
    72  
    73  type WorkflowNodeStatus struct {
    74  
    75  	// ChaosResource refs to the real chaos CR object.
    76  	// +optional
    77  	ChaosResource *corev1.TypedLocalObjectReference `json:"chaosResource,omitempty"`
    78  
    79  	// ConditionalBranchesStatus records the evaluation result of each ConditionalBranch
    80  	// +optional
    81  	ConditionalBranchesStatus *ConditionalBranchesStatus `json:"conditionalBranchesStatus,omitempty"`
    82  
    83  	// ActiveChildren means the created children node
    84  	// +optional
    85  	ActiveChildren []corev1.LocalObjectReference `json:"activeChildren,omitempty"`
    86  
    87  	// Children is necessary for representing the order when replicated child template references by parent template.
    88  	// +optional
    89  	FinishedChildren []corev1.LocalObjectReference `json:"finishedChildren,omitempty"`
    90  
    91  	// Represents the latest available observations of a workflow node's current state.
    92  	// +optional
    93  	// +patchMergeKey=type
    94  	// +patchStrategy=merge
    95  	Conditions []WorkflowNodeCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
    96  }
    97  
    98  type ConditionalBranch struct {
    99  	// Target is the name of other template, if expression is evaluated as true, this template will be spawned.
   100  	Target string `json:"target"`
   101  	// Expression is the expression for this conditional branch, expected type of result is boolean. If expression is empty, this branch will always be selected/the template will be spawned.
   102  	// +optional
   103  	Expression string `json:"expression,omitempty"`
   104  }
   105  
   106  type ConditionalBranchesStatus struct {
   107  	// +optional
   108  	Branches []ConditionalBranchStatus `json:"branches"`
   109  	// +optional
   110  	Context []string `json:"context"`
   111  }
   112  
   113  type ConditionalBranchStatus struct {
   114  	Target           string                 `json:"target"`
   115  	EvaluationResult corev1.ConditionStatus `json:"evaluationResult"`
   116  }
   117  
   118  type WorkflowNodeConditionType string
   119  
   120  const (
   121  	ConditionAccomplished   WorkflowNodeConditionType = "Accomplished"
   122  	ConditionDeadlineExceed WorkflowNodeConditionType = "DeadlineExceed"
   123  	ConditionChaosInjected  WorkflowNodeConditionType = "ChaosInjected"
   124  	ConditionAborted        WorkflowNodeConditionType = "Aborted"
   125  )
   126  
   127  type WorkflowNodeCondition struct {
   128  	Type   WorkflowNodeConditionType `json:"type"`
   129  	Status corev1.ConditionStatus    `json:"status"`
   130  	Reason string                    `json:"reason"`
   131  }
   132  
   133  // +kubebuilder:object:root=true
   134  type WorkflowNodeList struct {
   135  	metav1.TypeMeta `json:",inline"`
   136  	metav1.ListMeta `json:"metadata,omitempty"`
   137  	Items           []WorkflowNode `json:"items"`
   138  }
   139  
   140  func init() {
   141  	SchemeBuilder.Register(&WorkflowNode{}, &WorkflowNodeList{})
   142  }
   143  
   144  // Reasons
   145  const (
   146  	EntryCreated                         string = "EntryCreated"
   147  	InvalidEntry                         string = "InvalidEntry"
   148  	WorkflowAccomplished                 string = "WorkflowAccomplished"
   149  	NodeAccomplished                     string = "NodeAccomplished"
   150  	NodesCreated                         string = "NodesCreated"
   151  	NodeDeadlineExceed                   string = "NodeDeadlineExceed"
   152  	NodeDeadlineNotExceed                string = "NodeDeadlineNotExceed"
   153  	NodeDeadlineOmitted                  string = "NodeDeadlineOmitted"
   154  	ParentNodeDeadlineExceed             string = "ParentNodeDeadlineExceed"
   155  	ChaosCRCreated                       string = "ChaosCRCreated"
   156  	ChaosCRCreateFailed                  string = "ChaosCRCreateFailed"
   157  	ChaosCRDeleted                       string = "ChaosCRDeleted"
   158  	ChaosCRDeleteFailed                  string = "ChaosCRDeleteFailed"
   159  	ChaosCRNotExists                     string = "ChaosCRNotExists"
   160  	TaskPodSpawned                       string = "TaskPodSpawned"
   161  	TaskPodSpawnFailed                   string = "TaskPodSpawnFailed"
   162  	TaskPodPodCompleted                  string = "TaskPodPodCompleted"
   163  	ConditionalBranchesSelected          string = "ConditionalBranchesSelected"
   164  	RerunBySpecChanged                   string = "RerunBySpecChanged"
   165  	StatusCheckCreated                   string = "StatusCheckCreated"
   166  	StatusCheckCreatedFailed             string = "StatusCheckCreatedFailed"
   167  	StatusCheckDeleted                   string = "StatusCheckDeleted"
   168  	StatusCheckDeletedFailed             string = "StatusCheckDeletedFailed"
   169  	StatusCheckCompleted                 string = "StatusCheckCompleted"
   170  	StatusCheckNotExceedSuccessThreshold string = "StatusCheckNotExceedSuccessThreshold"
   171  	ParentNodeAborted                    string = "ParentNodeAborted"
   172  	WorkflowAborted                      string = "WorkflowAborted"
   173  )
   174  
   175  // GenericChaosList only use to list GenericChaos by certain EmbedChaos
   176  // +kubebuilder:object:generate=false
   177  type GenericChaosList interface {
   178  	runtime.Object
   179  	metav1.ListInterface
   180  	GetItems() []GenericChaos
   181  	DeepCopyList() GenericChaosList
   182  }
   183  
   184  // GenericChaos could be a place holder for any kubernetes Kind
   185  // +kubebuilder:object:generate=false
   186  type GenericChaos interface {
   187  	runtime.Object
   188  	metav1.Object
   189  }
   190