mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
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>
This commit is contained in:
@ -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, ","))
|
||||
|
Reference in New Issue
Block a user