Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .golangci-kal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ linters:
linters:
- kubeapilinter
- path: "api/core/v1beta2/*|api/controlplane/kubeadm/v1beta2/*"
text: "optionalfields: field (Naming|MachineNaming|Deletion) is optional and should (be a pointer|have the omitempty tag)"
text: "optionalfields: field (Naming|HealthCheck|MachineNaming|Deletion) is optional and should (be a pointer|have the omitempty tag)"
linters:
- kubeapilinter

Expand Down
10 changes: 10 additions & 0 deletions api/controlplane/kubeadm/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ func spokeKubeadmControlPlane(in *KubeadmControlPlane, c randfill.Continue) {
if reflect.DeepEqual(in.Spec.RolloutBefore, &RolloutBefore{}) {
in.Spec.RolloutBefore = nil
}
if in.Spec.RolloutStrategy != nil {
if reflect.DeepEqual(in.Spec.RolloutStrategy.RollingUpdate, &RollingUpdate{}) {
in.Spec.RolloutStrategy.RollingUpdate = nil
}
}
if reflect.DeepEqual(in.Spec.RolloutStrategy, &RolloutStrategy{}) {
in.Spec.RolloutStrategy = nil
}
Expand Down Expand Up @@ -252,6 +257,11 @@ func spokeKubeadmControlPlaneTemplate(in *KubeadmControlPlaneTemplate, c randfil
if reflect.DeepEqual(in.Spec.Template.Spec.RolloutBefore, &RolloutBefore{}) {
in.Spec.Template.Spec.RolloutBefore = nil
}
if in.Spec.Template.Spec.RolloutStrategy != nil {
if reflect.DeepEqual(in.Spec.Template.Spec.RolloutStrategy.RollingUpdate, &RollingUpdate{}) {
in.Spec.Template.Spec.RolloutStrategy.RollingUpdate = nil
}
}
if reflect.DeepEqual(in.Spec.Template.Spec.RolloutStrategy, &RolloutStrategy{}) {
in.Spec.Template.Spec.RolloutStrategy = nil
}
Expand Down
26 changes: 6 additions & 20 deletions api/core/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ func Convert_v1beta1_ControlPlaneClass_To_v1beta2_ControlPlaneClass(in *ControlP
convert_v1beta1_LocalObjectTemplate_To_v1beta2_ClusterClassTemplateReference(&in.LocalObjectTemplate, &out.TemplateRef, s)

if in.MachineHealthCheck != nil {
out.HealthCheck = &clusterv1.ControlPlaneClassHealthCheck{}
for _, c := range in.MachineHealthCheck.UnhealthyConditions {
out.HealthCheck.Checks.UnhealthyNodeConditions = append(out.HealthCheck.Checks.UnhealthyNodeConditions, clusterv1.UnhealthyNodeCondition{
Type: c.Type,
Expand Down Expand Up @@ -712,7 +711,7 @@ func Convert_v1beta2_ControlPlaneClass_To_v1beta1_ControlPlaneClass(in *clusterv
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDeletionTimeoutSeconds)
Convert_v1beta2_ClusterClassTemplateReference_To_v1beta1_LocalObjectTemplate(&in.TemplateRef, &out.LocalObjectTemplate, s)

if in.HealthCheck != nil {
if !reflect.DeepEqual(in.HealthCheck, clusterv1.ControlPlaneClassHealthCheck{}) {
out.MachineHealthCheck = &MachineHealthCheckClass{}
for _, c := range in.HealthCheck.Checks.UnhealthyNodeConditions {
out.MachineHealthCheck.UnhealthyConditions = append(out.MachineHealthCheck.UnhealthyConditions, UnhealthyCondition{
Expand Down Expand Up @@ -755,7 +754,6 @@ func Convert_v1beta1_ControlPlaneTopology_To_v1beta2_ControlPlaneTopology(in *Co
out.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)

if in.MachineHealthCheck != nil {
out.HealthCheck = &clusterv1.ControlPlaneTopologyHealthCheck{}
out.HealthCheck.Enabled = in.MachineHealthCheck.Enable
for _, c := range in.MachineHealthCheck.UnhealthyConditions {
out.HealthCheck.Checks.UnhealthyNodeConditions = append(out.HealthCheck.Checks.UnhealthyNodeConditions, clusterv1.UnhealthyNodeCondition{
Expand Down Expand Up @@ -791,7 +789,7 @@ func Convert_v1beta2_ControlPlaneTopology_To_v1beta1_ControlPlaneTopology(in *cl
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeVolumeDetachTimeoutSeconds)
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDeletionTimeoutSeconds)

if in.HealthCheck != nil {
if !reflect.DeepEqual(in.HealthCheck, clusterv1.ControlPlaneTopologyHealthCheck{}) {
out.MachineHealthCheck = &MachineHealthCheckTopology{}
out.MachineHealthCheck.Enable = in.HealthCheck.Enabled
for _, c := range in.HealthCheck.Checks.UnhealthyNodeConditions {
Expand Down Expand Up @@ -839,9 +837,6 @@ func Convert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in
}
}
if in.Strategy.Remediation != nil && in.Strategy.Remediation.MaxInFlight != nil {
if out.HealthCheck == nil {
out.HealthCheck = &clusterv1.MachineDeploymentClassHealthCheck{}
}
out.HealthCheck.Remediation.MaxInFlight = in.Strategy.Remediation.MaxInFlight
}
}
Expand All @@ -850,9 +845,6 @@ func Convert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in
out.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)

if in.MachineHealthCheck != nil {
if out.HealthCheck == nil {
out.HealthCheck = &clusterv1.MachineDeploymentClassHealthCheck{}
}
for _, c := range in.MachineHealthCheck.UnhealthyConditions {
out.HealthCheck.Checks.UnhealthyNodeConditions = append(out.HealthCheck.Checks.UnhealthyNodeConditions, clusterv1.UnhealthyNodeCondition{
Type: c.Type,
Expand Down Expand Up @@ -909,7 +901,7 @@ func Convert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClass(in
}
out.Strategy.RollingUpdate.DeletePolicy = ptr.To(string(in.Deletion.Order))
}
if in.HealthCheck != nil && in.HealthCheck.Remediation.MaxInFlight != nil {
if in.HealthCheck.Remediation.MaxInFlight != nil {
if out.Strategy == nil {
out.Strategy = &MachineDeploymentStrategy{}
}
Expand All @@ -923,7 +915,7 @@ func Convert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClass(in
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDeletionTimeoutSeconds)

// Check if HealthCheck is not nil and another field apart from MaxInFlight is set (MaxInFlight is set in Strategy above).
if in.HealthCheck != nil && !reflect.DeepEqual(in.HealthCheck, &clusterv1.MachineDeploymentClassHealthCheck{
if !reflect.DeepEqual(in.HealthCheck, clusterv1.MachineDeploymentClassHealthCheck{
Remediation: clusterv1.MachineDeploymentClassHealthCheckRemediation{MaxInFlight: in.HealthCheck.Remediation.MaxInFlight},
}) {
out.MachineHealthCheck = &MachineHealthCheckClass{}
Expand Down Expand Up @@ -973,9 +965,6 @@ func Convert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopol
}
}
if in.Strategy.Remediation != nil && in.Strategy.Remediation.MaxInFlight != nil {
if out.HealthCheck == nil {
out.HealthCheck = &clusterv1.MachineDeploymentTopologyHealthCheck{}
}
out.HealthCheck.Remediation.MaxInFlight = in.Strategy.Remediation.MaxInFlight
}
}
Expand All @@ -984,9 +973,6 @@ func Convert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopol
out.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)

if in.MachineHealthCheck != nil {
if out.HealthCheck == nil {
out.HealthCheck = &clusterv1.MachineDeploymentTopologyHealthCheck{}
}
out.HealthCheck.Enabled = in.MachineHealthCheck.Enable
for _, c := range in.MachineHealthCheck.UnhealthyConditions {
out.HealthCheck.Checks.UnhealthyNodeConditions = append(out.HealthCheck.Checks.UnhealthyNodeConditions, clusterv1.UnhealthyNodeCondition{
Expand Down Expand Up @@ -1036,7 +1022,7 @@ func Convert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentTopol
}
out.Strategy.RollingUpdate.DeletePolicy = ptr.To(string(in.Deletion.Order))
}
if in.HealthCheck != nil && in.HealthCheck.Remediation.MaxInFlight != nil {
if in.HealthCheck.Remediation.MaxInFlight != nil {
if out.Strategy == nil {
out.Strategy = &MachineDeploymentStrategy{}
}
Expand All @@ -1050,7 +1036,7 @@ func Convert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentTopol
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDeletionTimeoutSeconds)

// Check if HealthCheck is not nil and another field apart from MaxInFlight is set (MaxInFlight is set in Strategy above).
if in.HealthCheck != nil && !reflect.DeepEqual(in.HealthCheck, &clusterv1.MachineDeploymentTopologyHealthCheck{
if !reflect.DeepEqual(in.HealthCheck, clusterv1.MachineDeploymentTopologyHealthCheck{
Remediation: clusterv1.MachineDeploymentTopologyHealthCheckRemediation{MaxInFlight: in.HealthCheck.Remediation.MaxInFlight},
}) {
out.MachineHealthCheck = &MachineHealthCheckTopology{}
Expand Down
8 changes: 4 additions & 4 deletions api/core/v1beta2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ type ControlPlaneTopology struct {
// healthCheck allows to enable, disable and override control plane health check
// configuration from the ClusterClass for this control plane.
// +optional
HealthCheck *ControlPlaneTopologyHealthCheck `json:"healthCheck,omitempty"`
HealthCheck ControlPlaneTopologyHealthCheck `json:"healthCheck,omitempty,omitzero"`

// deletion contains configuration options for Machine deletion.
// +optional
Expand Down Expand Up @@ -689,7 +689,7 @@ type ControlPlaneTopologyHealthCheck struct {
Remediation ControlPlaneTopologyHealthCheckRemediation `json:"remediation,omitempty,omitzero"`
}

// IsDefined returns true if both checks and remediation are zero.
// IsDefined returns true if one of checks and remediation are not zero.
func (m *ControlPlaneTopologyHealthCheck) IsDefined() bool {
return !reflect.ValueOf(m.Checks).IsZero() || !reflect.ValueOf(m.Remediation).IsZero()
}
Expand Down Expand Up @@ -852,7 +852,7 @@ type MachineDeploymentTopology struct {
// healthCheck allows to enable, disable and override MachineDeployment health check
// configuration from the ClusterClass for this MachineDeployment.
// +optional
HealthCheck *MachineDeploymentTopologyHealthCheck `json:"healthCheck,omitempty"`
HealthCheck MachineDeploymentTopologyHealthCheck `json:"healthCheck,omitempty,omitzero"`

// deletion contains configuration options for Machine deletion.
// +optional
Expand Down Expand Up @@ -938,7 +938,7 @@ type MachineDeploymentTopologyHealthCheck struct {
Remediation MachineDeploymentTopologyHealthCheckRemediation `json:"remediation,omitempty,omitzero"`
}

// IsDefined returns true if both checks and remediation are zero.
// IsDefined returns true if one of checks and remediation are not zero.
func (m *MachineDeploymentTopologyHealthCheck) IsDefined() bool {
return !reflect.ValueOf(m.Checks).IsZero() || !reflect.ValueOf(m.Remediation).IsZero()
}
Expand Down
16 changes: 14 additions & 2 deletions api/core/v1beta2/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1beta2

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 @@ -171,7 +173,7 @@ type ControlPlaneClass struct {
// This field is supported if and only if the ControlPlane provider template
// referenced above is Machine based and supports setting replicas.
// +optional
HealthCheck *ControlPlaneClassHealthCheck `json:"healthCheck,omitempty"`
HealthCheck ControlPlaneClassHealthCheck `json:"healthCheck,omitempty,omitzero"`

// naming allows changing the naming pattern used when creating the control plane provider object.
// +optional
Expand Down Expand Up @@ -226,6 +228,11 @@ type ControlPlaneClassHealthCheck struct {
Remediation ControlPlaneClassHealthCheckRemediation `json:"remediation,omitempty,omitzero"`
}

// IsDefined returns true if one of checks and remediation are not zero.
func (m *ControlPlaneClassHealthCheck) IsDefined() bool {
return !reflect.ValueOf(m.Checks).IsZero() || !reflect.ValueOf(m.Remediation).IsZero()
}

// ControlPlaneClassHealthCheckChecks are the checks that are used to evaluate if a control plane Machine is healthy.
// +kubebuilder:validation:MinProperties=1
type ControlPlaneClassHealthCheckChecks struct {
Expand Down Expand Up @@ -405,7 +412,7 @@ type MachineDeploymentClass struct {

// healthCheck defines a MachineHealthCheck for this MachineDeploymentClass.
// +optional
HealthCheck *MachineDeploymentClassHealthCheck `json:"healthCheck,omitempty"`
HealthCheck MachineDeploymentClassHealthCheck `json:"healthCheck,omitempty,omitzero"`

// failureDomain is the failure domain the machines will be created in.
// Must match the name of a FailureDomain from the Cluster status.
Expand Down Expand Up @@ -480,6 +487,11 @@ type MachineDeploymentClassHealthCheck struct {
Remediation MachineDeploymentClassHealthCheckRemediation `json:"remediation,omitempty,omitzero"`
}

// IsDefined returns true if one of checks and remediation are not zero.
func (m *MachineDeploymentClassHealthCheck) IsDefined() bool {
return !reflect.ValueOf(m.Checks).IsZero() || !reflect.ValueOf(m.Remediation).IsZero()
}

// MachineDeploymentClassHealthCheckChecks are the checks that are used to evaluate if a MachineDeployment Machine is healthy.
// +kubebuilder:validation:MinProperties=1
type MachineDeploymentClassHealthCheckChecks struct {
Expand Down
24 changes: 4 additions & 20 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.

4 changes: 4 additions & 0 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.

8 changes: 2 additions & 6 deletions exp/topology/desiredstate/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -821,11 +820,8 @@ func (g *generator) computeMachineDeployment(ctx context.Context, s *scope.Scope
}
}

var remediationMaxInFlight *intstr.IntOrString
if machineDeploymentClass.HealthCheck != nil && machineDeploymentClass.HealthCheck.Remediation.MaxInFlight != nil {
remediationMaxInFlight = machineDeploymentClass.HealthCheck.Remediation.MaxInFlight
}
if machineDeploymentTopology.HealthCheck != nil && machineDeploymentTopology.HealthCheck.Remediation.MaxInFlight != nil {
remediationMaxInFlight := machineDeploymentClass.HealthCheck.Remediation.MaxInFlight
if machineDeploymentTopology.HealthCheck.Remediation.MaxInFlight != nil {
remediationMaxInFlight = machineDeploymentTopology.HealthCheck.Remediation.MaxInFlight
}

Expand Down
10 changes: 5 additions & 5 deletions exp/topology/desiredstate/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ func TestComputeMachineDeployment(t *testing.T) {
clusterClassMDStrategy := clusterv1.MachineDeploymentRolloutStrategy{
Type: clusterv1.OnDeleteMachineDeploymentStrategyType,
}
clusterClassHealthCheck := &clusterv1.MachineDeploymentClassHealthCheck{
clusterClassHealthCheck := clusterv1.MachineDeploymentClassHealthCheck{
Remediation: clusterv1.MachineDeploymentClassHealthCheckRemediation{
MaxInFlight: ptr.To(intstr.FromInt32(5)),
},
Expand All @@ -1771,7 +1771,7 @@ func TestComputeMachineDeployment(t *testing.T) {
WithAnnotations(annotations).
WithInfrastructureTemplate(workerInfrastructureMachineTemplate).
WithBootstrapTemplate(workerBootstrapTemplate).
WithMachineHealthCheckClass(&clusterv1.MachineDeploymentClassHealthCheck{
WithMachineHealthCheckClass(clusterv1.MachineDeploymentClassHealthCheck{
Checks: clusterv1.MachineDeploymentClassHealthCheckChecks{
UnhealthyNodeConditions: unhealthyNodeConditions,
NodeStartupTimeoutSeconds: nodeTimeoutDuration,
Expand Down Expand Up @@ -1816,7 +1816,7 @@ func TestComputeMachineDeployment(t *testing.T) {
},
BootstrapTemplate: workerBootstrapTemplate,
InfrastructureMachineTemplate: workerInfrastructureMachineTemplate,
HealthCheck: &clusterv1.MachineDeploymentClassHealthCheck{
HealthCheck: clusterv1.MachineDeploymentClassHealthCheck{
Checks: clusterv1.MachineDeploymentClassHealthCheckChecks{
UnhealthyNodeConditions: unhealthyNodeConditions,
NodeStartupTimeoutSeconds: ptr.To(int32(1)),
Expand All @@ -1836,7 +1836,7 @@ func TestComputeMachineDeployment(t *testing.T) {
topologyMDStrategy := clusterv1.MachineDeploymentRolloutStrategy{
Type: clusterv1.RollingUpdateMachineDeploymentStrategyType,
}
topologyHealthCheck := &clusterv1.MachineDeploymentTopologyHealthCheck{
topologyHealthCheck := clusterv1.MachineDeploymentTopologyHealthCheck{
Remediation: clusterv1.MachineDeploymentTopologyHealthCheckRemediation{
MaxInFlight: ptr.To(intstr.FromInt32(1)),
},
Expand Down Expand Up @@ -1992,7 +1992,7 @@ func TestComputeMachineDeployment(t *testing.T) {
},
BootstrapTemplate: workerBootstrapTemplate,
InfrastructureMachineTemplate: workerInfrastructureMachineTemplate,
HealthCheck: &clusterv1.MachineDeploymentClassHealthCheck{
HealthCheck: clusterv1.MachineDeploymentClassHealthCheck{
Checks: clusterv1.MachineDeploymentClassHealthCheckChecks{
UnhealthyNodeConditions: unhealthyNodeConditions,
NodeStartupTimeoutSeconds: ptr.To(int32(1)),
Expand Down
Loading