kubernetes: Kubelet can generate an invalid fully qualified domain name for a pod

Kubelet can generate an invalid fully qualified domain name for a pod when the ClusterDomain configured in the kubelets config.yaml defaults to “”

The code in function GeneratePodHostNameAndDomain can result in a fully qualified domain name ending in a period, which is invalid.

The problematic line is hostDomain = fmt.Sprintf("%s.%s.svc.%s", pod.Spec.Subdomain, pod.Namespace, clusterDomain)

https://github.com/kubernetes/kubernetes/blob/36930f4cb605450ccbe3126caad365aa5f51267c/pkg/kubelet/kubelet_pods.go#L455

The code already has a check for length of subdomain string being > 0. I wonder if a similar check for the ClusterDomain string would be sensible?

Note: I believe that kubeadm will set ClusterDomain in the kubelets config to a non empty string, but it remains the case that the default of “” doesn’t get handled well. Id be happy to submit a fix, but would appreciate insights from an SME first.

About this issue

  • Original URL
  • State: open
  • Created 8 months ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Hi! I would like to work on this if possible.

/assign

/help /good-first-issue

Adding a check and changing the pattern string if ClusterDomain is empty sounds like an easy good first issue.