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

Fix: Deleting multiple networks stops at first delete fail #1618

Merged
merged 1 commit into from Dec 9, 2022

Conversation

yzxiu
Copy link
Contributor

@yzxiu yzxiu commented Dec 7, 2022

fixing #1587

 ~ nerdctl network create deleteme --gateway 10.10.11.1 --subnet 10.10.11.0/24

f9d6cec6deabf54691804bb7c1bf02ad7f461ab07f31a18398495b9de1cabf28

 ~ nerdctl  network ls                                                         
NETWORK ID      NAME               FILE
                k8s-pod-network    /etc/cni/net.d/10-calico.conflist
17f29b073143    bridge             /etc/cni/net.d/nerdctl-bridge.conflist
f9d6cec6deab    deleteme           /etc/cni/net.d/nerdctl-deleteme.conflist
                host               
                none

 ~ nerdctl network rm host k8s-pod-network test deleteme
ERRO[0000] pseudo network "host" cannot be removed      
ERRO[0000] k8s-pod-network is managed outside nerdctl and cannot be removed 
ERRO[0000] No such network: test                        
f9d6cec6deab

Signed-off-by: yaozhenxiu 946666800@qq.com

@yzxiu
Copy link
Contributor Author

yzxiu commented Dec 7, 2022

@fahedouch see #1592

} else if n == 0 {
return fmt.Errorf("no such network %s", name)
fmt.Fprintf(cmd.OutOrStdout(), "Error: No such network: %s\n", name)
Copy link
Member

Choose a reason for hiding this comment

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

please use logrus.Error(err) or logrus.WithError(err).Errorf("failed to ... %s", var) to set the Error level for these logs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@AkihiroSuda
Copy link
Member

Please squash commits

@yzxiu
Copy link
Contributor Author

yzxiu commented Dec 8, 2022

Please squash commits

Done

@fahedouch fahedouch added this to the v1.1.0 milestone Dec 8, 2022
@@ -93,14 +94,17 @@ func networkRmAction(cmd *cobra.Command, args []string) error {

for _, name := range args {
if name == "host" || name == "none" {
return fmt.Errorf("pseudo network %q cannot be removed", name)
logrus.Errorf("pseudo network %q cannot be removed\n", name)
Copy link
Member

Choose a reason for hiding this comment

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

\n is useless ( it is not interpreted)

cmd/nerdctl/network_rm.go Outdated Show resolved Hide resolved
pkg/idutil/netwalker/netwalker.go Outdated Show resolved Hide resolved
@fahedouch
Copy link
Member

cc @yzxiu

    network_rm_linux_test.go:65: assertion failed: res.ExitCode is 0
--- FAIL: TestNetworkRemoveWhenLinkWithContainer (0.47s)

@AkihiroSuda AkihiroSuda modified the milestones: v1.1.0, v1.1.1 (tentative) Dec 9, 2022
@yzxiu yzxiu force-pushed the fix-rm-network branch 3 times, most recently from ae16016 to 7248cda Compare December 9, 2022 07:35
@yzxiu
Copy link
Contributor Author

yzxiu commented Dec 9, 2022

cc @yzxiu

    network_rm_linux_test.go:65: assertion failed: res.ExitCode is 0
--- FAIL: TestNetworkRemoveWhenLinkWithContainer (0.47s)

@fahedouch PTAL

cmd/nerdctl/network_rm.go Outdated Show resolved Hide resolved

// compatible with docker
if status != 0 {
return ExitCodeError{
Copy link
Member

Choose a reason for hiding this comment

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

return errors.New(..) is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ExitCodeError is to allow the program to exit with status code 1 without outputting an error message.

if return errors.New(..), will output redundant error lines, like

ERRO[0000] network "deleteme" is in use by container ["182ea93ddc15b187419a05cb10a4b8d3cdace1fc2b8592a10b345396ce91edc7"] 
FATA[0000] 

Copy link
Contributor Author

@yzxiu yzxiu Dec 9, 2022

Choose a reason for hiding this comment

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

There is no error message needs to be output here(err is always nil), but the program needs to exit with status 1, so use ExitCodeError

Copy link
Member

Choose a reason for hiding this comment

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

ok got the point, can we change status by code ( more explicit I guess) and error :nil is useless

Suggested change
return ExitCodeError{
return ExitCodeError{
exitCode: code,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok got the point, can we change status by code ( more explicit I guess) and error :nil is useless

Done

Copy link
Member

Choose a reason for hiding this comment

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

ExitCodeError is to allow the program to exit with status code 1 without outputting an error message.

if return errors.New(..), will output redundant error lines, like

ERRO[0000] network "deleteme" is in use by container ["182ea93ddc15b187419a05cb10a4b8d3cdace1fc2b8592a10b345396ce91edc7"] 
FATA[0000] 

Could you add that in the code comment?
Or just print warnings for errs[0]...errs[n-2] and return errs[n-1]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ExitCodeError is to allow the program to exit with status code 1 without outputting an error message.

Add that in the code comment, like this?

// compatible with docker
// ExitCodeError is to allow the program to exit with status code 1 without outputting an error message.
if code != 0 {
	return ExitCodeError{
		exitCode: code,
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ExitCodeError is to allow the program to exit with status code 1 without outputting an error message.
if return errors.New(..), will output redundant error lines, like

ERRO[0000] network "deleteme" is in use by container ["182ea93ddc15b187419a05cb10a4b8d3cdace1fc2b8592a10b345396ce91edc7"] 
FATA[0000] 

Could you add that in the code comment? Or just print warnings for errs[0]...errs[n-2] and return errs[n-1]?

return err will result in two different outputs, like ERRO[0000]... and FATA[0000]...

I think using ExitCodeError here is a better choice

Copy link
Member

Choose a reason for hiding this comment

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

Add that in the code comment, like this?

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add that in the code comment, like this?

Yes

Done

Copy link
Member

@fahedouch fahedouch left a comment

Choose a reason for hiding this comment

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

Thanks

Signed-off-by: yaozhenxiu <946666800@qq.com>
Copy link
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 4a71d00 into containerd:main Dec 9, 2022
@yzxiu yzxiu deleted the fix-rm-network branch December 9, 2022 20:00
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.

None yet

4 participants