Skip to content

Commit 5ee7d25

Browse files
Address review comments
Signed-off-by: Furkat Gofurov <[email protected]>
1 parent c6a7148 commit 5ee7d25

File tree

20 files changed

+63
-195
lines changed

20 files changed

+63
-195
lines changed

api/core/v1beta1/conversion.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
7373
return err
7474
}
7575

76+
dst.Spec.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions = restored.Spec.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions
77+
for i, md := range restored.Spec.Topology.Workers.MachineDeployments {
78+
dst.Spec.Topology.Workers.MachineDeployments[i].HealthCheck.Checks.UnhealthyMachineConditions = md.HealthCheck.Checks.UnhealthyMachineConditions
79+
}
80+
7681
// Recover intent for bool values converted to *bool.
7782
clusterv1.Convert_bool_To_Pointer_bool(src.Spec.Paused, ok, restored.Spec.Paused, &dst.Spec.Paused)
7883

@@ -145,6 +150,11 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
145150
return err
146151
}
147152

153+
dst.Spec.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions = restored.Spec.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions
154+
for i, md := range restored.Spec.Workers.MachineDeployments {
155+
dst.Spec.Workers.MachineDeployments[i].HealthCheck.Checks.UnhealthyMachineConditions = md.HealthCheck.Checks.UnhealthyMachineConditions
156+
}
157+
148158
// Recover intent for bool values converted to *bool.
149159
for i, patch := range dst.Spec.Patches {
150160
for j, definition := range patch.Definitions {
@@ -513,6 +523,8 @@ func (src *MachineHealthCheck) ConvertTo(dstRaw conversion.Hub) error {
513523
return err
514524
}
515525

526+
dst.Spec.Checks.UnhealthyMachineConditions = restored.Spec.Checks.UnhealthyMachineConditions
527+
516528
clusterv1.Convert_int32_To_Pointer_int32(src.Status.ExpectedMachines, ok, restored.Status.ExpectedMachines, &dst.Status.ExpectedMachines)
517529
clusterv1.Convert_int32_To_Pointer_int32(src.Status.CurrentHealthy, ok, restored.Status.CurrentHealthy, &dst.Status.CurrentHealthy)
518530
clusterv1.Convert_int32_To_Pointer_int32(src.Status.RemediationsAllowed, ok, restored.Status.RemediationsAllowed, &dst.Status.RemediationsAllowed)

api/core/v1beta1/conversion_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func ClusterFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
9999
hubClusterVariable,
100100
hubFailureDomain,
101101
hubUnhealthyNodeCondition,
102-
hubUnhealthyMachineCondition,
103102
spokeCluster,
104103
spokeClusterTopology,
105104
spokeObjectReference,
@@ -127,17 +126,6 @@ func hubClusterSpec(in *clusterv1.ClusterSpec, c randfill.Continue) {
127126
in.ControlPlaneRef.APIGroup = gvk.Group
128127
in.ControlPlaneRef.Kind = gvk.Kind
129128
}
130-
131-
// remove MachineHealthCheck.UnhealthyMachineConditions as it does not exist in v1beta1.
132-
if in.Topology.IsDefined() && in.Topology.ControlPlane.HealthCheck.IsDefined() {
133-
in.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions = nil
134-
}
135-
136-
if in.Topology.IsDefined() && len(in.Topology.Workers.MachineDeployments) > 0 {
137-
for i := range in.Topology.Workers.MachineDeployments {
138-
in.Topology.Workers.MachineDeployments[i].HealthCheck.Checks.UnhealthyMachineConditions = nil
139-
}
140-
}
141129
}
142130

143131
func hubClusterStatus(in *clusterv1.ClusterStatus, c randfill.Continue) {
@@ -189,14 +177,6 @@ func hubUnhealthyNodeCondition(in *clusterv1.UnhealthyNodeCondition, c randfill.
189177
}
190178
}
191179

192-
func hubUnhealthyMachineCondition(in *clusterv1.UnhealthyMachineCondition, c randfill.Continue) {
193-
c.FillNoCustom(in)
194-
195-
if in.TimeoutSeconds == nil {
196-
in.TimeoutSeconds = ptr.To(int32(0)) // TimeoutSeconds is a required field and nil does not round trip
197-
}
198-
}
199-
200180
func spokeCluster(in *Cluster, c randfill.Continue) {
201181
c.FillNoCustom(in)
202182

@@ -287,14 +267,12 @@ func spokeClusterVariable(in *ClusterVariable, c randfill.Continue) {
287267

288268
func ClusterClassFuncs(_ runtimeserializer.CodecFactory) []interface{} {
289269
return []interface{}{
290-
hubClusterClassSpec,
291270
hubClusterClassVariable,
292271
hubClusterClassStatusVariableDefinition,
293272
hubClusterClassStatus,
294273
hubJSONPatch,
295274
hubJSONSchemaProps,
296275
hubUnhealthyNodeCondition,
297-
hubUnhealthyMachineCondition,
298276
spokeClusterClass,
299277
spokeObjectReference,
300278
spokeClusterClassStatus,
@@ -309,21 +287,6 @@ func ClusterClassFuncs(_ runtimeserializer.CodecFactory) []interface{} {
309287
}
310288
}
311289

312-
func hubClusterClassSpec(in *clusterv1.ClusterClassSpec, c randfill.Continue) {
313-
c.FillNoCustom(in)
314-
315-
// remove MachineHealthCheck.UnhealthyMachineConditions as it does not exist in v1beta1.
316-
if in.ControlPlane.HealthCheck.IsDefined() && in.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions != nil {
317-
in.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions = nil
318-
}
319-
320-
if len(in.Workers.MachineDeployments) > 0 {
321-
for i := range in.Workers.MachineDeployments {
322-
in.Workers.MachineDeployments[i].HealthCheck.Checks.UnhealthyMachineConditions = nil
323-
}
324-
}
325-
}
326-
327290
func hubClusterClassVariable(in *clusterv1.ClusterClassVariable, c randfill.Continue) {
328291
c.FillNoCustom(in)
329292

@@ -765,9 +728,7 @@ func spokeMachineDeploymentStatus(in *MachineDeploymentStatus, c randfill.Contin
765728
func MachineHealthCheckFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
766729
return []interface{}{
767730
hubUnhealthyNodeCondition,
768-
hubUnhealthyMachineCondition,
769731
hubMachineHealthCheckStatus,
770-
hubMachineHealthCheckSpec,
771732
spokeMachineHealthCheck,
772733
spokeMachineHealthCheckSpec,
773734
spokeObjectReference,
@@ -776,14 +737,6 @@ func MachineHealthCheckFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{}
776737
}
777738
}
778739

779-
func hubMachineHealthCheckSpec(in *clusterv1.MachineHealthCheckSpec, c randfill.Continue) {
780-
c.FillNoCustom(in)
781-
782-
if in.Checks.UnhealthyMachineConditions != nil {
783-
in.Checks.UnhealthyMachineConditions = nil
784-
}
785-
}
786-
787740
func hubMachineHealthCheckStatus(in *clusterv1.MachineHealthCheckStatus, c randfill.Continue) {
788741
c.FillNoCustom(in)
789742
// Drop empty structs with only omit empty fields.

api/core/v1beta2/machinehealthcheck_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ type UnhealthyNodeCondition struct {
237237

238238
// timeoutSeconds is the duration that a node must be in a given status for,
239239
// after which the node is considered unhealthy.
240-
// For example, with a value of "1h", the node must match the status
240+
// For example, with a value of "3600", the node must match the status
241241
// for at least 1 hour before being considered unhealthy.
242242
// +required
243243
// +kubebuilder:validation:Minimum=0
@@ -249,7 +249,7 @@ type UnhealthyNodeCondition struct {
249249
// status for at least the timeout value, a machine is considered unhealthy.
250250
type UnhealthyMachineCondition struct {
251251
// type of Machine condition
252-
// +kubebuilder:validation:Type=string
252+
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
253253
// +kubebuilder:validation:MinLength=1
254254
// +kubebuilder:validation:MaxLength=316
255255
// +required
@@ -262,7 +262,7 @@ type UnhealthyMachineCondition struct {
262262

263263
// timeoutSeconds is the duration that a machine must be in a given status for,
264264
// after which the machine is considered unhealthy.
265-
// For example, with a value of "1h", the machine must match the status
265+
// For example, with a value of "3600", the machine must match the status
266266
// for at least 1 hour before being considered unhealthy.
267267
// +required
268268
// +kubebuilder:validation:Minimum=0

api/core/v1beta2/zz_generated.openapi.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusters.yaml

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_machinehealthchecks.yaml

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/api/core/v1alpha3/conversion.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
9898
if err != nil {
9999
return err
100100
}
101+
// Recover unhealthyMachineConditions for control plane and machine deployments
102+
dst.Spec.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions = restored.Spec.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions
103+
for i, md := range restored.Spec.Topology.Workers.MachineDeployments {
104+
if i < len(dst.Spec.Topology.Workers.MachineDeployments) {
105+
dst.Spec.Topology.Workers.MachineDeployments[i].HealthCheck.Checks.UnhealthyMachineConditions = md.HealthCheck.Checks.UnhealthyMachineConditions
106+
}
107+
}
101108

102109
// Recover intent for bool values converted to *bool.
103110
clusterv1.Convert_bool_To_Pointer_bool(src.Spec.Paused, ok, restored.Spec.Paused, &dst.Spec.Paused)
@@ -503,6 +510,8 @@ func (src *MachineHealthCheck) ConvertTo(dstRaw conversion.Hub) error {
503510
return err
504511
}
505512

513+
dst.Spec.Checks.UnhealthyMachineConditions = restored.Spec.Checks.UnhealthyMachineConditions
514+
506515
clusterv1.Convert_int32_To_Pointer_int32(src.Status.ExpectedMachines, ok, restored.Status.ExpectedMachines, &dst.Status.ExpectedMachines)
507516
clusterv1.Convert_int32_To_Pointer_int32(src.Status.CurrentHealthy, ok, restored.Status.CurrentHealthy, &dst.Status.CurrentHealthy)
508517
clusterv1.Convert_int32_To_Pointer_int32(src.Status.RemediationsAllowed, ok, restored.Status.RemediationsAllowed, &dst.Status.RemediationsAllowed)

0 commit comments

Comments
 (0)