mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Fix a bug in validation that was leftover from the previous way of externalizing services.
This commit is contained in:
parent
6410f37a32
commit
99583fc8c5
@ -485,21 +485,6 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
|
||||
allErrs = append(allErrs, ValidateLabels(service.Labels, "labels")...)
|
||||
allErrs = append(allErrs, ValidateLabels(service.Annotations, "annotations")...)
|
||||
|
||||
if service.Spec.CreateExternalLoadBalancer {
|
||||
services, err := lister.ListServices(ctx)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, errs.NewInternalError(err))
|
||||
} else {
|
||||
for i := range services.Items {
|
||||
if services.Items[i].Name != service.Name &&
|
||||
services.Items[i].Spec.CreateExternalLoadBalancer &&
|
||||
services.Items[i].Spec.Port == service.Spec.Port {
|
||||
allErrs = append(allErrs, errs.NewConflict("service", service.Name, fmt.Errorf("port: %d is already in use", service.Spec.Port)))
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if service.Spec.SessionAffinity == "" {
|
||||
service.Spec.SessionAffinity = api.AffinityTypeNone
|
||||
} else if !supportedSessionAffinityType.Has(string(service.Spec.SessionAffinity)) {
|
||||
|
@ -953,7 +953,7 @@ func TestValidateService(t *testing.T) {
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "invalid port in use",
|
||||
name: "external port in use",
|
||||
svc: api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -970,7 +970,7 @@ func TestValidateService(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
numErrs: 1,
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "same port in use, but not external",
|
||||
|
Loading…
Reference in New Issue
Block a user