mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Update api/validation service validation with service fields moved by #2086
This commit is contained in:
parent
fc0dab630c
commit
535785e3b9
@ -408,14 +408,14 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
|
|||||||
if labels.Set(service.Spec.Selector).AsSelector().Empty() {
|
if labels.Set(service.Spec.Selector).AsSelector().Empty() {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("spec.selector", service.Spec.Selector))
|
allErrs = append(allErrs, errs.NewFieldRequired("spec.selector", service.Spec.Selector))
|
||||||
}
|
}
|
||||||
if service.CreateExternalLoadBalancer {
|
if service.Spec.CreateExternalLoadBalancer {
|
||||||
services, err := lister.ListServices(ctx)
|
services, err := lister.ListServices(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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].CreateExternalLoadBalancer && services.Items[i].Port == service.Port {
|
if services.Items[i].Spec.CreateExternalLoadBalancer && services.Items[i].Spec.Port == service.Spec.Port {
|
||||||
allErrs = append(allErrs, errs.NewConflict("service", service.Namespace, fmt.Errorf("Port: %d is already in use", service.Port)))
|
allErrs = append(allErrs, errs.NewConflict("service", service.Namespace, fmt.Errorf("Port: %d is already in use", service.Spec.Port)))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -753,13 +753,15 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "invalid port in use",
|
name: "invalid port in use",
|
||||||
svc: api.Service{
|
svc: api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
CreateExternalLoadBalancer: true,
|
CreateExternalLoadBalancer: true,
|
||||||
Selector: map[string]string{"foo": "bar"},
|
Selector: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
existing: api.ServiceList{
|
existing: api.ServiceList{
|
||||||
Items: []api.Service{
|
Items: []api.Service{
|
||||||
{Port: 80, CreateExternalLoadBalancer: true},
|
{Spec: api.ServiceSpec{Port: 80, CreateExternalLoadBalancer: true}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
@ -768,13 +770,15 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "same port in use, but not external",
|
name: "same port in use, but not external",
|
||||||
svc: api.Service{
|
svc: api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
CreateExternalLoadBalancer: true,
|
CreateExternalLoadBalancer: true,
|
||||||
Selector: map[string]string{"foo": "bar"},
|
Selector: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
existing: api.ServiceList{
|
existing: api.ServiceList{
|
||||||
Items: []api.Service{
|
Items: []api.Service{
|
||||||
{Port: 80},
|
{Spec: api.ServiceSpec{Port: 80}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
@ -783,12 +787,14 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "same port in use, but not external on input",
|
name: "same port in use, but not external on input",
|
||||||
svc: api.Service{
|
svc: api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Selector: map[string]string{"foo": "bar"},
|
Selector: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
existing: api.ServiceList{
|
existing: api.ServiceList{
|
||||||
Items: []api.Service{
|
Items: []api.Service{
|
||||||
{Port: 80, CreateExternalLoadBalancer: true},
|
{Spec: api.ServiceSpec{Port: 80, CreateExternalLoadBalancer: true}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
@ -797,12 +803,14 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "same port in use, but neither external",
|
name: "same port in use, but neither external",
|
||||||
svc: api.Service{
|
svc: api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Selector: map[string]string{"foo": "bar"},
|
Selector: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
existing: api.ServiceList{
|
existing: api.ServiceList{
|
||||||
Items: []api.Service{
|
Items: []api.Service{
|
||||||
{Port: 80},
|
{Spec: api.ServiceSpec{Port: 80}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user