Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Override memory limits of rook operator to 512Mi #938

Merged
merged 2 commits into from
Sep 15, 2020

Conversation

surajssd
Copy link
Member

  • Add tests for rook-ceph

Fixes: #932

@johananl
Copy link
Member

make test is failing for me:

--- FAIL: TestConversion (0.16s)
    --- FAIL: TestConversion/EnvVars (0.00s)
        --- FAIL: TestConversion/EnvVars/CSI_PROVISIONER_NODE_AFFINITY (0.00s)
            component_test.go:198: expected value of env "CSI_PROVISIONER_NODE_AFFINITY":"storage_node_key1=storage_node_value1; storage_node_key2=storage_node_value2;", got "CSI_PROVISIONER_NODE_AFFINITY":"storage_node_key2=storage_node_value2; storage_node_key1=storage_node_value1;"
        --- FAIL: TestConversion/EnvVars/AGENT_NODE_AFFINITY (0.00s)
            component_test.go:198: expected value of env "AGENT_NODE_AFFINITY":"storage_node_key1=storage_node_value1; storage_node_key2=storage_node_value2;", got "AGENT_NODE_AFFINITY":"storage_node_key2=storage_node_value2; storage_node_key1=storage_node_value1;"
        --- FAIL: TestConversion/EnvVars/DISCOVER_AGENT_NODE_AFFINITY (0.00s)
            component_test.go:198: expected value of env "DISCOVER_AGENT_NODE_AFFINITY":"storage_node_key1=storage_node_value1; storage_node_key2=storage_node_value2;", got "DISCOVER_AGENT_NODE_AFFINITY":"storage_node_key2=storage_node_value2; storage_node_key1=storage_node_value1;"
FAIL
coverage: 77.4% of statements
FAIL    github.com/kinvolk/lokomotive/pkg/components/rook       0.267s

@surajssd surajssd force-pushed the surajssd/upgrade-memory-limits-rook branch from a6ac636 to 58bcbf7 Compare September 10, 2020 13:15
@surajssd
Copy link
Member Author

@johananl Thanks for catching that.

make test is failing for me:

I have filed an issue here: #942.

Also I have disabled the tests that have inconsistent output and are prone to fail randomly.

@surajssd surajssd force-pushed the surajssd/upgrade-memory-limits-rook branch from 58bcbf7 to fe336ff Compare September 10, 2020 14:55
invidian
invidian previously approved these changes Sep 10, 2020
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

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

OK

pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
return deploy
}

// nolint:funlen
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// nolint:funlen
//nolint:funlen

Copy link
Member Author

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.

Copy link
Member

@invidian invidian Sep 11, 2020

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

😄

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@johananl johananl Sep 11, 2020

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.

pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
pkg/components/rook/component_test.go Outdated Show resolved Hide resolved
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
tc.Test(t, m)
Copy link
Member

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.

Copy link
Member Author

@surajssd surajssd Sep 11, 2020

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@johananl johananl Sep 11, 2020

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@invidian invidian left a 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.

pkg/components/rook/component_conversion_test.go Outdated Show resolved Hide resolved
}
}

func memoryResources(t *testing.T, m map[string]string, deploy *appsv1.Deployment) {
Copy link
Member

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.

Suggested change
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 {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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 😄

Copy link
Member

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).

@surajssd surajssd force-pushed the surajssd/upgrade-memory-limits-rook branch from 21e761c to 8a1baa6 Compare September 14, 2020 11:03
@invidian
Copy link
Member

It seems this PR hit #940 many times :| And #952 simplifies modifying the timeouts.

@surajssd
Copy link
Member Author

It seems this PR hit #940 many times :| And #952 simplifies modifying the timeouts.

Yeah, I thought it was one off, but then my cluster that I created locally also timed out.

@surajssd surajssd force-pushed the surajssd/upgrade-memory-limits-rook branch from 8a1baa6 to bc4d404 Compare September 15, 2020 07:11
@surajssd surajssd force-pushed the surajssd/upgrade-memory-limits-rook branch 2 times, most recently from ee913b8 to 109a3f3 Compare September 15, 2020 07:30
johananl
johananl previously approved these changes Sep 15, 2020
Copy link
Member

@johananl johananl left a 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.

invidian
invidian previously approved these changes Sep 15, 2020
Copy link
Member

@invidian invidian left a 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.

@johananl
Copy link
Member

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.

@johananl
Copy link
Member

Pushed an example here: https://github.com/kinvolk/lokomotive/blob/39e3a898fa955e8493d8ffca187ca5736d6d1050/pkg/components/rook/component_conversion_test.go

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>
@surajssd surajssd dismissed stale reviews from invidian and johananl via c422331 September 15, 2020 11:22
@surajssd surajssd force-pushed the surajssd/upgrade-memory-limits-rook branch from 109a3f3 to c422331 Compare September 15, 2020 11:22
@surajssd surajssd merged commit 2e1ac51 into master Sep 15, 2020
@surajssd surajssd deleted the surajssd/upgrade-memory-limits-rook branch September 15, 2020 12:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increase the rook-ceph-operator memory limits
3 participants