Skip to content

Commit 1644530

Browse files
committed
Fix review findings
1 parent fbed717 commit 1644530

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

api/core/v1beta2/cluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ type ControlPlaneTopologyMachineHealthCheck struct {
667667

668668
// IsDefined returns true if both checks and remediation are zero.
669669
func (m *ControlPlaneTopologyMachineHealthCheck) IsDefined() bool {
670-
return reflect.ValueOf(m.Checks).IsZero() && reflect.ValueOf(m.Remediation).IsZero()
670+
return !reflect.ValueOf(m.Checks).IsZero() || !reflect.ValueOf(m.Remediation).IsZero()
671671
}
672672

673673
// ControlPlaneTopologyMachineHealthCheckChecks are the checks that are used to evaluate if a control plane Machine is healthy.
@@ -892,7 +892,7 @@ type MachineDeploymentTopologyMachineHealthCheck struct {
892892

893893
// IsDefined returns true if both checks and remediation are zero.
894894
func (m *MachineDeploymentTopologyMachineHealthCheck) IsDefined() bool {
895-
return reflect.ValueOf(m.Checks).IsZero() && reflect.ValueOf(m.Remediation).IsZero()
895+
return !reflect.ValueOf(m.Checks).IsZero() || !reflect.ValueOf(m.Remediation).IsZero()
896896
}
897897

898898
// MachineDeploymentTopologyMachineHealthCheckChecks are the checks that are used to evaluate if a MachineDeployment Machine is healthy.

exp/topology/scope/blueprint.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (b *ClusterBlueprint) IsControlPlaneMachineHealthCheckEnabled() bool {
104104
}
105105
// If no MachineHealthCheck is defined in the ClusterClass or in the Cluster Topology then return false.
106106
if b.ClusterClass.Spec.ControlPlane.HealthCheck == nil &&
107-
(b.Topology.ControlPlane.HealthCheck == nil || b.Topology.ControlPlane.HealthCheck.IsDefined()) {
107+
(b.Topology.ControlPlane.HealthCheck == nil || !b.Topology.ControlPlane.HealthCheck.IsDefined()) {
108108
return false
109109
}
110110
// If `enable` is not set then consider it as true. A MachineHealthCheck will be created from either ClusterClass or Cluster Topology.
@@ -121,7 +121,7 @@ func (b *ClusterBlueprint) ControlPlaneMachineHealthCheckClass() (clusterv1.Mach
121121
return clusterv1.MachineHealthCheckChecks{}, clusterv1.MachineHealthCheckRemediation{}
122122
}
123123

124-
if b.Topology.ControlPlane.HealthCheck != nil && !b.Topology.ControlPlane.HealthCheck.IsDefined() {
124+
if b.Topology.ControlPlane.HealthCheck != nil && b.Topology.ControlPlane.HealthCheck.IsDefined() {
125125
return clusterv1.MachineHealthCheckChecks{
126126
NodeStartupTimeoutSeconds: b.Topology.ControlPlane.HealthCheck.Checks.NodeStartupTimeoutSeconds,
127127
UnhealthyNodeConditions: b.Topology.ControlPlane.HealthCheck.Checks.UnhealthyNodeConditions,
@@ -155,7 +155,7 @@ func (b *ClusterBlueprint) HasControlPlaneMachineHealthCheck() bool {
155155
// Returns false otherwise.
156156
func (b *ClusterBlueprint) IsMachineDeploymentMachineHealthCheckEnabled(md *clusterv1.MachineDeploymentTopology) bool {
157157
// If no MachineHealthCheck is defined in the ClusterClass or in the Cluster Topology then return false.
158-
if b.MachineDeployments[md.Class].MachineHealthCheck == nil && (md.HealthCheck == nil || md.HealthCheck.IsDefined()) {
158+
if b.MachineDeployments[md.Class].MachineHealthCheck == nil && (md.HealthCheck == nil || !md.HealthCheck.IsDefined()) {
159159
return false
160160
}
161161
// If `enable` is not set then consider it as true. A MachineHealthCheck will be created from either ClusterClass or Cluster Topology.
@@ -172,7 +172,7 @@ func (b *ClusterBlueprint) MachineDeploymentMachineHealthCheckClass(md *clusterv
172172
return clusterv1.MachineHealthCheckChecks{}, clusterv1.MachineHealthCheckRemediation{}
173173
}
174174

175-
if md.HealthCheck != nil && !md.HealthCheck.IsDefined() {
175+
if md.HealthCheck != nil && md.HealthCheck.IsDefined() {
176176
return clusterv1.MachineHealthCheckChecks{
177177
NodeStartupTimeoutSeconds: md.HealthCheck.Checks.NodeStartupTimeoutSeconds,
178178
UnhealthyNodeConditions: md.HealthCheck.Checks.UnhealthyNodeConditions,

internal/webhooks/cluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust
640640
fldPath := field.NewPath("spec", "topology", "controlPlane", "machineHealthCheck")
641641

642642
// Validate ControlPlane MachineHealthCheck if defined.
643-
if !cluster.Spec.Topology.ControlPlane.HealthCheck.IsDefined() {
643+
if cluster.Spec.Topology.ControlPlane.HealthCheck.IsDefined() {
644644
// Ensure ControlPlane does not define a MachineHealthCheck if the ClusterClass does not define MachineInfrastructure.
645645
if clusterClass.Spec.ControlPlane.MachineInfrastructure == nil {
646646
allErrs = append(allErrs, field.Forbidden(
@@ -659,7 +659,7 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust
659659
// Check if the machineHealthCheck is explicitly enabled in the ControlPlaneTopology.
660660
if cluster.Spec.Topology.ControlPlane.HealthCheck.Enabled != nil && *cluster.Spec.Topology.ControlPlane.HealthCheck.Enabled {
661661
// Ensure the MHC is defined in at least one of the ControlPlaneTopology of the Cluster or the ControlPlaneClass of the ClusterClass.
662-
if cluster.Spec.Topology.ControlPlane.HealthCheck.IsDefined() && clusterClass.Spec.ControlPlane.HealthCheck == nil {
662+
if !cluster.Spec.Topology.ControlPlane.HealthCheck.IsDefined() && clusterClass.Spec.ControlPlane.HealthCheck == nil {
663663
allErrs = append(allErrs, field.Forbidden(
664664
fldPath.Child("enable"),
665665
fmt.Sprintf("cannot be set to %t as MachineHealthCheck definition is not available in the Cluster topology or the ClusterClass", *cluster.Spec.Topology.ControlPlane.HealthCheck.Enabled),
@@ -674,7 +674,7 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust
674674
fldPath := field.NewPath("spec", "topology", "workers", "machineDeployments").Key(md.Name).Child("machineHealthCheck")
675675

676676
// Validate the MachineDeployment MachineHealthCheck if defined.
677-
if !md.HealthCheck.IsDefined() {
677+
if md.HealthCheck.IsDefined() {
678678
allErrs = append(allErrs, validateMachineHealthCheckNodeStartupTimeoutSeconds(fldPath, md.HealthCheck.Checks.NodeStartupTimeoutSeconds)...)
679679
allErrs = append(allErrs, validateMachineHealthCheckUnhealthyLessThanOrEqualTo(fldPath, md.HealthCheck.Remediation.TriggerIf.UnhealthyLessThanOrEqualTo)...)
680680
}
@@ -687,7 +687,7 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust
687687
// Check if the machineHealthCheck is explicitly enabled in the machineDeploymentTopology.
688688
if md.HealthCheck.Enabled != nil && *md.HealthCheck.Enabled {
689689
// Ensure the MHC is defined in at least one of the MachineDeploymentTopology of the Cluster or the MachineDeploymentClass of the ClusterClass.
690-
if md.HealthCheck.IsDefined() && mdClass.HealthCheck == nil {
690+
if !md.HealthCheck.IsDefined() && mdClass.HealthCheck == nil {
691691
allErrs = append(allErrs, field.Forbidden(
692692
fldPath.Child("enable"),
693693
fmt.Sprintf("cannot be set to %t as MachineHealthCheck definition is not available in the Cluster topology or the ClusterClass", *md.HealthCheck.Enabled),

internal/webhooks/clusterclass.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func validateUpdatesToMachineHealthCheckClasses(clusters []clusterv1.Cluster, ol
194194
if cluster.Spec.Topology.ControlPlane.HealthCheck != nil &&
195195
cluster.Spec.Topology.ControlPlane.HealthCheck.Enabled != nil &&
196196
*cluster.Spec.Topology.ControlPlane.HealthCheck.Enabled &&
197-
cluster.Spec.Topology.ControlPlane.HealthCheck.IsDefined() {
197+
!cluster.Spec.Topology.ControlPlane.HealthCheck.IsDefined() {
198198
clustersUsingMHC = append(clustersUsingMHC, cluster.Name)
199199
}
200200
}
@@ -222,7 +222,7 @@ func validateUpdatesToMachineHealthCheckClasses(clusters []clusterv1.Cluster, ol
222222
if mdTopology.HealthCheck != nil &&
223223
mdTopology.HealthCheck.Enabled != nil &&
224224
*mdTopology.HealthCheck.Enabled &&
225-
mdTopology.HealthCheck.IsDefined() {
225+
!mdTopology.HealthCheck.IsDefined() {
226226
clustersUsingMHC = append(clustersUsingMHC, cluster.Name)
227227
break
228228
}

0 commit comments

Comments
 (0)