mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-01-27 10:19:35 +00:00
Fix incorrect validation on the kubelet
This commit is contained in:
@@ -575,8 +575,8 @@ func (kl *Kubelet) GeneratePodHostNameAndDomain(pod *v1.Pod) (string, string, er
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.HostnameOverride) && pod.Spec.HostnameOverride != nil {
|
||||
hostname := *pod.Spec.HostnameOverride
|
||||
if msgs := utilvalidation.IsDNS1123Label(hostname); len(msgs) != 0 {
|
||||
return "", "", fmt.Errorf("pod HostnameOverride %q is not a valid DNS label: %s", hostname, strings.Join(msgs, ";"))
|
||||
if msgs := utilvalidation.IsDNS1123Subdomain(hostname); len(msgs) != 0 {
|
||||
return "", "", fmt.Errorf("pod HostnameOverride %q is not a valid DNS subdomain: %s", hostname, strings.Join(msgs, ";"))
|
||||
}
|
||||
truncatedHostname, err := truncatePodHostnameIfNeeded(pod.Name, hostname)
|
||||
if err != nil {
|
||||
|
||||
@@ -7468,7 +7468,15 @@ func TestGeneratePodHostNameAndDomain(t *testing.T) {
|
||||
podHostnameOverride: ptr.To("Invalid-Hostname-!"),
|
||||
featureGateEnabled: true,
|
||||
expectError: true,
|
||||
errorContains: "pod HostnameOverride \"Invalid-Hostname-!\" is not a valid DNS label",
|
||||
errorContains: "pod HostnameOverride \"Invalid-Hostname-!\" is not a valid DNS subdomain",
|
||||
},
|
||||
{
|
||||
name: "HostnameOverride - enabled - overrides all - valid DNS hostname",
|
||||
podName: "test-pod",
|
||||
podHostnameOverride: ptr.To("valid.hostname"),
|
||||
expectedHostname: "valid.hostname",
|
||||
featureGateEnabled: true,
|
||||
errorContains: "",
|
||||
},
|
||||
{
|
||||
name: "HostnameOverride - disabled - is ignored",
|
||||
|
||||
@@ -56,6 +56,14 @@ var _ = SIGDescribe("Override hostname of Pod", framework.WithFeatureGate(featur
|
||||
f := framework.NewDefaultFramework("hostfqdn")
|
||||
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
|
||||
|
||||
ginkgo.It("a pod has hostnameOverride field with value that is a valid DNS subdomain.", func(ctx context.Context) {
|
||||
pod := newTestPod(f.Namespace.Name)
|
||||
hostnameOverride := "override.example.host"
|
||||
pod.Spec.HostnameOverride = &hostnameOverride
|
||||
output := []string{fmt.Sprintf("%s;%s;", hostnameOverride, hostnameOverride)}
|
||||
e2eoutput.TestContainerOutput(ctx, f, "hostnameOverride overrides hostname", pod, 0, output)
|
||||
})
|
||||
|
||||
ginkgo.It("a pod with hostname and hostnameOverride fields will have hostnameOverride as hostname", func(ctx context.Context) {
|
||||
pod := newTestPod(f.Namespace.Name)
|
||||
hostname := "custom-host"
|
||||
|
||||
Reference in New Issue
Block a user