mirror of https://github.com/k3s-io/k3s
Exclude service itself when checking conflict.
parent
29b73cc4b5
commit
241f3d702b
|
@ -431,7 +431,9 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
|
||||||
allErrs = append(allErrs, errs.NewInternalError(err))
|
allErrs = append(allErrs, errs.NewInternalError(err))
|
||||||
} else {
|
} else {
|
||||||
for i := range services.Items {
|
for i := range services.Items {
|
||||||
if services.Items[i].Spec.CreateExternalLoadBalancer && services.Items[i].Spec.Port == service.Spec.Port {
|
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)))
|
allErrs = append(allErrs, errs.NewConflict("service", service.Name, fmt.Errorf("Port: %d is already in use", service.Spec.Port)))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,6 @@ func reloadIPsFromStorage(ipa *ipAllocator, registry Registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
|
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
|
||||||
|
|
||||||
service := obj.(*api.Service)
|
service := obj.(*api.Service)
|
||||||
if !api.ValidNamespace(ctx, &service.ObjectMeta) {
|
if !api.ValidNamespace(ctx, &service.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))
|
||||||
|
|
|
@ -641,6 +641,14 @@ func TestServiceRegistryIPExternalLoadBalancer(t *testing.T) {
|
||||||
if created_service.Spec.ProxyPort != 6502 {
|
if created_service.Spec.ProxyPort != 6502 {
|
||||||
t.Errorf("Unexpected ProxyPort: %d", created_service.Spec.ProxyPort)
|
t.Errorf("Unexpected ProxyPort: %d", created_service.Spec.ProxyPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update := new(api.Service)
|
||||||
|
*update = *created_service
|
||||||
|
|
||||||
|
_, err := rest.Update(ctx, update)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceRegistryIPReloadFromStorage(t *testing.T) {
|
func TestServiceRegistryIPReloadFromStorage(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue