-
Notifications
You must be signed in to change notification settings - Fork 47
Override memory limits of rook operator to 512Mi #938
Conversation
|
a6ac636
to
58bcbf7
Compare
58bcbf7
to
fe336ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
return deploy | ||
} | ||
|
||
// nolint:funlen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// nolint:funlen | |
//nolint:funlen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A space after comment makes it more readable. Also this is consistent with other comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johananl is right: https://golangci-lint.run/usage/false-positives/.
Also:
0 ✓ (78.1ms) 13:55:01 invidian@dellxps15mateusz ~/repos/kinvolk/lokomotive (invidian/unused-code)$ git grep '//nolint' | wc -l
27
0 ✓ (115ms) 13:55:03 invidian@dellxps15mateusz ~/repos/kinvolk/lokomotive (invidian/unused-code)$ git grep '// nolint' | wc -l
26
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Comments with space after //
$ grep '// ' | wc -l
127153
# Comments without space after //
$ grep '//' | grep -v '// ' | wc -l
16671
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but IMO the rule does not apply, as nolint
is a meta comment. Regular comments should have the space for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my suggestion is strictly (!) for nolint
comments. This seems to be the prevailing standard. I don't care too much which one we do as long as we're consistent.
fe336ff
to
032acfe
Compare
tc := tc | ||
t.Run(tc.Name, func(t *testing.T) { | ||
t.Parallel() | ||
tc.Test(t, m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After seeing @johananl comments and looking at this code, This indeed doesn't seem to make sense to define those tests in the array?
You could just have a helper function returning deploy
and m
and have separate test cases with proper names.
That would be simpler case if there is no logic shared between the tests at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong in defining them in an array? Which test cases has "improper" names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's just too complex for no reason and inconsistent with other tests we have written. We could write all tests we have this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this way of writing code is more readable because you can look at the array and understand what is going on. All the boilerplate can be ignored for a reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think table-driven tests (tests cases in a slice) are a very good practice in Go. They are also recommended officially and unofficially. Besides being easy to read and maintain, defining all the test-case-specific data in a declarative data structure forces you to think about your tests cases in a more structured - and generic - way.
What I think doesn't make sense is to declare a function in every test case. This indeed bloats the test case data structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree table-driven tests are good, but if they share common test logic, which is not the case here, as we only share preparation logic and we define testing function in a table... All examples you linked @johananl actally share the test logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point was that perhaps we can structure the tests so that they have a shared logic. I didn't try to refactor the tests myself and don't want to halt the merging for this, just something for @surajssd to think about in case there is an obvious way to improve how we're doing things here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the code to be in different functions which resue the boilterplate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts, but nothing really blocking.
} | ||
} | ||
|
||
func memoryResources(t *testing.T, m map[string]string, deploy *appsv1.Deployment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I'd prefer to have isolated tests with common helper rather than a dispatcher test, I think it is simpler while not adding much of a boilerplate. This make setup part of the test obvious/explicit.
func memoryResources(t *testing.T, m map[string]string, deploy *appsv1.Deployment) { | |
func TestMemoryResources(t *testing.T, m map[string]string, deploy *appsv1.Deployment) { | |
m, deploy := manifestsAndDeployment(t) |
` | ||
|
||
m := renderManifests(t, configHCL) | ||
if len(m) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With such code, this condition should be put in separate test IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I put it in a separate function, how do I stop when such an error is encountered? If this fails as in len(m)
is zero then this test will fail on error: Operator deployment config not found
.
So catching this before we proceed further makes sense and gives up precise error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, I this sort of make sense. But other tests will fail gracefully if we remove this condition and we assume all rendering fails? I wonder how this should be handled in Go 🤔 I guess it's fine then 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way the tests are currently structured, rendering the manifest is not the actual check in the unit test but rather a preliminary step. What @invidian is talking about sounds like treating a zero-length manifest as a test case on its own (which is valid, but possibly a different "category" than the tests in this function).
21e761c
to
8a1baa6
Compare
8a1baa6
to
bc4d404
Compare
ee913b8
to
109a3f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can keep iterating on the tests but the current state is obviously better than current master
and I don't see a good reason to delay merging further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can keep iterating on the tests but the current state is obviously better than current master and I don't see a good reason to delay merging further.
I'm a bit concerned about introducing the dispatcher pattern as it may be then copied in the future and become a habit and I disagree that this is the right way to write unit tests in Go. But I'm also fine with merging.
I think I have an alternative proposal to the current test structure. I'm still typing it but if you want to wait a bit I can push it somewhere. |
Add a memory limit override, by increasing it to 512Mi. Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
Add unit tests that verify if the conversion worked correctly. Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
109a3f3
to
c422331
Compare
Fixes: #932