aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorAndrei Natanael Cosma <andrei@intersect.ro>2022-10-02 19:08:17 +0200
committerAndrei Natanael Cosma <andrei@intersect.ro>2022-10-04 21:59:57 +0200
commitf250560a8043f25771f8ba41b2faf585829b0c9b (patch)
tree4876bc718d78438d561bf08a7dcb2dfcf5c33928 /pkg
parent0330d1abed7559e33baf50167a161e8ec54363b3 (diff)
downloadpodman-f250560a8043f25771f8ba41b2faf585829b0c9b.tar.gz
podman-f250560a8043f25771f8ba41b2faf585829b0c9b.tar.bz2
podman-f250560a8043f25771f8ba41b2faf585829b0c9b.zip
Add pods created by kube play to a default network
In order to allow pods to reach other pods (as in Kubernetes) they all need to be added to the same network. A network is created (if it doesn't exist) and pods created by play-kube are added to that network. When network options are passed to kube command the pods are not attached to the default kube network. Signed-off-by: Andrei Natanael Cosma <andrei@intersect.ro>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/domain/infra/abi/play.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index 8779acfda..bec5c4cb5 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -40,6 +40,9 @@ import (
// container-specific sd-notify modes.
const sdNotifyAnnotation = "io.containers.sdnotify"
+// default network created/used by kube
+const kubeDefaultNetwork = "podman-default-kube-network"
+
// createServiceContainer creates a container that can later on
// be associated with the pods of a K8s yaml. It will be started along with
// the first pod.
@@ -114,6 +117,19 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
report := &entities.PlayKubeReport{}
validKinds := 0
+ // when no network options are specified, create a common network for all the pods
+ if len(options.Networks) == 0 {
+ _, err := ic.NetworkCreate(
+ ctx, nettypes.Network{
+ Name: kubeDefaultNetwork,
+ DNSEnabled: true,
+ },
+ )
+ if err != nil && !errors.Is(err, nettypes.ErrNetworkExists) {
+ return nil, err
+ }
+ }
+
// read yaml document
content, err := io.ReadAll(body)
if err != nil {
@@ -338,6 +354,11 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
return nil, err
}
+ // add kube default network if no network is explicitly added
+ if podOpt.Net.Network.NSMode != "host" && len(options.Networks) == 0 {
+ options.Networks = []string{kubeDefaultNetwork}
+ }
+
if len(options.Networks) > 0 {
ns, networks, netOpts, err := specgen.ParseNetworkFlag(options.Networks)
if err != nil {