Skip to content

Commit fd0f4e2

Browse files
committed
Address some more review comments
Signed-off-by: Stefan Büringer [email protected]
1 parent 452b2c9 commit fd0f4e2

File tree

5 files changed

+66
-22
lines changed

5 files changed

+66
-22
lines changed

internal/controllers/machine/machine_controller.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ type Reconciler struct {
100100
// during a single reconciliation.
101101
nodeDeletionRetryTimeout time.Duration
102102
ssaCache ssa.Cache
103-
reconcileDeleteCache cache.Cache[cache.ReconcileEntry]
103+
104+
// reconcileDeleteCache is used to store when reconcileDelete should not be executed before a
105+
// specific time for a specific Request. This is used to implement rate-limiting to avoid
106+
// e.g. spamming workload clusters with eviction requests during Node drain.
107+
reconcileDeleteCache cache.Cache[cache.ReconcileEntry]
104108
}
105109

106110
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {

internal/controllers/machine/machine_controller_status.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ func setReadyCondition(ctx context.Context, machine *clusterv1.Machine) {
536536
log := ctrl.LoggerFrom(ctx)
537537

538538
forConditionTypes := v1beta2conditions.ForConditionTypes{
539-
// MachineDeletingV1Beta2Condition is added via AdditionalConditions if DeletionTimestamp is set.
539+
clusterv1.MachineDeletingV1Beta2Condition,
540540
clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
541541
clusterv1.MachineInfrastructureReadyV1Beta2Condition,
542542
clusterv1.MachineNodeHealthyV1Beta2Condition,
@@ -564,7 +564,7 @@ func setReadyCondition(ctx context.Context, machine *clusterv1.Machine) {
564564
}
565565

566566
if !machine.DeletionTimestamp.IsZero() {
567-
summaryOpts = append(summaryOpts, v1beta2conditions.AdditionalConditions{calculateDeletingConditionForSummary(machine)})
567+
summaryOpts = append(summaryOpts, v1beta2conditions.OverrideConditions{calculateDeletingConditionForSummary(machine)})
568568
}
569569

570570
readyCondition, err := v1beta2conditions.NewSummaryCondition(machine, clusterv1.MachineReadyV1Beta2Condition, summaryOpts...)
@@ -586,6 +586,11 @@ func setReadyCondition(ctx context.Context, machine *clusterv1.Machine) {
586586
// calculateDeletingConditionForSummary calculates a Deleting condition for the calculation of the Ready condition
587587
// (which is done via a summary). This is necessary to avoid including the verbose details of the Deleting condition
588588
// message in the summary.
589+
// This is important to ensure we have a limited amount of unique messages across Machines. This allows us to deduplicate
590+
// messages when aggregating Ready conditions of many Machines into the MachinesReady condition of e.g. the MachineSet.
591+
// For the same reason we are only surfacing messages with "more than 30m" instead of using the exact durations.
592+
// We assume that 30m is a duration after which it makes sense to notify users that Node drains and waiting for volume
593+
// detach are still in progress.
589594
func calculateDeletingConditionForSummary(machine *clusterv1.Machine) v1beta2conditions.ConditionWithOwnerInfo {
590595
deletingCondition := v1beta2conditions.Get(machine, clusterv1.MachineDeletingV1Beta2Condition)
591596

util/conditions/v1beta2/options.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func (t IgnoreTypesIfMissing) ApplyToSummary(opts *SummaryOptions) {
7979
opts.ignoreTypesIfMissing = t
8080
}
8181

82-
// AdditionalConditions allows to add additional conditions that should be used in the summary.
83-
type AdditionalConditions []ConditionWithOwnerInfo
82+
// OverrideConditions allows to override conditions from the source object that should be used in the summary.
83+
type OverrideConditions []ConditionWithOwnerInfo
8484

8585
// ApplyToSummary applies this configuration to the given summary options.
86-
func (t AdditionalConditions) ApplyToSummary(opts *SummaryOptions) {
87-
opts.additionalConditions = t
86+
func (t OverrideConditions) ApplyToSummary(opts *SummaryOptions) {
87+
opts.overrideConditions = t
8888
}
8989

9090
// CustomMergeStrategy allows to define a custom merge strategy when creating new summary or aggregate conditions.

util/conditions/v1beta2/summary.go

+23-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type SummaryOptions struct {
3636
conditionTypes []string
3737
negativePolarityConditionTypes []string
3838
ignoreTypesIfMissing []string
39-
additionalConditions []ConditionWithOwnerInfo
39+
overrideConditions []ConditionWithOwnerInfo
4040
}
4141

4242
// ApplyOptions applies the given list options on these options,
@@ -74,23 +74,36 @@ func NewSummaryCondition(sourceObj Getter, targetConditionType string, opts ...S
7474
expectedConditionTypes := sets.New[string](summarizeOpt.conditionTypes...)
7575
ignoreTypesIfMissing := sets.New[string](summarizeOpt.ignoreTypesIfMissing...)
7676
existingConditionTypes := sets.New[string]()
77-
allConditionTypes := summarizeOpt.conditionTypes
7877

79-
// Drops all the conditions not in scope for the merge operation
8078
conditions := getConditionsWithOwnerInfo(sourceObj)
79+
80+
conditionsByType := map[string]ConditionWithOwnerInfo{}
81+
for _, c := range conditions {
82+
conditionsByType[c.Type] = c
83+
}
84+
overrideConditionsByType := map[string]ConditionWithOwnerInfo{}
85+
for _, c := range summarizeOpt.overrideConditions {
86+
overrideConditionsByType[c.Type] = c
87+
88+
if _, ok := conditionsByType[c.Type]; !ok {
89+
return nil, errors.Errorf("override condition %s must exist in source object", c.Type)
90+
}
91+
}
92+
8193
conditionsInScope := make([]ConditionWithOwnerInfo, 0, len(expectedConditionTypes))
8294
for _, condition := range conditions {
95+
// Drops all the conditions not in scope for the merge operation
8396
if !expectedConditionTypes.Has(condition.Type) {
8497
continue
8598
}
86-
conditionsInScope = append(conditionsInScope, condition)
87-
existingConditionTypes.Insert(condition.Type)
88-
}
8999

90-
for _, condition := range summarizeOpt.additionalConditions {
91-
conditionsInScope = append(conditionsInScope, condition)
100+
if overrideCondition, ok := overrideConditionsByType[condition.Type]; ok {
101+
conditionsInScope = append(conditionsInScope, overrideCondition)
102+
} else {
103+
conditionsInScope = append(conditionsInScope, condition)
104+
}
105+
92106
existingConditionTypes.Insert(condition.Type)
93-
allConditionTypes = append(allConditionTypes, condition.Type)
94107
}
95108

96109
// Add the expected conditions which do not exist, so we are compliant with K8s guidelines
@@ -118,7 +131,7 @@ func NewSummaryCondition(sourceObj Getter, targetConditionType string, opts ...S
118131
return nil, errors.New("summary can't be performed when the list of conditions to be summarized is empty")
119132
}
120133

121-
status, reason, message, err := summarizeOpt.mergeStrategy.Merge(conditionsInScope, allConditionTypes)
134+
status, reason, message, err := summarizeOpt.mergeStrategy.Merge(conditionsInScope, summarizeOpt.conditionTypes)
122135
if err != nil {
123136
return nil, err
124137
}

util/conditions/v1beta2/summary_test.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestSummary(t *testing.T) {
3434
conditionType string
3535
options []SummaryOption
3636
want *metav1.Condition
37+
wantErr bool
3738
}{
3839
{
3940
name: "One issue",
@@ -210,14 +211,14 @@ func TestSummary(t *testing.T) {
210211
},
211212
},
212213
{
213-
name: "Include additional condition",
214+
name: "Override condition",
214215
conditions: []metav1.Condition{
215216
{Type: "A", Status: metav1.ConditionTrue, Reason: "Reason-A", Message: "Message-A"}, // info
216217
{Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C", Message: "Message-C"}, // issue
217218
},
218219
conditionType: clusterv1.AvailableV1Beta2Condition,
219-
options: []SummaryOption{ForConditionTypes{"A"}, NegativePolarityConditionTypes{"!C"}, IgnoreTypesIfMissing{"!C"},
220-
AdditionalConditions{
220+
options: []SummaryOption{ForConditionTypes{"A", "!C"}, NegativePolarityConditionTypes{"!C"}, IgnoreTypesIfMissing{"!C"},
221+
OverrideConditions{
221222
{
222223
OwnerResource: ConditionOwnerInfo{
223224
Kind: "Phase3Obj",
@@ -227,14 +228,35 @@ func TestSummary(t *testing.T) {
227228
Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C-additional", Message: "Message-C-additional", // issue
228229
},
229230
},
230-
}}, // AdditionalCondition replaces the same condition from the SourceObject
231+
}}, // OverrideCondition replaces the same condition from the SourceObject
231232
want: &metav1.Condition{
232233
Type: clusterv1.AvailableV1Beta2Condition,
233234
Status: metav1.ConditionFalse, // False because !C is an issue
234235
Reason: "Reason-C-additional", // Picking the reason from the additional condition
235236
Message: "!C: Message-C-additional", // Picking the message from the additional condition (info dropped)
236237
},
237238
},
239+
{
240+
name: "Error if override condition does not exist in source object",
241+
conditions: []metav1.Condition{
242+
{Type: "A", Status: metav1.ConditionTrue, Reason: "Reason-A", Message: "Message-A"}, // info
243+
// !C is missing in source object
244+
},
245+
conditionType: clusterv1.AvailableV1Beta2Condition,
246+
options: []SummaryOption{ForConditionTypes{"A", "!C"}, NegativePolarityConditionTypes{"!C"}, IgnoreTypesIfMissing{"!C"},
247+
OverrideConditions{
248+
{
249+
OwnerResource: ConditionOwnerInfo{
250+
Kind: "Phase3Obj",
251+
Name: "SourceObject",
252+
},
253+
Condition: metav1.Condition{
254+
Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C-additional", Message: "Message-C-additional", // issue
255+
},
256+
},
257+
}},
258+
wantErr: true,
259+
},
238260
}
239261

240262
for _, tt := range tests {
@@ -252,7 +274,7 @@ func TestSummary(t *testing.T) {
252274
}
253275

254276
got, err := NewSummaryCondition(obj, tt.conditionType, tt.options...)
255-
g.Expect(err).ToNot(HaveOccurred())
277+
g.Expect(err != nil).To(Equal(tt.wantErr))
256278

257279
g.Expect(got).To(Equal(tt.want))
258280
})

0 commit comments

Comments
 (0)