Skip to content

Fix raft of issues related to network listing#3508

Merged
AkihiroSuda merged 2 commits intocontainerd:mainfrom
apostasie:chore-clean-network-walker
Oct 7, 2024
Merged

Fix raft of issues related to network listing#3508
AkihiroSuda merged 2 commits intocontainerd:mainfrom
apostasie:chore-clean-network-walker

Conversation

@apostasie
Copy link
Copy Markdown
Contributor

@apostasie apostasie commented Oct 7, 2024

Fix a number of bugs, oddities, and diverging behavior compared with docker, involving network ls, remove, create.

Notably:

And possibly others.

First commit is code, second commit is tests.

This is a small PR (besides tests).

Note that this is not a silver bullet for racyness / concurrency issues - a more indepth rewrite of netutil is required.

Comment thread pkg/netutil/netutil.go

// ParseMTU parses the mtu option
func ParseMTU(mtu string) (int, error) {
func parseMTU(mtu string) (int, error) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No reason for this to be public.

Comment thread pkg/netutil/netutil.go
}
}
id, labels := nerdctlIDLabels(lcl.Bytes)
id, lbls := nerdctlIDLabels(lcl.Bytes)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do not shadow imports.

Comment thread pkg/netutil/netutil.go

func (e *CNIEnv) CreateNetwork(opts types.NetworkCreateOptions) (*NetworkConfig, error) { //nolint:revive
var net *NetworkConfig
var netConf *NetworkConfig
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do not shadow imports.

Comment thread pkg/netutil/netutil.go
}

func (e *CNIEnv) FilterNetworks(filterf func(*NetworkConfig) bool) ([]*NetworkConfig, error) {
func (e *CNIEnv) filterNetworks(filterf func(*NetworkConfig) bool) ([]*NetworkConfig, error) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No reason for this to be public.

Comment thread pkg/netutil/netutil.go
if err != nil {
return nil, err
}
for _, net := range networkConfigs {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do not shadow imports.

Comment thread pkg/netutil/netutil.go
log.L.Warnf("duplicate network name %q, %#v will get superseded by %#v", n.Name, original, n)
}
m[n.Name] = n
if n.NerdctlID != nil {
Copy link
Copy Markdown
Contributor Author

@apostasie apostasie Oct 7, 2024

Choose a reason for hiding this comment

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

No reason for this. This is just encouraging collisions of unrelated namespaces (names and ids).

Comment thread pkg/netutil/netutil.go

type CNIEnvOpt func(e *CNIEnv) error

func (e *CNIEnv) ListNetworksMatch(reqs []string, allowPseudoNetwork bool) (list map[string][]*NetworkConfig, errs []error) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaces walker.

@apostasie apostasie force-pushed the chore-clean-network-walker branch from 1943696 to c8bb50d Compare October 7, 2024 00:51
limitations under the License.
*/

package netwalker
Copy link
Copy Markdown
Contributor Author

@apostasie apostasie Oct 7, 2024

Choose a reason for hiding this comment

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

As exposed in the ticket about walkers, this pattern is introducing complexity with no clear upside.

Furthermore, for the specific case here of network, it is buggy.

Removing entirely and replacing with a simpler, shorter method in netutil.

@apostasie apostasie force-pushed the chore-clean-network-walker branch from c8bb50d to dc640e4 Compare October 7, 2024 01:06
@apostasie apostasie changed the title [WIP] fix network raft basic issues [WIP] fix raft of issues related to network listing Oct 7, 2024
Comment thread pkg/netutil/netutil.go
return err
}
net, err = e.generateNetworkConfig(opts.Name, opts.Labels, plugins)
netConf, err = e.generateNetworkConfig(opts.Name, opts.Labels, plugins)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do not shadow imports.

@apostasie apostasie force-pushed the chore-clean-network-walker branch 2 times, most recently from 94ca981 to 5e9762c Compare October 7, 2024 02:05
Current implementation of netwalker (henceforth network inspect and remove) suffers from many
issues, rooting from mixing names and identifiers in the same namespace, faulty erroring logic,
and overly complicated design making debugging and reasonning harder.

This commit removes the walker and replaces it with a simpler approach.
Next commit will add tests.

Signed-off-by: apostasie <spam_blackhole@farcloser.world>
@apostasie apostasie force-pushed the chore-clean-network-walker branch from 5e9762c to 725482c Compare October 7, 2024 02:10
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
@apostasie apostasie force-pushed the chore-clean-network-walker branch from 725482c to 1fe34f8 Compare October 7, 2024 02:37
@apostasie apostasie changed the title [WIP] fix raft of issues related to network listing Fix raft of issues related to network listing Oct 7, 2024
@apostasie apostasie marked this pull request as ready for review October 7, 2024 03:06
@apostasie
Copy link
Copy Markdown
Contributor Author

@AkihiroSuda this is ready to go.
Not a particularly elegant PR tbh, but it does fix issues and will hopefully unblock #3492.

@apostasie apostasie mentioned this pull request Oct 7, 2024
@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Oct 7, 2024
{
Description: "invalid name network",
Command: test.RunCommand("network", "inspect", "∞"),
// FIXME: this is not even a valid identifier
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason to avoid ASCII here,?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really (I just routinely use non-ascii when testing "wrong things" as it tends to wreak more havoc / uncover issues).

If you prefer ASCII, that is fine with me, as long as the identifier is not "valid".

Copy link
Copy Markdown
Contributor Author

@apostasie apostasie Oct 7, 2024

Choose a reason for hiding this comment

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

The problem here (and the reason for the FIXME) is that identifiers should be validated before looking up the network.

Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit e8ae137 into containerd:main Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants