Skip to content

Commit

Permalink
also log the delta when lendingLimit is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrove-oss committed Oct 16, 2024
1 parent cacf2c7 commit 98ad6e3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions internal/controller/appwrapper/slackcq_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *SlackClusterQueueMonitor) Reconcile(ctx context.Context, req ctrl.Reque

// enforce lending limits on 1st flavor of 1st resource group
resources := cq.Spec.ResourceGroups[0].Flavors[0].Resources
limitsChanged := false
delta := map[v1.ResourceName]*resource.Quantity{}
for i, quota := range resources {
var lendingLimit *resource.Quantity
if unschedulableQuantity := unschedulableQuantities[quota.Name]; unschedulableQuantity != nil {
Expand All @@ -89,19 +89,28 @@ func (r *SlackClusterQueueMonitor) Reconcile(ctx context.Context, req ctrl.Reque
lendingLimit = resource.NewQuantity(0, resource.DecimalSI)
}
}
if quota.LendingLimit == nil && lendingLimit != nil ||
quota.LendingLimit != nil && lendingLimit == nil ||
quota.LendingLimit != nil && lendingLimit != nil && quota.LendingLimit.Cmp(*lendingLimit) != 0 {
limitsChanged = true
if quota.LendingLimit == nil && lendingLimit != nil {
delta[quota.Name] = ptr.To(quota.NominalQuota)
delta[quota.Name].Sub(*lendingLimit)
delta[quota.Name].Neg()
resources[i].LendingLimit = lendingLimit
} else if quota.LendingLimit != nil && lendingLimit == nil {
delta[quota.Name] = ptr.To(quota.NominalQuota)
delta[quota.Name].Sub(*quota.LendingLimit)
resources[i].LendingLimit = lendingLimit
} else if quota.LendingLimit != nil && lendingLimit != nil && quota.LendingLimit.Cmp(*lendingLimit) != 0 {
delta[quota.Name] = ptr.To(*quota.LendingLimit)
delta[quota.Name].Sub(*lendingLimit)
delta[quota.Name].Neg()
resources[i].LendingLimit = lendingLimit
}
}

// update lending limits
if limitsChanged {
if len(delta) > 0 {
err := r.Update(ctx, cq)
if err == nil {
log.FromContext(ctx).Info("Updated lending limits", "Resources", resources)
log.FromContext(ctx).Info("Updated lending limits", "Changed by", delta, "Updated Resources", resources)
return ctrl.Result{}, nil
} else if errors.IsConflict(err) {
return ctrl.Result{Requeue: true}, nil
Expand Down

0 comments on commit 98ad6e3

Please sign in to comment.