summaryrefslogtreecommitdiff
path: root/libpod/kube.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2021-11-22 11:50:08 -0600
committerBrent Baude <bbaude@redhat.com>2021-11-22 11:50:08 -0600
commit9c8fb5cc0c0eb17adac1c2ddb43e23cd723c718b (patch)
treef564e502b0a06f330dd2fbf4e1389d1bd5312419 /libpod/kube.go
parent26b45a1564fb01090f6a10776922654641a76681 (diff)
downloadpodman-9c8fb5cc0c0eb17adac1c2ddb43e23cd723c718b.tar.gz
podman-9c8fb5cc0c0eb17adac1c2ddb43e23cd723c718b.tar.bz2
podman-9c8fb5cc0c0eb17adac1c2ddb43e23cd723c718b.zip
Rename pod on generate of container
When generating kube of a container, the podname and container name in the yaml are identical. This offends rules in podman where pods and containers cannot have the same name. We now append _pod to the podname to avoid that collision. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/kube.go')
-rw-r--r--libpod/kube.go11
1 files changed, 10 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,