Skip to content

Commit

Permalink
Merge pull request #7199 from ykakarap/patchable-mhc-managed-clusters
Browse files Browse the repository at this point in the history
✨ Add support to configure MachineHealthChecks for managed Clusters
  • Loading branch information
k8s-ci-robot authored Sep 27, 2022
2 parents a2b11c7 + 241c193 commit 80c4450
Show file tree
Hide file tree
Showing 17 changed files with 1,582 additions and 11 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
}
dst.Spec.Topology.Variables = restored.Spec.Topology.Variables

if restored.Spec.Topology.ControlPlane.MachineHealthCheck != nil {
dst.Spec.Topology.ControlPlane.MachineHealthCheck = restored.Spec.Topology.ControlPlane.MachineHealthCheck
}

if restored.Spec.Topology.ControlPlane.NodeDrainTimeout != nil {
dst.Spec.Topology.ControlPlane.NodeDrainTimeout = restored.Spec.Topology.ControlPlane.NodeDrainTimeout
}
Expand All @@ -65,6 +69,7 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout
dst.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout
dst.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout
dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha4/zz_generated.conversion.go

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

29 changes: 29 additions & 0 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ type ControlPlaneTopology struct {
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// MachineHealthCheck allows to enable, disable and override
// the MachineHealthCheck configuration in the ClusterClass for this control plane.
// +optional
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`

// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
Expand Down Expand Up @@ -172,6 +177,11 @@ type MachineDeploymentTopology struct {
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// MachineHealthCheck allows to enable, disable and override
// the MachineHealthCheck configuration in the ClusterClass for this MachineDeployment.
// +optional
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`

// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
Expand All @@ -194,6 +204,25 @@ type MachineDeploymentTopology struct {
Variables *MachineDeploymentVariables `json:"variables,omitempty"`
}

// MachineHealthCheckTopology defines a MachineHealthCheck for a group of machines.
type MachineHealthCheckTopology struct {
// Enable controls if a MachineHealthCheck should be created for the target machines.
//
// If false: No MachineHealthCheck will be created.
//
// If not set(default): A MachineHealthCheck will be created if it is defined here or
// in the associated ClusterClass. If no MachineHealthCheck is defined then none will be created.
//
// If true: A MachineHealthCheck is guaranteed to be created. Cluster validation will
// block if `enable` is true and no MachineHealthCheck definition is available.
// +optional
Enable *bool `json:"enable,omitempty"`

// MachineHealthCheckClass defines a MachineHealthCheck for a group of machines.
// If specified (any field is set), it entirely overrides the MachineHealthCheckClass defined in ClusterClass.
MachineHealthCheckClass `json:",inline"`
}

// ClusterVariable can be used to customize the Cluster through
// patches. It must comply to the corresponding
// ClusterClassVariable defined in the ClusterClass.
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1beta1

import (
"reflect"

corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -177,6 +179,11 @@ type MachineHealthCheckClass struct {
RemediationTemplate *corev1.ObjectReference `json:"remediationTemplate,omitempty"`
}

// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
func (m MachineHealthCheckClass) IsZero() bool {
return reflect.ValueOf(m).IsZero()
}

// ClusterClassVariable defines a variable which can
// be configured in the Cluster topology and used in patches.
type ClusterClassVariable struct {
Expand Down
31 changes: 31 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

78 changes: 76 additions & 2 deletions api/v1beta1/zz_generated.openapi.go

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

Loading

0 comments on commit 80c4450

Please sign in to comment.