mirror of
https://github.com/containers/podman.git
synced 2025-07-29 11:22:38 +08:00
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>
This commit is contained in:
@ -427,7 +427,9 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container) (*v1.Pod,
|
|||||||
hostNetwork := true
|
hostNetwork := true
|
||||||
podDNS := v1.PodDNSConfig{}
|
podDNS := v1.PodDNSConfig{}
|
||||||
kubeAnnotations := make(map[string]string)
|
kubeAnnotations := make(map[string]string)
|
||||||
|
ctrNames := make([]string, 0, len(ctrs))
|
||||||
for _, ctr := range ctrs {
|
for _, ctr := range ctrs {
|
||||||
|
ctrNames = append(ctrNames, strings.ReplaceAll(ctr.Name(), "_", ""))
|
||||||
// Convert auto-update labels into kube annotations
|
// Convert auto-update labels into kube annotations
|
||||||
for k, v := range getAutoUpdateAnnotations(removeUnderscores(ctr.Name()), ctr.Labels()) {
|
for k, v := range getAutoUpdateAnnotations(removeUnderscores(ctr.Name()), ctr.Labels()) {
|
||||||
kubeAnnotations[k] = v
|
kubeAnnotations[k] = v
|
||||||
@ -484,8 +486,15 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container) (*v1.Pod,
|
|||||||
}
|
}
|
||||||
} // end if ctrDNS
|
} // 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(
|
return newPodObject(
|
||||||
strings.ReplaceAll(ctrs[0].Name(), "_", ""),
|
podName,
|
||||||
kubeAnnotations,
|
kubeAnnotations,
|
||||||
kubeInitCtrs,
|
kubeInitCtrs,
|
||||||
kubeCtrs,
|
kubeCtrs,
|
||||||
|
@ -71,6 +71,7 @@ var _ = Describe("Podman generate kube", func() {
|
|||||||
Expect(pod.Spec.DNSConfig).To(BeNil())
|
Expect(pod.Spec.DNSConfig).To(BeNil())
|
||||||
Expect(pod.Spec.Containers[0].WorkingDir).To(Equal(""))
|
Expect(pod.Spec.Containers[0].WorkingDir).To(Equal(""))
|
||||||
Expect(pod.Spec.Containers[0].Env).To(BeNil())
|
Expect(pod.Spec.Containers[0].Env).To(BeNil())
|
||||||
|
Expect(pod.Name).To(Equal("top_pod"))
|
||||||
|
|
||||||
numContainers := 0
|
numContainers := 0
|
||||||
for range pod.Spec.Containers {
|
for range pod.Spec.Containers {
|
||||||
|
Reference in New Issue
Block a user