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

Add support for specifying CNI networks in podman play kube #5620

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/podman/cliconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ type KubePlayValues struct {
Authfile string
CertDir string
Creds string
Network string
Quiet bool
SignaturePolicy string
TlsVerify bool
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/play_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func init() {
flags.StringVar(&playKubeCommand.SeccompProfileRoot, "seccomp-profile-root", defaultSeccompRoot, "Directory path for seccomp profiles")
markFlagHidden(flags, "signature-policy")
}
flags.StringVar(&playKubeCommand.Network, "network", "", "Connect pod to CNI network(s)")
}

func playKubeCmd(c *cliconfig.KubePlayValues) error {
Expand Down
1 change: 1 addition & 0 deletions completions/bash/podman
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,7 @@ _podman_play_kube() {
--authfile
--cert-dir
--creds
--network
"

local boolean_options="
Expand Down
14 changes: 13 additions & 1 deletion docs/source/markdown/podman-play-kube.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ The [username[:password]] to use to authenticate with the registry if required.
If one or both values are not supplied, a command line prompt will appear and the
value can be entered. The password is entered without echo.

**--network**=*cni networks*

A comma-separated list of the names of CNI networks the pod should join.

cfelder marked this conversation as resolved.
Show resolved Hide resolved
**--quiet**, **-q**

Suppress output information when pulling images
Expand All @@ -62,8 +66,16 @@ $ podman play kube demo.yml
52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6
```

CNI network(s) can be specified as comma-separated list using ``--network``
```
$ podman play kube demo.yml --network cni1,cni2
52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6
```

Please take into account that CNI networks must be created first using podman-network-create(1).

## SEE ALSO
podman(1), podman-container(1), podman-pod(1), podman-generate-kube(1), podman-play(1)
podman(1), podman-container(1), podman-pod(1), podman-generate-kube(1), podman-play(1), podman-network-create(1)

## HISTORY
December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)
18 changes: 17 additions & 1 deletion pkg/adapter/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (r *LocalRuntime) CreatePod(ctx context.Context, cli *cliconfig.PodCreateVa
logrus.Debugf("Pod will use host networking")
options = append(options, libpod.WithPodHostNetwork())
case "":
return "", errors.Errorf("invalid value passed to --net: must provide a comma-separated list of CNI networks or host")
return "", errors.Errorf("invalid value passed to --network: must provide a comma-separated list of CNI networks or host")
cfelder marked this conversation as resolved.
Show resolved Hide resolved
default:
// We'll assume this is a comma-separated list of CNI
// networks.
Expand Down Expand Up @@ -595,6 +595,22 @@ func (r *LocalRuntime) PlayKubeYAML(ctx context.Context, c *cliconfig.KubePlayVa
podPorts := getPodPorts(podYAML.Spec.Containers)
podOptions = append(podOptions, libpod.WithInfraContainerPorts(podPorts))

if c.Flag("network").Changed {
netValue := c.String("network")
switch strings.ToLower(netValue) {
case "bridge", "host":
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(netValue, ",")
logrus.Debugf("Pod joining CNI networks: %v", networks)
podOptions = append(podOptions, libpod.WithPodNetworks(networks))
}
}

// Create the Pod
pod, err = r.NewPod(ctx, podOptions...)
if err != nil {
Expand Down