Skip to content

Commit d0b468f

Browse files
committed
Merge pull request kubernetes#5830 from vmarmol/hostname
Cap container hostname length to 63 chars.
2 parents 5c40bd6 + 07f928b commit d0b468f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: pkg/kubelet/kubelet.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -765,13 +765,20 @@ func (kl *Kubelet) runContainer(pod *api.Pod, container *api.Container, podVolum
765765
binds := makeBinds(container, podVolumes)
766766
exposedPorts, portBindings := makePortsAndBindings(container)
767767

768+
// TODO(vmarmol): Handle better.
769+
// Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
770+
const hostnameMaxLen = 63
771+
containerHostname := pod.Name
772+
if len(containerHostname) > hostnameMaxLen {
773+
containerHostname = containerHostname[:hostnameMaxLen]
774+
}
768775
opts := docker.CreateContainerOptions{
769776
Name: dockertools.BuildDockerName(dockertools.KubeletContainerName{GetPodFullName(pod), pod.UID, container.Name}, container),
770777
Config: &docker.Config{
771778
Cmd: container.Command,
772779
Env: envVariables,
773780
ExposedPorts: exposedPorts,
774-
Hostname: pod.Name,
781+
Hostname: containerHostname,
775782
Image: container.Image,
776783
Memory: container.Resources.Limits.Memory().Value(),
777784
CPUShares: milliCPUToShares(container.Resources.Limits.Cpu().MilliValue()),

0 commit comments

Comments
 (0)