aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-06-30 17:13:28 -0400
committerGitHub <noreply@github.com>2021-06-30 17:13:28 -0400
commitfd1715568b7c14451dcf2581c385c8d3e307d30e (patch)
tree40b067377bda67d7d4002100e7210547bf4317f5 /pkg
parent61b7beaf8e595bdc1305a12b49e26a25bbc2bc42 (diff)
parent092902b455551d7353163c1e6d322f3605b9a897 (diff)
downloadpodman-fd1715568b7c14451dcf2581c385c8d3e307d30e.tar.gz
podman-fd1715568b7c14451dcf2581c385c8d3e307d30e.tar.bz2
podman-fd1715568b7c14451dcf2581c385c8d3e307d30e.zip
Merge pull request #10816 from rhatdan/network
Handle advanced --network options in podman play kube
Diffstat (limited to 'pkg')
-rw-r--r--pkg/domain/infra/abi/play.go24
-rw-r--r--pkg/specgen/namespaces.go22
2 files changed, 35 insertions, 11 deletions
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index 0ac9b5d8d..4782f0d01 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -182,20 +182,22 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
return nil, err
}
if options.Network != "" {
- switch strings.ToLower(options.Network) {
- case "bridge", "host":
+ ns, cniNets, netOpts, err := specgen.ParseNetworkString(options.Network)
+ if err != nil {
+ return nil, err
+ }
+
+ if (ns.IsBridge() && len(cniNets) == 0) || ns.IsHost() {
return nil, errors.Errorf("invalid value passed to --network: bridge or host networking must be configured in YAML")
- case "":
- return nil, errors.Errorf("invalid value passed to --network: must provide a comma-separated list of CNI networks")
- default:
- // We'll assume this is a comma-separated list of CNI
- // networks.
- networks := strings.Split(options.Network, ",")
- logrus.Debugf("Pod joining CNI networks: %v", networks)
- p.NetNS.NSMode = specgen.Bridge
- p.CNINetworks = append(p.CNINetworks, networks...)
+ }
+ logrus.Debugf("Pod %q joining CNI networks: %v", podName, cniNets)
+ p.NetNS.NSMode = specgen.Bridge
+ p.CNINetworks = append(p.CNINetworks, cniNets...)
+ if len(netOpts) > 0 {
+ p.NetworkOptions = netOpts
}
}
+
if len(options.StaticIPs) > *ipIndex {
p.StaticIP = &options.StaticIPs[*ipIndex]
} else if len(options.StaticIPs) > 0 {
diff --git a/pkg/specgen/namespaces.go b/pkg/specgen/namespaces.go
index 80852930a..76fa66bc7 100644
--- a/pkg/specgen/namespaces.go
+++ b/pkg/specgen/namespaces.go
@@ -68,6 +68,11 @@ func (n *Namespace) IsHost() bool {
return n.NSMode == Host
}
+// IsBridge returns a bool if the namespace is a Bridge
+func (n *Namespace) IsBridge() bool {
+ return n.NSMode == Bridge
+}
+
// IsPath indicates via bool if the namespace is based on a path
func (n *Namespace) IsPath() bool {
return n.NSMode == Path
@@ -301,3 +306,20 @@ func ParseNetworkNamespace(ns string, rootlessDefaultCNI bool) (Namespace, []str
return toReturn, cniNetworks, nil
}
+
+func ParseNetworkString(network string) (Namespace, []string, map[string][]string, error) {
+ var networkOptions map[string][]string
+ parts := strings.SplitN(network, ":", 2)
+
+ ns, cniNets, err := ParseNetworkNamespace(network, containerConfig.Containers.RootlessNetworking == "cni")
+ if err != nil {
+ return Namespace{}, nil, nil, err
+ }
+
+ if len(parts) > 1 {
+ networkOptions = make(map[string][]string)
+ networkOptions[parts[0]] = strings.Split(parts[1], ",")
+ cniNets = nil
+ }
+ return ns, cniNets, networkOptions, nil
+}