Skip to content

Commit

Permalink
Merge pull request #660 from Junnplus/bridge-netif
Browse files Browse the repository at this point in the history
remove bridge network interface after network rm
  • Loading branch information
AkihiroSuda authored Jan 3, 2022
2 parents ed3d553 + 40824b9 commit 3cd3045
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/nerdctl/network_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func networkRmAction(cmd *cobra.Command, args []string) error {
if err := os.RemoveAll(l.File); err != nil {
return err
}
// Remove the bridge network interface on the host.
if l.Plugins[0].Network.Type == "bridge" {
netIf := fmt.Sprintf("nerdctl%d", *l.NerdctlID)
removeBridgeNetworkInterface(netIf)
}
fmt.Fprintln(cmd.OutOrStdout(), name)
}
return nil
Expand Down
19 changes: 19 additions & 0 deletions cmd/nerdctl/network_rm_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

func removeBridgeNetworkInterface(name string) {}
31 changes: 31 additions & 0 deletions cmd/nerdctl/network_rm_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)

func removeBridgeNetworkInterface(netIf string) {
link, err := netlink.LinkByName(netIf)
if err == nil {
if err = netlink.LinkDel(link); err != nil {
logrus.Warnf("Failed to remove network interface %s: %v", netIf, err)
}
}
}
19 changes: 19 additions & 0 deletions cmd/nerdctl/network_rm_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

func removeBridgeNetworkInterface(name string) {}

0 comments on commit 3cd3045

Please sign in to comment.