Skip to content

libnet: pass store as an arg to netdrivers#49158

Merged
thaJeztah merged 1 commit intomoby:masterfrom
akerouanton:netdrivers-store-param
Dec 20, 2024
Merged

libnet: pass store as an arg to netdrivers#49158
thaJeztah merged 1 commit intomoby:masterfrom
akerouanton:netdrivers-store-param

Conversation

@akerouanton
Copy link
Copy Markdown
Member

- What I did

Before that change, we were passing the datastore to network drivers through a map[string]interface{}. Then, each driver that needed the store would cast the datastore to the correct type.

This was not a good design, as it was not clear which drivers were using the store and which were not. Not all unit tests were passing the store, leading to logs about uninitialized store being written.

This change makes the store a parameter of the RegisterX functions. All unit tests are now passing a valid datastore to the drivers. A new testutil func is added for that purpose.

- How to verify it

Existing unit tests.

@akerouanton akerouanton added this to the 28.0.0 milestone Dec 20, 2024
@akerouanton akerouanton self-assigned this Dec 20, 2024
@akerouanton akerouanton force-pushed the netdrivers-store-param branch 2 times, most recently from 024499e to 82bc688 Compare December 20, 2024 14:52
@thaJeztah
Copy link
Copy Markdown
Member

Hm.. would love to have some eyes from @corhere on this PR; wasn't there a discussion as well to get rid of the datastore (so some of the "pass through config" to be by design to move away from it?

Also wondering; does this interface change of the Register functions break things elsewhere? (I recall some things also being present in the swarm kit repository, and plugins, but have to dig in memory on some of that).

it was not clear which drivers were using the store and which were not.

Curious; I see all Register functions in this PR to accept a store; what are the drivers that do not accept / use a store? (Or are some of these not using the store, and should have a _ to indicate that?)

@akerouanton
Copy link
Copy Markdown
Member Author

wasn't there a discussion as well to get rid of the datastore (so some of the "pass through config" to be by design to move away from it?

I think what you're referring to is what commit d21d088 did. Before that commit, we were passing the datastore config to every stateful driver, and then each would initialize their own instance of the datastore. Since the same config was passed, they were all racing for the same file lock -- with a default timeout of 1 minute. That timeout was removed in 4d7c11c.

I recall we discussed removing datastore from netdrivers during a networking sync call, but that was mostly a random thought. Maybe we'll do that some day, but we still need to figure out how persistence should be done, how to manage concurrency, etc… It's not a priority, and not something that will happen some time soon IMO.

Also wondering; does this interface change of the Register functions break things elsewhere? (I recall some things also being present in the swarm kit repository, and plugins, but have to dig in memory on some of that).
I see all Register functions in this PR to accept a store; what are the drivers that do not accept / use a store?

All the Register functions touched in this PR are for drivers that locally persist data. The overlay driver is left untouched as it uses the networkdb for persistence, and both host and null drivers are left touched too because they're stateless.

For Swarmkit integration, we've synthetic drivers that get registered here. These are left untouched too -- so nothing should break in Swarmkit.

Copy link
Copy Markdown
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

Comment thread internal/testutils/storeutils/store.go Outdated
Comment on lines +17 to +25
tempDir, err := os.MkdirTemp("", "*")
assert.NilError(t, err)

ds, err := datastore.New(tempDir, "libnetwork")
assert.NilError(t, err)

t.Cleanup(func() {
assert.NilError(t, os.RemoveAll(tempDir))
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
tempDir, err := os.MkdirTemp("", "*")
assert.NilError(t, err)
ds, err := datastore.New(tempDir, "libnetwork")
assert.NilError(t, err)
t.Cleanup(func() {
assert.NilError(t, os.RemoveAll(tempDir))
})
ds, err := datastore.New(t.TempDir(), "libnetwork")
assert.NilError(t, err)

Copy link
Copy Markdown
Member Author

@akerouanton akerouanton Dec 20, 2024

Choose a reason for hiding this comment

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

TempDir returns the default directory to use for temporary files.

If we do that, all tests are going to use the same boltdb file. This could result in weird test failures, and this would prevent parallel execution.

I think many tests can't be parallelized currently because they share the same netns but let's not make it worse 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Forget what I said, I thought you were suggesting os.TempDir() 🙈 I'll do that change!

@thaJeztah
Copy link
Copy Markdown
Member

Thanks both!! Sorry for the noise on my side; I wanted to be sure we were not undoing work that was set in progress ❤️

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

(pending the conversation above on t.TempDir(), which I'm "+1'" on)

Before that change, we were passing the datastore to network drivers
through a `map[string]interface{}`. Then, each driver that needed the
store would cast the datastore to the correct type.

This was not a good design, as it was not clear which drivers were using
the store and which were not. Not all unit tests were passing the store,
leading to logs about uninitialized store being written.

This change makes the store a parameter of the `RegisterX` functions.
All unit tests are now passing a valid datastore to the drivers. A new
testutil func is added for that purpose.

Signed-off-by: Albin Kerouanton <[email protected]>
@akerouanton akerouanton force-pushed the netdrivers-store-param branch from 82bc688 to e5bf6d8 Compare December 20, 2024 16:51
@thaJeztah thaJeztah merged commit b5d5fef into moby:master Dec 20, 2024
@akerouanton akerouanton deleted the netdrivers-store-param branch December 20, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants