summaryrefslogtreecommitdiff
path: root/cmd/podman/play_kube.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-02-26 11:13:23 -0600
committerbaude <bbaude@redhat.com>2019-02-26 12:13:12 -0600
commited1ea8dea1b2738829a05dd3c3dbcf4b6744ad3f (patch)
tree7a7f4466c4909fe2b5121badfb6e3cfc2e9e03d8 /cmd/podman/play_kube.go
parent1ad0d29fc2eb52fec707a4458fe31adc862e2862 (diff)
downloadpodman-ed1ea8dea1b2738829a05dd3c3dbcf4b6744ad3f.tar.gz
podman-ed1ea8dea1b2738829a05dd3c3dbcf4b6744ad3f.tar.bz2
podman-ed1ea8dea1b2738829a05dd3c3dbcf4b6744ad3f.zip
rename pod when we have a name collision with a container
when podman generate kube runs, it names the pod based on the first container it finds. the resulting yaml file is perfectly acceptable in a kubernetes environment. But when replaying the YAML file with podman, we cannot have a container and pod with the same name. therefore, we rename the pod if find a collision to name_pod. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/play_kube.go')
-rw-r--r--cmd/podman/play_kube.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/podman/play_kube.go b/cmd/podman/play_kube.go
index 1a45cbed9..69a15ba8d 100644
--- a/cmd/podman/play_kube.go
+++ b/cmd/podman/play_kube.go
@@ -90,8 +90,17 @@ func playKubeYAMLCmd(c *cliconfig.KubePlayValues) error {
return errors.Wrapf(err, "unable to read %s as YAML", args[0])
}
+ // check for name collision between pod and container
+ podName := podYAML.ObjectMeta.Name
+ for _, n := range podYAML.Spec.Containers {
+ if n.Name == podName {
+ fmt.Printf("a container exists with the same name (%s) as the pod in your YAML file; changing pod name to %s_pod\n", podName, podName)
+ podName = fmt.Sprintf("%s_pod", podName)
+ }
+ }
+
podOptions = append(podOptions, libpod.WithInfraContainer())
- podOptions = append(podOptions, libpod.WithPodName(podYAML.ObjectMeta.Name))
+ podOptions = append(podOptions, libpod.WithPodName(podName))
// TODO for now we just used the default kernel namespaces; we need to add/subtract this from yaml
nsOptions, err := shared.GetNamespaceOptions(strings.Split(DefaultKernelNamespaces, ","))