Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename pod on generate of container #12386

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/generate_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down