sigs.k8s.io/cluster-api@v1.6.3/api/v1alpha4/machinehealthcheck_types.go (about)

     1  /*
     2  Copyright 2020 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha4
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  	"k8s.io/apimachinery/pkg/util/intstr"
    23  )
    24  
    25  // ANCHOR: MachineHealthCheckSpec
    26  
    27  // MachineHealthCheckSpec defines the desired state of MachineHealthCheck.
    28  type MachineHealthCheckSpec struct {
    29  	// ClusterName is the name of the Cluster this object belongs to.
    30  	// +kubebuilder:validation:MinLength=1
    31  	ClusterName string `json:"clusterName"`
    32  
    33  	// Label selector to match machines whose health will be exercised
    34  	Selector metav1.LabelSelector `json:"selector"`
    35  
    36  	// UnhealthyConditions contains a list of the conditions that determine
    37  	// whether a node is considered unhealthy.  The conditions are combined in a
    38  	// logical OR, i.e. if any of the conditions is met, the node is unhealthy.
    39  	//
    40  	// +kubebuilder:validation:MinItems=1
    41  	UnhealthyConditions []UnhealthyCondition `json:"unhealthyConditions"`
    42  
    43  	// Any further remediation is only allowed if at most "MaxUnhealthy" machines selected by
    44  	// "selector" are not healthy.
    45  	// +optional
    46  	MaxUnhealthy *intstr.IntOrString `json:"maxUnhealthy,omitempty"`
    47  
    48  	// Any further remediation is only allowed if the number of machines selected by "selector" as not healthy
    49  	// is within the range of "UnhealthyRange". Takes precedence over MaxUnhealthy.
    50  	// Eg. "[3-5]" - This means that remediation will be allowed only when:
    51  	// (a) there are at least 3 unhealthy machines (and)
    52  	// (b) there are at most 5 unhealthy machines
    53  	// +optional
    54  	// +kubebuilder:validation:Pattern=^\[[0-9]+-[0-9]+\]$
    55  	UnhealthyRange *string `json:"unhealthyRange,omitempty"`
    56  
    57  	// Machines older than this duration without a node will be considered to have
    58  	// failed and will be remediated.
    59  	// If not set, this value is defaulted to 10 minutes.
    60  	// If you wish to disable this feature, set the value explicitly to 0.
    61  	// +optional
    62  	NodeStartupTimeout *metav1.Duration `json:"nodeStartupTimeout,omitempty"`
    63  
    64  	// RemediationTemplate is a reference to a remediation template
    65  	// provided by an infrastructure provider.
    66  	//
    67  	// This field is completely optional, when filled, the MachineHealthCheck controller
    68  	// creates a new object from the template referenced and hands off remediation of the machine to
    69  	// a controller that lives outside of Cluster API.
    70  	// +optional
    71  	RemediationTemplate *corev1.ObjectReference `json:"remediationTemplate,omitempty"`
    72  }
    73  
    74  // ANCHOR_END: MachineHealthCHeckSpec
    75  
    76  // ANCHOR: UnhealthyCondition
    77  
    78  // UnhealthyCondition represents a Node condition type and value with a timeout
    79  // specified as a duration.  When the named condition has been in the given
    80  // status for at least the timeout value, a node is considered unhealthy.
    81  type UnhealthyCondition struct {
    82  	// +kubebuilder:validation:Type=string
    83  	// +kubebuilder:validation:MinLength=1
    84  	Type corev1.NodeConditionType `json:"type"`
    85  
    86  	// +kubebuilder:validation:Type=string
    87  	// +kubebuilder:validation:MinLength=1
    88  	Status corev1.ConditionStatus `json:"status"`
    89  
    90  	Timeout metav1.Duration `json:"timeout"`
    91  }
    92  
    93  // ANCHOR_END: UnhealthyCondition
    94  
    95  // ANCHOR: MachineHealthCheckStatus
    96  
    97  // MachineHealthCheckStatus defines the observed state of MachineHealthCheck.
    98  type MachineHealthCheckStatus struct {
    99  	// total number of machines counted by this machine health check
   100  	// +kubebuilder:validation:Minimum=0
   101  	ExpectedMachines int32 `json:"expectedMachines,omitempty"`
   102  
   103  	// total number of healthy machines counted by this machine health check
   104  	// +kubebuilder:validation:Minimum=0
   105  	CurrentHealthy int32 `json:"currentHealthy,omitempty"`
   106  
   107  	// RemediationsAllowed is the number of further remediations allowed by this machine health check before
   108  	// maxUnhealthy short circuiting will be applied
   109  	// +kubebuilder:validation:Minimum=0
   110  	RemediationsAllowed int32 `json:"remediationsAllowed,omitempty"`
   111  
   112  	// ObservedGeneration is the latest generation observed by the controller.
   113  	// +optional
   114  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
   115  
   116  	// Targets shows the current list of machines the machine health check is watching
   117  	// +optional
   118  	Targets []string `json:"targets,omitempty"`
   119  
   120  	// Conditions defines current service state of the MachineHealthCheck.
   121  	// +optional
   122  	Conditions Conditions `json:"conditions,omitempty"`
   123  }
   124  
   125  // ANCHOR_END: MachineHealthCheckStatus
   126  
   127  // +kubebuilder:object:root=true
   128  // +kubebuilder:unservedversion
   129  // +kubebuilder:deprecatedversion
   130  // +kubebuilder:resource:path=machinehealthchecks,shortName=mhc;mhcs,scope=Namespaced,categories=cluster-api
   131  // +kubebuilder:subresource:status
   132  // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.clusterName",description="Cluster"
   133  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of MachineHealthCheck"
   134  // +kubebuilder:printcolumn:name="MaxUnhealthy",type="string",JSONPath=".spec.maxUnhealthy",description="Maximum number of unhealthy machines allowed"
   135  // +kubebuilder:printcolumn:name="ExpectedMachines",type="integer",JSONPath=".status.expectedMachines",description="Number of machines currently monitored"
   136  // +kubebuilder:printcolumn:name="CurrentHealthy",type="integer",JSONPath=".status.currentHealthy",description="Current observed healthy machines"
   137  
   138  // MachineHealthCheck is the Schema for the machinehealthchecks API.
   139  //
   140  // Deprecated: This type will be removed in one of the next releases.
   141  type MachineHealthCheck struct {
   142  	metav1.TypeMeta   `json:",inline"`
   143  	metav1.ObjectMeta `json:"metadata,omitempty"`
   144  
   145  	// Specification of machine health check policy
   146  	Spec MachineHealthCheckSpec `json:"spec,omitempty"`
   147  
   148  	// Most recently observed status of MachineHealthCheck resource
   149  	Status MachineHealthCheckStatus `json:"status,omitempty"`
   150  }
   151  
   152  // GetConditions returns the set of conditions for this object.
   153  func (m *MachineHealthCheck) GetConditions() Conditions {
   154  	return m.Status.Conditions
   155  }
   156  
   157  // SetConditions sets the conditions on this object.
   158  func (m *MachineHealthCheck) SetConditions(conditions Conditions) {
   159  	m.Status.Conditions = conditions
   160  }
   161  
   162  // +kubebuilder:object:root=true
   163  
   164  // MachineHealthCheckList contains a list of MachineHealthCheck.
   165  //
   166  // Deprecated: This type will be removed in one of the next releases.
   167  type MachineHealthCheckList struct {
   168  	metav1.TypeMeta `json:",inline"`
   169  	metav1.ListMeta `json:"metadata,omitempty"`
   170  	Items           []MachineHealthCheck `json:"items"`
   171  }
   172  
   173  func init() {
   174  	objectTypes = append(objectTypes, &MachineHealthCheck{}, &MachineHealthCheckList{})
   175  }