Skip to content

✨ MachineHealthCheck supports checking Machine conditions #12275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions api/core/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestFuzzyConversion(t *testing.T) {

func ClusterFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
hubClusterSpec,
hubClusterStatus,
spokeClusterTopology,
spokeClusterStatus,
Expand All @@ -99,6 +100,21 @@ func hubClusterStatus(in *clusterv1.ClusterStatus, c randfill.Continue) {
}
}

func hubClusterSpec(in *clusterv1.ClusterSpec, c randfill.Continue) {
c.FillNoCustom(in)

// remove MachineHealthCheck.UnhealthyMachineConditions as it does not exist in v1beta1.
if in.Topology != nil && in.Topology.ControlPlane.MachineHealthCheck != nil {
in.Topology.ControlPlane.MachineHealthCheck.UnhealthyMachineConditions = nil
}

if in.Topology != nil && in.Topology.Workers != nil && len(in.Topology.Workers.MachineDeployments) > 0 {
for i := range in.Topology.Workers.MachineDeployments {
in.Topology.Workers.MachineDeployments[i].MachineHealthCheck = nil
}
}
}

func spokeClusterTopology(in *Topology, c randfill.Continue) {
c.FillNoCustom(in)

Expand Down Expand Up @@ -129,6 +145,22 @@ func ClusterClassFuncs(_ runtimeserializer.CodecFactory) []interface{} {
hubJSONSchemaProps,
spokeClusterClassStatus,
spokeJSONSchemaProps,
hubClusterClassSpec,
}
}

func hubClusterClassSpec(in *clusterv1.ClusterClassSpec, c randfill.Continue) {
c.FillNoCustom(in)

// remove MachineHealthCheck.UnhealthyMachineConditions as it does not exist in v1beta1.
if in.ControlPlane.MachineHealthCheck != nil && in.ControlPlane.MachineHealthCheck.UnhealthyMachineConditions != nil {
in.ControlPlane.MachineHealthCheck.UnhealthyMachineConditions = nil
}

if len(in.Workers.MachineDeployments) > 0 {
for i := range in.Workers.MachineDeployments {
in.Workers.MachineDeployments[i].MachineHealthCheck = nil
}
}
}

Expand Down Expand Up @@ -348,13 +380,24 @@ func spokeMachineDeploymentStatus(in *MachineDeploymentStatus, c randfill.Contin

func MachineHealthCheckFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
hubMachineHealthCheckSpec,
hubMachineHealthCheckStatus,
spokeMachineHealthCheckStatus,
}
}

func hubMachineHealthCheckSpec(in *clusterv1.MachineHealthCheckSpec, c randfill.Continue) {
c.FillNoCustom(in)

// Drop UnhealthyMachineConditions as it does not exist in v1beta1.
if in.UnhealthyMachineConditions != nil {
in.UnhealthyMachineConditions = nil
}
}

func hubMachineHealthCheckStatus(in *clusterv1.MachineHealthCheckStatus, c randfill.Continue) {
c.FillNoCustom(in)

// Drop empty structs with only omit empty fields.
if in.Deprecated != nil {
if in.Deprecated.V1Beta1 == nil || reflect.DeepEqual(in.Deprecated.V1Beta1, &clusterv1.MachineHealthCheckV1Beta1DeprecatedStatus{}) {
Expand Down
2 changes: 2 additions & 0 deletions api/core/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions api/core/v1beta2/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ type MachineHealthCheckClass struct {
// +kubebuilder:validation:MaxItems=100
UnhealthyNodeConditions []UnhealthyNodeCondition `json:"unhealthyNodeConditions,omitempty"`

// unhealthyMachineConditions contains a list of the machine conditions that determine
// whether a node is considered unhealthy. The conditions are combined in a
// logical OR, i.e. if any of the conditions is met, the node is unhealthy.
//
// +optional
// +kubebuilder:validation:MaxItems=100
UnhealthyMachineConditions []UnhealthyMachineCondition `json:"unhealthyMachineConditions,omitempty"`

// maxUnhealthy specifies the maximum number of unhealthy machines allowed.
// Any further remediation is only allowed if at most "maxUnhealthy" machines selected by
// "selector" are not healthy.
Expand Down
4 changes: 4 additions & 0 deletions api/core/v1beta2/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ const (
// defined by a MachineHealthCheck object.
MachineHealthCheckUnhealthyNodeReason = "UnhealthyNode"

// MachineHealthCheckUnhealthyMachineReason surfaces when the machine does not pass the health checks
// defined by a MachineHealthCheck object.
MachineHealthCheckUnhealthyMachineReason = "UnhealthyMachine"

// MachineHealthCheckNodeStartupTimeoutReason surfaces when the node hosted on the machine does not appear within
// the timeout defined by a MachineHealthCheck object.
MachineHealthCheckNodeStartupTimeoutReason = "NodeStartupTimeout"
Expand Down
36 changes: 36 additions & 0 deletions api/core/v1beta2/machinehealthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ type MachineHealthCheckSpec struct {
// +kubebuilder:validation:MaxItems=100
UnhealthyNodeConditions []UnhealthyNodeCondition `json:"unhealthyNodeConditions,omitempty"`

// unhealthyMachineConditions contains a list of the machine conditions that determine
// whether a node is considered unhealthy. The conditions are combined in a
// logical OR, i.e. if any of the conditions is met, the node is unhealthy.
//
// +optional
// +kubebuilder:validation:MaxItems=100
UnhealthyMachineConditions []UnhealthyMachineCondition `json:"unhealthyMachineConditions,omitempty"`

// maxUnhealthy specifies the maximum number of unhealthy machines allowed.
// Any further remediation is only allowed if at most "maxUnhealthy" machines selected by
// "selector" are not healthy.
Expand Down Expand Up @@ -148,6 +156,34 @@ type UnhealthyNodeCondition struct {

// ANCHOR_END: UnhealthyNodeCondition

// ANCHOR: UnhealthyMachineCondition

// UnhealthyMachineCondition represents a Node condition type and value with a timeout
// specified as a duration. When the named condition has been in the given
// status for at least the timeout value, a node is considered unhealthy.
type UnhealthyMachineCondition struct {
// type of Node condition
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=316
// +required
Type string `json:"type"`

// status of the condition, one of True, False, Unknown.
// +required
// +kubebuilder:validation:Enum=True;False;Unknown
Status metav1.ConditionStatus `json:"status"`

// timeout is the duration that a node must be in a given status for,
// after which the node is considered unhealthy.
// For example, with a value of "1h", the node must match the status
// for at least 1 hour before being considered unhealthy.
// +required
Timeout metav1.Duration `json:"timeout"`
}

// ANCHOR_END: UnhealthyMachineCondition

// ANCHOR: MachineHealthCheckStatus

// MachineHealthCheckStatus defines the observed state of MachineHealthCheck.
Expand Down
3 changes: 3 additions & 0 deletions api/core/v1beta2/v1beta1_condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ const (

// UnhealthyNodeConditionV1Beta1Reason is the reason used when a machine's node has one of the MachineHealthCheck's unhealthy conditions.
UnhealthyNodeConditionV1Beta1Reason = "UnhealthyNode"

// UnhealthyMachineConditionV1Beta1Reason is the reason used when a machine has one of the MachineHealthCheck's unhealthy conditions.
UnhealthyMachineConditionV1Beta1Reason = "UnhealthyMachine"
)

const (
Expand Down
26 changes: 26 additions & 0 deletions api/core/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 84 additions & 3 deletions api/core/v1beta2/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading