mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Svc REST: Don't call validation directly
The validation is called soon after anyway.
This commit is contained in:
		@@ -4455,6 +4455,7 @@ func ValidateService(service *core.Service) field.ErrorList {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// external traffic fields
 | 
						// external traffic fields
 | 
				
			||||||
	allErrs = append(allErrs, validateServiceExternalTrafficFieldsValue(service)...)
 | 
						allErrs = append(allErrs, validateServiceExternalTrafficFieldsValue(service)...)
 | 
				
			||||||
 | 
						allErrs = append(allErrs, validateServiceExternalTrafficFieldsCombination(service)...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// internal traffic policy field
 | 
						// internal traffic policy field
 | 
				
			||||||
	allErrs = append(allErrs, validateServiceInternalTrafficFieldsValue(service)...)
 | 
						allErrs = append(allErrs, validateServiceInternalTrafficFieldsValue(service)...)
 | 
				
			||||||
@@ -4545,11 +4546,11 @@ func validateServiceInternalTrafficFieldsValue(service *core.Service) field.Erro
 | 
				
			|||||||
	return allErrs
 | 
						return allErrs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ValidateServiceExternalTrafficFieldsCombination validates if ExternalTrafficPolicy,
 | 
					// validateServiceExternalTrafficFieldsCombination validates if ExternalTrafficPolicy,
 | 
				
			||||||
// HealthCheckNodePort and Type combination are legal. For update, it should be called
 | 
					// HealthCheckNodePort and Type combination are legal. For update, it should be called
 | 
				
			||||||
// after clearing externalTraffic related fields for the ease of transitioning between
 | 
					// after clearing externalTraffic related fields for the ease of transitioning between
 | 
				
			||||||
// different service types.
 | 
					// different service types.
 | 
				
			||||||
func ValidateServiceExternalTrafficFieldsCombination(service *core.Service) field.ErrorList {
 | 
					func validateServiceExternalTrafficFieldsCombination(service *core.Service) field.ErrorList {
 | 
				
			||||||
	allErrs := field.ErrorList{}
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if service.Spec.Type != core.ServiceTypeLoadBalancer &&
 | 
						if service.Spec.Type != core.ServiceTypeLoadBalancer &&
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12019,7 +12019,8 @@ func TestValidateServiceExternalTrafficFieldsCombination(t *testing.T) {
 | 
				
			|||||||
	for _, tc := range testCases {
 | 
						for _, tc := range testCases {
 | 
				
			||||||
		svc := makeValidService()
 | 
							svc := makeValidService()
 | 
				
			||||||
		tc.tweakSvc(&svc)
 | 
							tc.tweakSvc(&svc)
 | 
				
			||||||
		errs := ValidateServiceExternalTrafficFieldsCombination(&svc)
 | 
							// TODO: This test is probably insufficient for such a big function under test.
 | 
				
			||||||
 | 
							errs := validateServiceExternalTrafficFieldsCombination(&svc)
 | 
				
			||||||
		if len(errs) != tc.numErrs {
 | 
							if len(errs) != tc.numErrs {
 | 
				
			||||||
			t.Errorf("Unexpected error list for case %q: %v", tc.name, errs.ToAggregate())
 | 
								t.Errorf("Unexpected error list for case %q: %v", tc.name, errs.ToAggregate())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,6 @@ import (
 | 
				
			|||||||
	"k8s.io/klog/v2"
 | 
						"k8s.io/klog/v2"
 | 
				
			||||||
	apiservice "k8s.io/kubernetes/pkg/api/service"
 | 
						apiservice "k8s.io/kubernetes/pkg/api/service"
 | 
				
			||||||
	api "k8s.io/kubernetes/pkg/apis/core"
 | 
						api "k8s.io/kubernetes/pkg/apis/core"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/apis/core/validation"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/features"
 | 
						"k8s.io/kubernetes/pkg/features"
 | 
				
			||||||
	registry "k8s.io/kubernetes/pkg/registry/core/service"
 | 
						registry "k8s.io/kubernetes/pkg/registry/core/service"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
 | 
						"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
 | 
				
			||||||
@@ -230,9 +229,6 @@ func (rs *REST) Create(ctx context.Context, obj runtime.Object, createValidation
 | 
				
			|||||||
			return nil, errors.NewInternalError(err)
 | 
								return nil, errors.NewInternalError(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if errs := validation.ValidateServiceExternalTrafficFieldsCombination(service); len(errs) > 0 {
 | 
					 | 
				
			||||||
		return nil, errors.NewInvalid(api.Kind("Service"), service.Name, errs)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	out, err := rs.services.Create(ctx, service, createValidation, options)
 | 
						out, err := rs.services.Create(ctx, service, createValidation, options)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -468,9 +464,6 @@ func (rs *REST) Update(ctx context.Context, name string, objInfo rest.UpdatedObj
 | 
				
			|||||||
	if !success || err != nil {
 | 
						if !success || err != nil {
 | 
				
			||||||
		return nil, false, err
 | 
							return nil, false, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if errs := validation.ValidateServiceExternalTrafficFieldsCombination(service); len(errs) > 0 {
 | 
					 | 
				
			||||||
		return nil, false, errors.NewInvalid(api.Kind("Service"), service.Name, errs)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	out, created, err := rs.services.Update(ctx, service.Name, rest.DefaultUpdatedObjectInfo(service), createValidation, updateValidation, forceAllowCreate, options)
 | 
						out, created, err := rs.services.Update(ctx, service.Name, rest.DefaultUpdatedObjectInfo(service), createValidation, updateValidation, forceAllowCreate, options)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user