autocomplete podman search --filter

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2022-05-24 10:35:36 +02:00
parent 8af98b342d
commit d924c46dae
35 changed files with 377 additions and 156 deletions

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package cni

View File

@@ -16,8 +16,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package cni

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package cni

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package cni
@@ -12,7 +12,6 @@ import (
pkgutil "github.com/containers/common/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)
// NetworkCreate will take a partial filled Network and fill the
@@ -133,14 +132,7 @@ func (n *cniNetwork) NetworkRemove(nameOrID string) error {
// Remove the bridge network interface on the host.
if network.libpodNet.Driver == types.BridgeNetworkDriver {
link, err := netlink.LinkByName(network.libpodNet.NetworkInterface)
if err == nil {
err = netlink.LinkDel(link)
// only log the error, it is not fatal
if err != nil {
logrus.Infof("Failed to remove network interface %s: %v", network.libpodNet.NetworkInterface, err)
}
}
deleteLink(network.libpodNet.NetworkInterface)
}
file := network.filename

View File

@@ -0,0 +1,17 @@
//go:build freebsd
// +build freebsd
package cni
import (
"os/exec"
"github.com/sirupsen/logrus"
)
func deleteLink(name string) {
if output, err := exec.Command("ifconfig", name, "destroy").CombinedOutput(); err != nil {
// only log the error, it is not fatal
logrus.Infof("Failed to remove network interface %s: %v: %s", name, err, output)
}
}

View File

@@ -0,0 +1,20 @@
//go:build linux
// +build linux
package cni
import (
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)
func deleteLink(name string) {
link, err := netlink.LinkByName(name)
if err == nil {
err = netlink.LinkDel(link)
// only log the error, it is not fatal
if err != nil {
logrus.Infof("Failed to remove network interface %s: %v", name, err)
}
}
}

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package cni

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package cni
@@ -12,13 +12,11 @@ import (
"github.com/containernetworking/cni/libcni"
cnitypes "github.com/containernetworking/cni/pkg/types"
types040 "github.com/containernetworking/cni/pkg/types/040"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containers/common/libnetwork/internal/util"
"github.com/containers/common/libnetwork/types"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)
// Setup will setup the container network namespace. It returns
@@ -36,14 +34,7 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
return nil, err
}
// set the loopback adapter up in the container netns
err = ns.WithNetNSPath(namespacePath, func(_ ns.NetNS) error {
link, err := netlink.LinkByName("lo")
if err == nil {
err = netlink.LinkSetUp(link)
}
return err
})
err = setupLoopback(namespacePath)
if err != nil {
return nil, errors.Wrapf(err, "failed to set the loopback adapter up")
}

View File

@@ -0,0 +1,13 @@
package cni
import (
"os/exec"
)
// FreeBSD vnet adds the lo0 interface automatically - we just need to
// add the default address. Note: this will also add ::1 as a side
// effect.
func setupLoopback(namespacePath string) error {
// The jexec wrapper runs the ifconfig command inside the jail.
return exec.Command("jexec", namespacePath, "ifconfig", "lo0", "inet", "127.0.0.1").Run()
}

View File

@@ -0,0 +1,17 @@
package cni
import (
"github.com/containernetworking/plugins/pkg/ns"
"github.com/vishvananda/netlink"
)
func setupLoopback(namespacePath string) error {
// set the loopback adapter up in the container netns
return ns.WithNetNSPath(namespacePath, func(_ ns.NetNS) error {
link, err := netlink.LinkByName("lo")
if err == nil {
err = netlink.LinkSetUp(link)
}
return err
})
}

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package netavark

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package netavark

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package netavark

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package netavark

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package netavark

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package netavark

View File

@@ -1,5 +1,5 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package network
@@ -25,14 +25,8 @@ import (
const (
// defaultNetworkBackendFileName is the file name for sentinel file to store the backend
defaultNetworkBackendFileName = "defaultNetworkBackend"
// cniConfigDir is the directory where cni configuration is found
cniConfigDir = "/etc/cni/net.d/"
// cniConfigDirRootless is the directory in XDG_CONFIG_HOME for cni plugins
cniConfigDirRootless = "cni/net.d/"
// netavarkConfigDir is the config directory for the rootful network files
netavarkConfigDir = "/etc/containers/networks"
// netavarkRunDir is the run directory for the rootful temporary network files such as the ipam db
netavarkRunDir = "/run/containers/networks"
// netavarkBinary is the name of the netavark binary
netavarkBinary = "netavark"

View File

@@ -0,0 +1,10 @@
package network
const (
// cniConfigDir is the directory where cni configuration is found
cniConfigDir = "/usr/local/etc/cni/net.d/"
// netavarkConfigDir is the config directory for the rootful network files
netavarkConfigDir = "/usr/local/etc/containers/networks"
// netavarkRunDir is the run directory for the rootful temporary network files such as the ipam db
netavarkRunDir = "/var/run/containers/networks"
)

View File

@@ -0,0 +1,10 @@
package network
const (
// cniConfigDir is the directory where cni configuration is found
cniConfigDir = "/etc/cni/net.d/"
// netavarkConfigDir is the config directory for the rootful network files
netavarkConfigDir = "/etc/containers/networks"
// netavarkRunDir is the run directory for the rootful temporary network files such as the ipam db
netavarkRunDir = "/run/containers/networks"
)