mirror of
https://github.com/containers/podman.git
synced 2025-06-28 14:29:04 +08:00
Merge pull request #18068 from umohnani8/kube-name
Fix invalid pod name and hostname during kube generate
This commit is contained in:
@ -470,8 +470,8 @@ func (p *Pod) podWithContainers(ctx context.Context, containers []*Container, po
|
|||||||
// Since hostname is only set at pod level, set the hostname to the hostname of the first container we encounter
|
// Since hostname is only set at pod level, set the hostname to the hostname of the first container we encounter
|
||||||
if hostname == "" {
|
if hostname == "" {
|
||||||
// Only set the hostname if it is not set to the truncated container ID, which we do by default if no
|
// Only set the hostname if it is not set to the truncated container ID, which we do by default if no
|
||||||
// hostname is specified for the container
|
// hostname is specified for the container and if it is not set to the pod name.
|
||||||
if !strings.Contains(ctr.ID(), ctr.Hostname()) {
|
if !strings.Contains(ctr.ID(), ctr.Hostname()) && ctr.Hostname() != p.Name() {
|
||||||
hostname = ctr.Hostname()
|
hostname = ctr.Hostname()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,9 +533,10 @@ func (p *Pod) podWithContainers(ctx context.Context, containers []*Container, po
|
|||||||
for _, vol := range deDupPodVolumes {
|
for _, vol := range deDupPodVolumes {
|
||||||
podVolumes = append(podVolumes, *vol)
|
podVolumes = append(podVolumes, *vol)
|
||||||
}
|
}
|
||||||
|
podName := removeUnderscores(p.Name())
|
||||||
|
|
||||||
return newPodObject(
|
return newPodObject(
|
||||||
p.Name(),
|
podName,
|
||||||
podAnnotations,
|
podAnnotations,
|
||||||
podInitCtrs,
|
podInitCtrs,
|
||||||
podContainers,
|
podContainers,
|
||||||
|
@ -1485,4 +1485,26 @@ USER test1`
|
|||||||
kube.WaitWithDefaultTimeout()
|
kube.WaitWithDefaultTimeout()
|
||||||
Expect(kube).Should(Exit(125))
|
Expect(kube).Should(Exit(125))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman generate kube on pod with invalid name", func() {
|
||||||
|
podName := "test_pod"
|
||||||
|
session := podmanTest.Podman([]string{"pod", "create", podName})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"create", "--pod", podName, "--restart", "no", ALPINE, "top"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"generate", "kube", podName})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube).Should(Exit(0))
|
||||||
|
|
||||||
|
pod := new(v1.Pod)
|
||||||
|
err := yaml.Unmarshal(kube.Out.Contents(), pod)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
// The pod name should no longer have _ and there should be no hostname in the generated yaml
|
||||||
|
Expect(pod.Name).To(Equal("testpod"))
|
||||||
|
Expect(pod.Spec.Hostname).To(Equal(""))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -105,7 +105,7 @@ metadata.creationTimestamp | =~ | [0-9T:-]\\+Z
|
|||||||
metadata.labels.app | = | ${pname}
|
metadata.labels.app | = | ${pname}
|
||||||
metadata.name | = | ${pname}
|
metadata.name | = | ${pname}
|
||||||
|
|
||||||
spec.hostname | = | $pname
|
spec.hostname | = | null
|
||||||
|
|
||||||
spec.containers[0].command | = | [\"top\"]
|
spec.containers[0].command | = | [\"top\"]
|
||||||
spec.containers[0].image | = | $IMAGE
|
spec.containers[0].image | = | $IMAGE
|
||||||
|
Reference in New Issue
Block a user