Commit 6a46bf1b authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #33274 from nebril/headless-lb

Automatic merge from submit-queue Disallow headless Services with LB type **What this PR does / why we need it**: It adds new validation rule for Services, to ensure that creating LoadBalancer type service with cluster IP set to "None" fails. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #33036 **Release note**: ```release-note Creating LoadBalancer Service with "None" ClusterIP is no longer possible ```
parents cfb833e8 9e1c886a
...@@ -2406,6 +2406,9 @@ func ValidateService(service *api.Service) field.ErrorList { ...@@ -2406,6 +2406,9 @@ func ValidateService(service *api.Service) field.ErrorList {
allErrs = append(allErrs, field.Invalid(portPath, port.Port, "may not expose port 10250 externally since it is used by kubelet")) allErrs = append(allErrs, field.Invalid(portPath, port.Port, "may not expose port 10250 externally since it is used by kubelet"))
} }
} }
if service.Spec.ClusterIP == "None" {
allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "may not be set to 'None' for LoadBalancer services"))
}
case api.ServiceTypeExternalName: case api.ServiceTypeExternalName:
if service.Spec.ClusterIP != "" { if service.Spec.ClusterIP != "" {
allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "must be empty for ExternalName services")) allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "must be empty for ExternalName services"))
......
...@@ -5173,6 +5173,14 @@ func TestValidateService(t *testing.T) { ...@@ -5173,6 +5173,14 @@ func TestValidateService(t *testing.T) {
}, },
numErrs: 1, numErrs: 1,
}, },
{
name: "LoadBalancer type cannot have None ClusterIP",
tweakSvc: func(s *api.Service) {
s.Spec.ClusterIP = "None"
s.Spec.Type = api.ServiceTypeLoadBalancer
},
numErrs: 1,
},
} }
for _, tc := range testCases { for _, tc := range testCases {
...@@ -6432,6 +6440,14 @@ func TestValidateServiceUpdate(t *testing.T) { ...@@ -6432,6 +6440,14 @@ func TestValidateServiceUpdate(t *testing.T) {
}, },
numErrs: 1, numErrs: 1,
}, },
{
name: "LoadBalancer type cannot have None ClusterIP",
tweakSvc: func(oldSvc, newSvc *api.Service) {
newSvc.Spec.ClusterIP = "None"
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
},
numErrs: 1,
},
} }
for _, tc := range testCases { for _, tc := range testCases {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment