...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder/statuscheck.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder

     1  // Copyright 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 recorder
    17  
    18  import (
    19  	"fmt"
    20  
    21  	corev1 "k8s.io/api/core/v1"
    22  
    23  	"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
    24  )
    25  
    26  type StatusCheckCompleted struct {
    27  	Msg v1alpha1.StatusCheckReason
    28  }
    29  
    30  func (it StatusCheckCompleted) Type() string {
    31  	return corev1.EventTypeNormal
    32  }
    33  
    34  func (it StatusCheckCompleted) Reason() string {
    35  	return v1alpha1.StatusCheckCompleted
    36  }
    37  
    38  func (it StatusCheckCompleted) Message() string {
    39  	return fmt.Sprintf("status check completed: %s", string(it.Msg))
    40  }
    41  
    42  type StatusCheckExecutionFailed struct {
    43  	ExecutorType string
    44  	Msg          string
    45  }
    46  
    47  func (it StatusCheckExecutionFailed) Type() string {
    48  	return corev1.EventTypeWarning
    49  }
    50  
    51  func (it StatusCheckExecutionFailed) Reason() string {
    52  	return string(v1alpha1.StatusCheckExecutionFailed)
    53  }
    54  
    55  func (it StatusCheckExecutionFailed) Message() string {
    56  	return fmt.Sprintf("%s execution of status check failed: %s", it.ExecutorType, it.Msg)
    57  }
    58  
    59  type StatusCheckExecutionSucceed struct {
    60  	ExecutorType string
    61  }
    62  
    63  func (it StatusCheckExecutionSucceed) Type() string {
    64  	return corev1.EventTypeNormal
    65  }
    66  
    67  func (it StatusCheckExecutionSucceed) Reason() string {
    68  	return string(v1alpha1.StatusCheckExecutionSucceed)
    69  }
    70  
    71  func (it StatusCheckExecutionSucceed) Message() string {
    72  	return fmt.Sprintf("%s execution of status check succeed", it.ExecutorType)
    73  }
    74  
    75  type StatusCheckDurationExceed struct {
    76  }
    77  
    78  func (it StatusCheckDurationExceed) Type() string {
    79  	return corev1.EventTypeWarning
    80  }
    81  
    82  func (it StatusCheckDurationExceed) Reason() string {
    83  	return string(v1alpha1.StatusCheckDurationExceed)
    84  }
    85  
    86  func (it StatusCheckDurationExceed) Message() string {
    87  	return "duration exceed"
    88  }
    89  
    90  type StatusCheckFailureThresholdExceed struct {
    91  }
    92  
    93  func (it StatusCheckFailureThresholdExceed) Type() string {
    94  	return corev1.EventTypeWarning
    95  }
    96  
    97  func (it StatusCheckFailureThresholdExceed) Reason() string {
    98  	return string(v1alpha1.StatusCheckFailureThresholdExceed)
    99  }
   100  
   101  func (it StatusCheckFailureThresholdExceed) Message() string {
   102  	return "failure threshold exceed"
   103  }
   104  
   105  type StatusCheckSuccessThresholdExceed struct {
   106  }
   107  
   108  func (it StatusCheckSuccessThresholdExceed) Type() string {
   109  	return corev1.EventTypeNormal
   110  }
   111  
   112  func (it StatusCheckSuccessThresholdExceed) Reason() string {
   113  	return string(v1alpha1.StatusCheckSuccessThresholdExceed)
   114  }
   115  
   116  func (it StatusCheckSuccessThresholdExceed) Message() string {
   117  	return "success threshold exceed"
   118  }
   119  
   120  func init() {
   121  	register(
   122  		StatusCheckCompleted{},
   123  		StatusCheckExecutionFailed{},
   124  		StatusCheckDurationExceed{},
   125  		StatusCheckFailureThresholdExceed{},
   126  		StatusCheckSuccessThresholdExceed{},
   127  	)
   128  }
   129