Skip to content

Commit b45a492

Browse files
authored
also log the delta when lendingLimit is updated (#256)
1 parent cacf2c7 commit b45a492

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

internal/controller/appwrapper/slackcq_monitor.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (r *SlackClusterQueueMonitor) Reconcile(ctx context.Context, req ctrl.Reque
7878

7979
// enforce lending limits on 1st flavor of 1st resource group
8080
resources := cq.Spec.ResourceGroups[0].Flavors[0].Resources
81-
limitsChanged := false
81+
delta := map[v1.ResourceName]*resource.Quantity{}
8282
for i, quota := range resources {
8383
var lendingLimit *resource.Quantity
8484
if unschedulableQuantity := unschedulableQuantities[quota.Name]; unschedulableQuantity != nil {
@@ -89,19 +89,28 @@ func (r *SlackClusterQueueMonitor) Reconcile(ctx context.Context, req ctrl.Reque
8989
lendingLimit = resource.NewQuantity(0, resource.DecimalSI)
9090
}
9191
}
92-
if quota.LendingLimit == nil && lendingLimit != nil ||
93-
quota.LendingLimit != nil && lendingLimit == nil ||
94-
quota.LendingLimit != nil && lendingLimit != nil && quota.LendingLimit.Cmp(*lendingLimit) != 0 {
95-
limitsChanged = true
92+
if quota.LendingLimit == nil && lendingLimit != nil {
93+
delta[quota.Name] = ptr.To(quota.NominalQuota)
94+
delta[quota.Name].Sub(*lendingLimit)
95+
delta[quota.Name].Neg()
96+
resources[i].LendingLimit = lendingLimit
97+
} else if quota.LendingLimit != nil && lendingLimit == nil {
98+
delta[quota.Name] = ptr.To(quota.NominalQuota)
99+
delta[quota.Name].Sub(*quota.LendingLimit)
100+
resources[i].LendingLimit = lendingLimit
101+
} else if quota.LendingLimit != nil && lendingLimit != nil && quota.LendingLimit.Cmp(*lendingLimit) != 0 {
102+
delta[quota.Name] = ptr.To(*quota.LendingLimit)
103+
delta[quota.Name].Sub(*lendingLimit)
104+
delta[quota.Name].Neg()
96105
resources[i].LendingLimit = lendingLimit
97106
}
98107
}
99108

100109
// update lending limits
101-
if limitsChanged {
110+
if len(delta) > 0 {
102111
err := r.Update(ctx, cq)
103112
if err == nil {
104-
log.FromContext(ctx).Info("Updated lending limits", "Resources", resources)
113+
log.FromContext(ctx).Info("Updated lending limits", "Changed by", delta, "Updated Resources", resources)
105114
return ctrl.Result{}, nil
106115
} else if errors.IsConflict(err) {
107116
return ctrl.Result{Requeue: true}, nil

0 commit comments

Comments
 (0)