Skip to content

Commit 8c8a128

Browse files
committed
address review comments
1 parent 9de2461 commit 8c8a128

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

api/compute/v1alpha1/machine_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ const (
189189
// MachineConditionType is a type a MachineCondition can have.
190190
type MachineConditionType string
191191

192+
const (
193+
// MachineConditionReady indicates that the machine is ready.
194+
MachineConditionReady MachineConditionType = "MachineReady"
195+
// MachineConditionVolumesReady indicates that the volumes are ready.
196+
MachineConditionVolumesReady MachineConditionType = "VolumesReady"
197+
// MachineConditionNetworkInterfacesReady indicates that the network interfaces are ready.
198+
MachineConditionNetworkInterfacesReady MachineConditionType = "NetworkInterfacesReady"
199+
)
200+
192201
// MachineCondition is one of the conditions of a machine.
193202
type MachineCondition struct {
194203
// Type is the type of the condition.

poollet/machinepoollet/controllers/machine_controller.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"sort"
1011
"strconv"
1112

1213
"github.com/go-logr/logr"
@@ -552,7 +553,7 @@ func (r *MachineReconciler) computeMachineReadyCondition(state computev1alpha1.M
552553
}
553554

554555
return computev1alpha1.MachineCondition{
555-
Type: "MachineReady",
556+
Type: computev1alpha1.MachineConditionReady,
556557
Status: status,
557558
Reason: reason,
558559
Message: message,
@@ -585,9 +586,8 @@ func (r *MachineReconciler) computeVolumesReadyCondition(volumeStatuses []comput
585586

586587
if status == corev1.ConditionTrue {
587588
for _, vs := range volumeStatuses {
588-
if vs.LastStateTransitionTime != nil {
589+
if vs.LastStateTransitionTime != nil && (lastTransitionTime == nil || vs.LastStateTransitionTime.After(lastTransitionTime.Time)) {
589590
lastTransitionTime = vs.LastStateTransitionTime
590-
break
591591
}
592592
}
593593
}
@@ -598,7 +598,7 @@ func (r *MachineReconciler) computeVolumesReadyCondition(volumeStatuses []comput
598598
}
599599

600600
return computev1alpha1.MachineCondition{
601-
Type: computev1alpha1.MachineConditionType("VolumesReady"),
601+
Type: computev1alpha1.MachineConditionVolumesReady,
602602
Status: status,
603603
Reason: reason,
604604
Message: message,
@@ -627,9 +627,8 @@ func (r *MachineReconciler) computeNetworkInterfacesReadyCondition(nicStatuses [
627627

628628
if status == corev1.ConditionTrue {
629629
for _, nicStatus := range nicStatuses {
630-
if nicStatus.LastStateTransitionTime != nil {
630+
if nicStatus.LastStateTransitionTime != nil && (lastTransitionTime == nil || nicStatus.LastStateTransitionTime.After(lastTransitionTime.Time)) {
631631
lastTransitionTime = nicStatus.LastStateTransitionTime
632-
break
633632
}
634633
}
635634
}
@@ -640,7 +639,7 @@ func (r *MachineReconciler) computeNetworkInterfacesReadyCondition(nicStatuses [
640639
}
641640

642641
return computev1alpha1.MachineCondition{
643-
Type: computev1alpha1.MachineConditionType("NetworkInterfacesReady"),
642+
Type: computev1alpha1.MachineConditionNetworkInterfacesReady,
644643
Status: status,
645644
Reason: reason,
646645
Message: message,
@@ -667,7 +666,33 @@ func (r *MachineReconciler) mergeMachineConditions(
667666
}
668667
}
669668

670-
return updated
669+
// Group conditions by type and keep only the latest 10 per type (by LastTransitionTime)
670+
const maxConditionsPerType = 10
671+
conditionsByType := make(map[string][]computev1alpha1.MachineCondition)
672+
for _, cond := range updated {
673+
condType := string(cond.Type)
674+
conditionsByType[condType] = append(conditionsByType[condType], cond)
675+
}
676+
677+
var result []computev1alpha1.MachineCondition
678+
// Sort condition types for deterministic ordering
679+
types := make([]string, 0, len(conditionsByType))
680+
for t := range conditionsByType {
681+
types = append(types, t)
682+
}
683+
sort.Strings(types)
684+
for _, t := range types {
685+
conds := conditionsByType[t]
686+
sort.Slice(conds, func(i, j int) bool {
687+
return conds[i].LastTransitionTime.Before(&conds[j].LastTransitionTime)
688+
})
689+
if len(conds) > maxConditionsPerType {
690+
conds = conds[len(conds)-maxConditionsPerType:]
691+
}
692+
result = append(result, conds...)
693+
}
694+
695+
return result
671696
}
672697

673698
func (r *MachineReconciler) prepareIRIPower(power computev1alpha1.Power) (iri.Power, error) {
@@ -1019,7 +1044,7 @@ func (r *MachineReconciler) enqueueMachinesReferencingNetworkInterface() handler
10191044
},
10201045
r.matchingWatchLabel(),
10211046
); err != nil {
1022-
log.Error(err, "Error listing machines using network interface", "NetworkInterfaceKey", client.ObjectKeyFromObject(nic))
1047+
log.Error(err, "Error listing machines using secret", "NetworkInterfaceKey", client.ObjectKeyFromObject(nic))
10231048
return nil
10241049
}
10251050

0 commit comments

Comments
 (0)