summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-11-22 16:19:58 -0500
committerGitHub <noreply@github.com>2021-11-22 16:19:58 -0500
commit992fafa9ab93f5bd20f505d80b07ed849a089c9a (patch)
treefbca2b06cd2ff00ded193cb3520cfed8636270aa
parent3eb1453b80db2dfe75edc4705f23f542a7a0f426 (diff)
parent9c8fb5cc0c0eb17adac1c2ddb43e23cd723c718b (diff)
downloadpodman-992fafa9ab93f5bd20f505d80b07ed849a089c9a.tar.gz
podman-992fafa9ab93f5bd20f505d80b07ed849a089c9a.tar.bz2
podman-992fafa9ab93f5bd20f505d80b07ed849a089c9a.zip
Merge pull request #12386 from baude/playkuberename
Rename pod on generate of container
-rw-r--r--libpod/kube.go11
-rw-r--r--test/e2e/generate_kube_test.go1
2 files changed, 11 insertions, 1 deletions
diff --git a/libpod/kube.go b/libpod/kube.go
index 850f2493c..351c49c9a 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -427,7 +427,9 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container) (*v1.Pod,
hostNetwork := true
podDNS := v1.PodDNSConfig{}
kubeAnnotations := make(map[string]string)
+ ctrNames := make([]string, 0, len(ctrs))
for _, ctr := range ctrs {
+ ctrNames = append(ctrNames, strings.ReplaceAll(ctr.Name(), "_", ""))
// Convert auto-update labels into kube annotations
for k, v := range getAutoUpdateAnnotations(removeUnderscores(ctr.Name()), ctr.Labels()) {
kubeAnnotations[k] = v
@@ -484,8 +486,15 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container) (*v1.Pod,
}
} // end if ctrDNS
}
+ podName := strings.ReplaceAll(ctrs[0].Name(), "_", "")
+ // Check if the pod name and container name will end up conflicting
+ // Append _pod if so
+ if util.StringInSlice(podName, ctrNames) {
+ podName = podName + "_pod"
+ }
+
return newPodObject(
- strings.ReplaceAll(ctrs[0].Name(), "_", ""),
+ podName,
kubeAnnotations,
kubeInitCtrs,
kubeCtrs,
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index cd382eba9..d95555068 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -71,6 +71,7 @@ var _ = Describe("Podman generate kube", func() {
Expect(pod.Spec.DNSConfig).To(BeNil())
Expect(pod.Spec.Containers[0].WorkingDir).To(Equal(""))
Expect(pod.Spec.Containers[0].Env).To(BeNil())
+ Expect(pod.Name).To(Equal("top_pod"))
numContainers := 0
for range pod.Spec.Containers {