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

Stop scale down timer #70

Closed
wants to merge 2 commits into from
Closed

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Feb 6, 2024

See: #67

When a deployment is deleted on reconcile there may still be a scale down timer running that modifies k8s replica state later. With this PR, the timer is stopped.

pkg/deployments/scaler.go Outdated Show resolved Hide resolved
@@ -136,6 +141,79 @@ func TestAddDeployment(t *testing.T) {
}
}

func TestRemoveDeployment(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we write these tests utilizing as many of the exported methods as possible and written in a manner that follows expected usage. This allows the tests to be more flexible over time. One example: asserting on m.ResolveDeployment() as opposed to m.modelToDeployment. I also think this is a good case for not using table-driven tests. In this case a table driven design is really only reusing m.removeDeployment(req) across all of the tests but it becomes harder to read and covers less surface area per lines of test than a usage/story-driven approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I can see the benefit of using method rather than messing with internal state. I also agree that the assert function is not great and values should be stored in the test spec. I like table test as a spec for the method. But I am so used to writing them, that I have a hard time to think how this test would look like in a classic fashion. Would you split it into multiple separate tests or work with a single manager and add/ remove state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally like the table tests as well but I like to limit them to data only and not logic. I think as a follow up we need to have tests for scaler.go and refactor it before we can fix #67 which is imo the highest priority issue right now.

If we think these tests on internal state are no longer productive, then we can simply remove the tests later as well. The issue with testing using internal state is that it makes refactoring the implementation harder later.

@samos123
Copy link
Contributor

samos123 commented Feb 7, 2024

This won't fix #67 since in my case I never deleted a deployment yet still triggered the issue. So not sure if this patch is needed. That being said, I think this fix is helpful because otherwise the timers would just keep on going even after the scaler is deleted?

This was an interesting read: https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082

@samos123 samos123 self-requested a review February 7, 2024 04:40
@samos123
Copy link
Contributor

samos123 commented Feb 7, 2024

I will include this in #76

@samos123 samos123 closed this Feb 7, 2024
samos123 added a commit that referenced this pull request Feb 9, 2024
Fixes #73 and includes pr #70 and others from Alex

* Remove compareScales function
* Refactor SetDesiredScale that is simpler to understand by storing
lastSuccessfulScale time
* Improve test coverage for scaler.go

Co-authored-by: Alex Peters <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants