Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only reset consolidation time if an attempt was made #232

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/controllers/deprovisioning/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (c *Controller) Builder(_ context.Context, m manager.Manager) controller.Bu

func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) {
// Attempt different deprovisioning methods. We'll only let one method perform an action
isConsolidated := c.cluster.Consolidated()
for _, d := range c.deprovisioners {
candidates, err := candidateNodes(ctx, c.cluster, c.kubeClient, c.clock, c.cloudProvider, d.ShouldDeprovision)
if err != nil {
Expand Down Expand Up @@ -135,8 +136,11 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
return reconcile.Result{Requeue: true}, nil
}

if !isConsolidated {
// Mark cluster as consolidated, only if the deprovisioners ran and were not able to perform any work.
c.cluster.SetConsolidated(true)
}
// All deprovisioners did nothing, so return nothing to do
c.cluster.SetConsolidated(true) // Mark cluster as consolidated
return reconcile.Result{RequeueAfter: pollingPeriod}, nil
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/controllers/deprovisioning/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ var _ = AfterEach(func() {
}
})

var _ = Describe("Consolidation State", func() {
It("should not reset consolidation state if consolidation hasn't run", func() {
// this assumes that the consolidate reset period is 5 minutes, which it is currently
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
Expect(cluster.Consolidated()).To(BeTrue())
fakeClock.Step(1 * time.Minute)
Expect(cluster.Consolidated()).To(BeTrue())

// reconciling now shouldn't set the last consolidated time to current time, as consolidation isn't actually
// running since it last ran 1 minute ago
_, err = deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
// but advancing the clock 4:30, so we are at 5:30 past the last run time should cause consolidated to return
// false
fakeClock.Step(4*time.Minute + 30*time.Second)
Expect(cluster.Consolidated()).To(BeFalse())
})
})

var _ = Describe("Pod Eviction Cost", func() {
const standardPodCost = 1.0
It("should have a standard disruptionCost for a pod with no priority or disruptionCost specified", func() {
Expand Down