Skip to content

Commit 375bac1

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

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

internal/controllers/machine/machine_controller_status.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/apimachinery/pkg/util/sets"
3030
"k8s.io/utils/ptr"
3131
ctrl "sigs.k8s.io/controller-runtime"
32+
"sigs.k8s.io/controller-runtime/pkg/client"
3233

3334
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3435
"sigs.k8s.io/cluster-api/controllers/clustercache"
@@ -73,8 +74,6 @@ func (r *Reconciler) reconcileStatus(ctx context.Context, s *scope) {
7374

7475
setAvailableCondition(ctx, s.machine)
7576

76-
// TODO: Update the Deleting condition.
77-
7877
setMachinePhaseAndLastUpdated(ctx, s.machine)
7978
}
8079

@@ -586,10 +585,10 @@ func setReadyCondition(ctx context.Context, machine *clusterv1.Machine) {
586585
// calculateDeletingConditionForSummary calculates a Deleting condition for the calculation of the Ready condition
587586
// (which is done via a summary). This is necessary to avoid including the verbose details of the Deleting condition
588587
// 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.
588+
// This is also important to ensure we have a limited amount of unique messages across Machines thus allowing to
589+
// nicely aggregate Ready conditions from many Machines into the MachinesReady condition of e.g. the MachineSet.
591590
// 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
591+
// 30 minutes is a duration after which we assume it makes sense to emphasize that Node drains and waiting for volume
593592
// detach are still in progress.
594593
func calculateDeletingConditionForSummary(machine *clusterv1.Machine) v1beta2conditions.ConditionWithOwnerInfo {
595594
deletingCondition := v1beta2conditions.Get(machine, clusterv1.MachineDeletingV1Beta2Condition)

util/conditions/v1beta2/options.go

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

82-
// OverrideConditions allows to override conditions from the source object that should be used in the summary.
82+
// OverrideConditions allows to override conditions read from the source object only for the scope of a summary operation.
83+
// The condition on the source object will preserve the original value.
8384
type OverrideConditions []ConditionWithOwnerInfo
8485

8586
// ApplyToSummary applies this configuration to the given summary options.

util/conditions/v1beta2/summary.go

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func NewSummaryCondition(sourceObj Getter, targetConditionType string, opts ...S
8383
}
8484
overrideConditionsByType := map[string]ConditionWithOwnerInfo{}
8585
for _, c := range summarizeOpt.overrideConditions {
86+
if _, ok := overrideConditionsByType[c.Type]; ok {
87+
return nil, errors.Errorf("override condition %s specified multiple times", c.Type)
88+
}
89+
8690
overrideConditionsByType[c.Type] = c
8791

8892
if _, ok := conditionsByType[c.Type]; !ok {

util/conditions/v1beta2/summary_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,36 @@ func TestSummary(t *testing.T) {
236236
Message: "!C: Message-C-additional", // Picking the message from the additional condition (info dropped)
237237
},
238238
},
239+
{
240+
name: "Error if the same override condition is specified multiple times",
241+
conditions: []metav1.Condition{
242+
{Type: "A", Status: metav1.ConditionTrue, Reason: "Reason-A", Message: "Message-A"}, // info
243+
{Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C", Message: "Message-C"}, // issue
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+
OwnerResource: ConditionOwnerInfo{
259+
Kind: "Phase3Obj",
260+
Name: "SourceObject",
261+
},
262+
Condition: metav1.Condition{
263+
Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C-additional", Message: "Message-C-additional", // issue
264+
},
265+
},
266+
}}, // OverrideCondition is specified multiple times
267+
wantErr: true,
268+
},
239269
{
240270
name: "Error if override condition does not exist in source object",
241271
conditions: []metav1.Condition{

0 commit comments

Comments
 (0)