summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go4
-rw-r--r--libpod/network/cni/cni_conversion.go6
-rw-r--r--libpod/network/cni/network.go2
-rw-r--r--libpod/network/cni/run.go17
-rw-r--r--libpod/network/types/network.go28
5 files changed, 29 insertions, 28 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 7d602326e..5c56ff036 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -8,7 +8,7 @@ import (
"os"
"time"
- cnitypes "github.com/containernetworking/cni/pkg/types/current"
+ types040 "github.com/containernetworking/cni/pkg/types/040"
"github.com/containers/common/pkg/secrets"
"github.com/containers/image/v5/manifest"
"github.com/containers/podman/v3/libpod/define"
@@ -176,7 +176,7 @@ type ContainerState struct {
// active.
// These are DEPRECATED and will be removed in a future release.
// This field is only used for backwarts compatibility.
- NetworkStatusOld []*cnitypes.Result `json:"networkResults,omitempty"`
+ NetworkStatusOld []*types040.Result `json:"networkResults,omitempty"`
// NetworkStatus contains the network Status for all networks
// the container is attached to. Only populated if we created a network
// namespace for the container, and the network namespace is currently
diff --git a/libpod/network/cni/cni_conversion.go b/libpod/network/cni/cni_conversion.go
index d69dd7eb3..7a73b874a 100644
--- a/libpod/network/cni/cni_conversion.go
+++ b/libpod/network/cni/cni_conversion.go
@@ -14,7 +14,6 @@ import (
"time"
"github.com/containernetworking/cni/libcni"
- "github.com/containernetworking/cni/pkg/version"
"github.com/containers/podman/v3/libpod/network/types"
"github.com/containers/podman/v3/libpod/network/util"
pkgutil "github.com/containers/podman/v3/pkg/util"
@@ -283,7 +282,10 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
ipMasq = false
}
// create CNI plugin configuration
- ncList := newNcList(network.Name, version.Current(), network.Labels, network.Options)
+ // explicitly use CNI version 0.4.0 here, to use v1.0.0 at least containernetwork-plugins-1.0.1 has to be installed
+ // the dnsname plugin also needs to be updated for 1.0.0
+ // TODO change to 1.0.0 when most distros support it
+ ncList := newNcList(network.Name, "0.4.0", network.Labels, network.Options)
var plugins []interface{}
switch network.Driver {
diff --git a/libpod/network/cni/network.go b/libpod/network/cni/network.go
index d77e63a5d..02801641e 100644
--- a/libpod/network/cni/network.go
+++ b/libpod/network/cni/network.go
@@ -127,7 +127,7 @@ func (n *cniNetwork) loadNetworks() error {
conf, err := libcni.ConfListFromFile(file)
if err != nil {
// do not log ENOENT errors
- if !os.IsNotExist(err) {
+ if !errors.Is(err, os.ErrNotExist) {
logrus.Warnf("Error loading CNI config file %s: %v", file, err)
}
continue
diff --git a/libpod/network/cni/run.go b/libpod/network/cni/run.go
index b69953c4b..834e7c867 100644
--- a/libpod/network/cni/run.go
+++ b/libpod/network/cni/run.go
@@ -10,7 +10,7 @@ import (
"github.com/containernetworking/cni/libcni"
cnitypes "github.com/containernetworking/cni/pkg/types"
- "github.com/containernetworking/cni/pkg/types/current"
+ types040 "github.com/containernetworking/cni/pkg/types/040"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/network/types"
@@ -107,14 +107,9 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
return nil, retErr
}
- var cnires *current.Result
- cnires, retErr = current.GetResult(res)
- if retErr != nil {
- return nil, retErr
- }
- logrus.Debugf("cni result for container %s network %s: %v", options.ContainerID, name, cnires)
+ logrus.Debugf("cni result for container %s network %s: %v", options.ContainerID, name, res)
var status types.StatusBlock
- status, retErr = CNIResultToStatus(cnires)
+ status, retErr = CNIResultToStatus(res)
if retErr != nil {
return nil, retErr
}
@@ -125,8 +120,12 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
// CNIResultToStatus convert the cni result to status block
// nolint:golint
-func CNIResultToStatus(cniResult *current.Result) (types.StatusBlock, error) {
+func CNIResultToStatus(res cnitypes.Result) (types.StatusBlock, error) {
result := types.StatusBlock{}
+ cniResult, err := types040.GetResult(res)
+ if err != nil {
+ return result, err
+ }
nameservers := make([]net.IP, 0, len(cniResult.DNS.Nameservers))
for _, nameserver := range cniResult.DNS.Nameservers {
ip := net.ParseIP(nameserver)
diff --git a/libpod/network/types/network.go b/libpod/network/types/network.go
index 6053ceb29..68a32d499 100644
--- a/libpod/network/types/network.go
+++ b/libpod/network/types/network.go
@@ -32,11 +32,11 @@ type ContainerNetwork interface {
// Network describes the Network attributes.
type Network struct {
// Name of the Network.
- Name string `json:"name,omitempty"`
+ Name string `json:"name"`
// ID of the Network.
- ID string `json:"id,omitempty"`
+ ID string `json:"id"`
// Driver for this Network, e.g. bridge, macvlan...
- Driver string `json:"driver,omitempty"`
+ Driver string `json:"driver"`
// InterfaceName is the network interface name on the host.
NetworkInterface string `json:"network_interface,omitempty"`
// Created contains the timestamp when this network was created.
@@ -97,7 +97,7 @@ func (n *IPNet) UnmarshalText(text []byte) error {
type Subnet struct {
// Subnet for this Network in CIDR form.
// swagger:strfmt string
- Subnet IPNet `json:"subnet,omitempty"`
+ Subnet IPNet `json:"subnet"`
// Gateway IP for this Network.
// swagger:strfmt string
Gateway net.IP `json:"gateway,omitempty"`
@@ -134,14 +134,14 @@ type NetInterface struct {
// Networks list of assigned subnets with their gateway.
Networks []NetAddress `json:"networks,omitempty"`
// MacAddress for this Interface.
- MacAddress net.HardwareAddr `json:"mac_address,omitempty"`
+ MacAddress net.HardwareAddr `json:"mac_address"`
}
// NetAddress contains the subnet and gatway.
type NetAddress struct {
// Subnet of this NetAddress. Note that the subnet contains the
// actual ip of the net interface and not the network address.
- Subnet IPNet `json:"subnet,omitempty"`
+ Subnet IPNet `json:"subnet"`
// Gateway for the Subnet. This can be nil if there is no gateway, e.g. internal network.
Gateway net.IP `json:"gateway,omitempty"`
}
@@ -157,27 +157,27 @@ type PerNetworkOptions struct {
// StaticMac for this container. Optional.
StaticMAC net.HardwareAddr `json:"static_mac,omitempty"`
// InterfaceName for this container. Required.
- InterfaceName string `json:"interface_name,omitempty"`
+ InterfaceName string `json:"interface_name"`
}
// NetworkOptions for a given container.
type NetworkOptions struct {
// ContainerID is the container id, used for iptables comments and ipam allocation.
- ContainerID string `json:"container_id,omitempty"`
+ ContainerID string `json:"container_id"`
// ContainerName is the container name, used as dns name.
- ContainerName string `json:"container_name,omitempty"`
+ ContainerName string `json:"container_name"`
// PortMappings contains the port mappings for this container
PortMappings []PortMapping `json:"port_mappings,omitempty"`
// Networks contains all networks with the PerNetworkOptions.
// The map should contain at least one element.
- Networks map[string]PerNetworkOptions `json:"networks,omitempty"`
+ Networks map[string]PerNetworkOptions `json:"networks"`
}
// PortMapping is one or more ports that will be mapped into the container.
type PortMapping struct {
// HostIP is the IP that we will bind to on the host.
// If unset, assumed to be 0.0.0.0 (all interfaces).
- HostIP string `json:"host_ip,omitempty"`
+ HostIP string `json:"host_ip"`
// ContainerPort is the port number that will be exposed from the
// container.
// Mandatory.
@@ -186,7 +186,7 @@ type PortMapping struct {
// the container.
// If omitted, a random port on the host (guaranteed to be over 1024)
// will be assigned.
- HostPort uint16 `json:"host_port,omitempty"`
+ HostPort uint16 `json:"host_port"`
// Range is the number of ports that will be forwarded, starting at
// HostPort and ContainerPort and counting up.
// This is 1-indexed, so 1 is assumed to be a single port (only the
@@ -195,12 +195,12 @@ type PortMapping struct {
// If unset, assumed to be 1 (a single port).
// Both hostport + range and containerport + range must be less than
// 65536.
- Range uint16 `json:"range,omitempty"`
+ Range uint16 `json:"range"`
// Protocol is the protocol forward.
// Must be either "tcp", "udp", and "sctp", or some combination of these
// separated by commas.
// If unset, assumed to be TCP.
- Protocol string `json:"protocol,omitempty"`
+ Protocol string `json:"protocol"`
}
// OCICNIPortMapping maps to the standard CNI portmapping Capability.