diff options
author | Urvashi Mohnani <umohnani@redhat.com> | 2022-05-10 13:23:46 -0400 |
---|---|---|
committer | Urvashi Mohnani <umohnani@redhat.com> | 2022-07-08 11:21:48 -0400 |
commit | 81a19a568f6234be47882b1c2b066a637749fd39 (patch) | |
tree | b0877e3ff18651d297838a21bcd1cd95ce23251d /pkg | |
parent | 49df3cc5cb7e6a1d9e28cacfa86562abbdf48fd9 (diff) | |
download | podman-81a19a568f6234be47882b1c2b066a637749fd39.tar.gz podman-81a19a568f6234be47882b1c2b066a637749fd39.tar.bz2 podman-81a19a568f6234be47882b1c2b066a637749fd39.zip |
Add ports and hostname correctly in kube yaml
If a pod is created without net sharing, allow adding
separate ports for each container to the kube yaml
and also set the pod level hostname correctly if the
uts namespace is not being shared.
Add a warning if the default namespace sharing options
have been modified by the user.
Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/domain/infra/abi/generate.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/domain/infra/abi/generate.go b/pkg/domain/infra/abi/generate.go index ff85dee9b..8b2193cb2 100644 --- a/pkg/domain/infra/abi/generate.go +++ b/pkg/domain/infra/abi/generate.go @@ -51,6 +51,7 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, content [][]byte ) + defaultKubeNS := true // Lookup for podman objects. for _, nameOrID := range nameOrIDs { // Let's assume it's a container, so get the container. @@ -76,6 +77,17 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, return nil, err } } else { + // Get the pod config to see if the user has modified the default + // namespace sharing values as this might affect the pods when run + // in a k8s cluster + podConfig, err := pod.Config() + if err != nil { + return nil, err + } + if !(podConfig.UsePodIPC && podConfig.UsePodNet && podConfig.UsePodUTS) { + defaultKubeNS = false + } + pods = append(pods, pod) continue } @@ -95,6 +107,15 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, return nil, errors.Errorf("Name or ID %q not found", nameOrID) } + if !defaultKubeNS { + warning := ` +# NOTE: The namespace sharing for a pod has been modified by the user and is not the same as the +# default settings for kubernetes. This can lead to unexpected behavior when running the generated +# kube yaml in a kubernetes cluster. +` + content = append(content, []byte(warning)) + } + // Generate kube persistent volume claims from volumes. if len(vols) >= 1 { pvs, err := getKubePVCs(vols) |