diff --git a/pkg/api/service/BUILD b/pkg/api/service/BUILD index 995ae5171e4..2fa3a6e54f3 100644 --- a/pkg/api/service/BUILD +++ b/pkg/api/service/BUILD @@ -26,7 +26,6 @@ go_test( deps = [ "//pkg/api:go_default_library", "//pkg/util/net/sets:go_default_library", - "//vendor/github.com/davecgh/go-spew/spew:go_default_library", ], ) diff --git a/pkg/api/service/util.go b/pkg/api/service/util.go index f75be925b59..242aab77f1f 100644 --- a/pkg/api/service/util.go +++ b/pkg/api/service/util.go @@ -77,26 +77,10 @@ func RequestsOnlyLocalTraffic(service *api.Service) bool { return service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyTypeLocal } -// NeedsHealthCheck Check if service needs health check. +// NeedsHealthCheck checks if service needs health check. func NeedsHealthCheck(service *api.Service) bool { if service.Spec.Type != api.ServiceTypeLoadBalancer { return false } return RequestsOnlyLocalTraffic(service) } - -// GetServiceHealthCheckNodePort Return health check node port for service, if one exists -func GetServiceHealthCheckNodePort(service *api.Service) int32 { - return service.Spec.HealthCheckNodePort -} - -// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field. -func ClearExternalTrafficPolicy(service *api.Service) { - service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("") -} - -// SetServiceHealthCheckNodePort sets the given health check node port on service. -// It does not check whether this service needs healthCheckNodePort. -func SetServiceHealthCheckNodePort(service *api.Service, hcNodePort int32) { - service.Spec.HealthCheckNodePort = hcNodePort -} diff --git a/pkg/api/service/util_test.go b/pkg/api/service/util_test.go index 89acbdeea87..c3eb0d1fb9b 100644 --- a/pkg/api/service/util_test.go +++ b/pkg/api/service/util_test.go @@ -20,8 +20,6 @@ import ( "strings" "testing" - "github.com/davecgh/go-spew/spew" - "k8s.io/kubernetes/pkg/api" netsets "k8s.io/kubernetes/pkg/util/net/sets" ) @@ -216,96 +214,3 @@ func TestNeedsHealthCheck(t *testing.T) { }, }) } - -func TestGetServiceHealthCheckNodePort(t *testing.T) { - checkGetServiceHealthCheckNodePort := func(healthCheckNodePort int32, service *api.Service) { - res := GetServiceHealthCheckNodePort(service) - if res != healthCheckNodePort { - t.Errorf("Expected health check node port = %v, got %v", - healthCheckNodePort, res) - } - } - - checkGetServiceHealthCheckNodePort(0, &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeClusterIP, - }, - }) - checkGetServiceHealthCheckNodePort(0, &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeNodePort, - ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeCluster, - }, - }) - checkGetServiceHealthCheckNodePort(0, &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeCluster, - }, - }) - checkGetServiceHealthCheckNodePort(34567, &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeLocal, - HealthCheckNodePort: int32(34567), - }, - }) -} - -func TestClearExternalTrafficPolicy(t *testing.T) { - testCases := []struct { - inputService *api.Service - }{ - // First class fields cases. - { - &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeClusterIP, - ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeCluster, - }, - }, - }, - } - - for i, tc := range testCases { - ClearExternalTrafficPolicy(tc.inputService) - if tc.inputService.Spec.ExternalTrafficPolicy != "" { - t.Errorf("%v: failed to clear ExternalTrafficPolicy", i) - spew.Dump(tc) - } - } -} - -func TestSetServiceHealthCheckNodePort(t *testing.T) { - testCases := []struct { - inputService *api.Service - hcNodePort int32 - }{ - // First class fields cases. - { - &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeClusterIP, - ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeCluster, - }, - }, - 30012, - }, - { - &api.Service{ - Spec: api.ServiceSpec{ - Type: api.ServiceTypeClusterIP, - ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeCluster, - }, - }, - 0, - }, - } - - for i, tc := range testCases { - SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort) - if tc.inputService.Spec.HealthCheckNodePort != tc.hcNodePort { - t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort) - } - } -} diff --git a/pkg/api/v1/service/BUILD b/pkg/api/v1/service/BUILD index 2dd2486996a..3788b24ae57 100644 --- a/pkg/api/v1/service/BUILD +++ b/pkg/api/v1/service/BUILD @@ -25,7 +25,6 @@ go_test( tags = ["automanaged"], deps = [ "//pkg/util/net/sets:go_default_library", - "//vendor/github.com/davecgh/go-spew/spew:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", ], ) diff --git a/pkg/api/v1/service/util.go b/pkg/api/v1/service/util.go index f496f04ca30..4cb453cf3eb 100644 --- a/pkg/api/v1/service/util.go +++ b/pkg/api/v1/service/util.go @@ -76,7 +76,7 @@ func RequestsOnlyLocalTraffic(service *v1.Service) bool { return service.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeLocal } -// NeedsHealthCheck Check if service needs health check. +// NeedsHealthCheck checks if service needs health check. func NeedsHealthCheck(service *v1.Service) bool { if service.Spec.Type != v1.ServiceTypeLoadBalancer { return false @@ -84,28 +84,12 @@ func NeedsHealthCheck(service *v1.Service) bool { return RequestsOnlyLocalTraffic(service) } -// GetServiceHealthCheckNodePort Return health check node port for service, if one exists -func GetServiceHealthCheckNodePort(service *v1.Service) int32 { - return service.Spec.HealthCheckNodePort -} - -// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field. -func ClearExternalTrafficPolicy(service *v1.Service) { - service.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyType("") -} - -// SetServiceHealthCheckNodePort sets the given health check node port on service. -// It does not check whether this service needs healthCheckNodePort. -func SetServiceHealthCheckNodePort(service *v1.Service, hcNodePort int32) { - service.Spec.HealthCheckNodePort = hcNodePort -} - -// GetServiceHealthCheckPathPort Return the path and nodePort programmed into the Cloud LB Health Check +// GetServiceHealthCheckPathPort returns the path and nodePort programmed into the Cloud LB Health Check func GetServiceHealthCheckPathPort(service *v1.Service) (string, int32) { if !NeedsHealthCheck(service) { return "", 0 } - port := GetServiceHealthCheckNodePort(service) + port := service.Spec.HealthCheckNodePort if port == 0 { return "", 0 } diff --git a/pkg/api/v1/service/util_test.go b/pkg/api/v1/service/util_test.go index 943706d2458..df9504cbe6c 100644 --- a/pkg/api/v1/service/util_test.go +++ b/pkg/api/v1/service/util_test.go @@ -20,8 +20,6 @@ import ( "strings" "testing" - "github.com/davecgh/go-spew/spew" - "k8s.io/api/core/v1" netsets "k8s.io/kubernetes/pkg/util/net/sets" ) @@ -216,96 +214,3 @@ func TestNeedsHealthCheck(t *testing.T) { }, }) } - -func TestGetServiceHealthCheckNodePort(t *testing.T) { - checkGetServiceHealthCheckNodePort := func(healthCheckNodePort int32, service *v1.Service) { - res := GetServiceHealthCheckNodePort(service) - if res != healthCheckNodePort { - t.Errorf("Expected health check node port = %v, got %v", - healthCheckNodePort, res) - } - } - - checkGetServiceHealthCheckNodePort(0, &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeClusterIP, - }, - }) - checkGetServiceHealthCheckNodePort(0, &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeNodePort, - ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, - }, - }) - checkGetServiceHealthCheckNodePort(0, &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, - }, - }) - checkGetServiceHealthCheckNodePort(34567, &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal, - HealthCheckNodePort: int32(34567), - }, - }) -} - -func TestClearExternalTrafficPolicy(t *testing.T) { - testCases := []struct { - inputService *v1.Service - }{ - // First class fields cases. - { - &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeClusterIP, - ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, - }, - }, - }, - } - - for i, tc := range testCases { - ClearExternalTrafficPolicy(tc.inputService) - if tc.inputService.Spec.ExternalTrafficPolicy != "" { - t.Errorf("%v: failed to clear ExternalTrafficPolicy", i) - spew.Dump(tc) - } - } -} - -func TestSetServiceHealthCheckNodePort(t *testing.T) { - testCases := []struct { - inputService *v1.Service - hcNodePort int32 - }{ - // First class fields cases. - { - &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeClusterIP, - ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, - }, - }, - 30012, - }, - { - &v1.Service{ - Spec: v1.ServiceSpec{ - Type: v1.ServiceTypeClusterIP, - ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, - }, - }, - 0, - }, - } - - for i, tc := range testCases { - SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort) - if tc.inputService.Spec.HealthCheckNodePort != tc.hcNodePort { - t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort) - } - } -} diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index dda2d9f6de7..aa340e96b91 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -211,7 +211,7 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, se copy(info.externalIPs, service.Spec.ExternalIPs) if apiservice.NeedsHealthCheck(service) { - p := apiservice.GetServiceHealthCheckNodePort(service) + p := service.Spec.HealthCheckNodePort if p == 0 { glog.Errorf("Service %q has no healthcheck nodeport", svcPortName.NamespacedName.String()) } else { diff --git a/pkg/registry/core/service/rest.go b/pkg/registry/core/service/rest.go index 8d4e080b873..46ac0100e37 100644 --- a/pkg/registry/core/service/rest.go +++ b/pkg/registry/core/service/rest.go @@ -183,7 +183,7 @@ func (rs *REST) Delete(ctx genericapirequest.Context, id string) (runtime.Object if utilfeature.DefaultFeatureGate.Enabled(features.ExternalTrafficLocalOnly) && apiservice.NeedsHealthCheck(service) { - nodePort := apiservice.GetServiceHealthCheckNodePort(service) + nodePort := service.Spec.HealthCheckNodePort if nodePort > 0 { err := rs.serviceNodePorts.Release(int(nodePort)) if err != nil { @@ -238,7 +238,7 @@ func externalTrafficPolicyUpdate(oldService, service *api.Service) { } if neededExternalTraffic && !needsExternalTraffic { // Clear ExternalTrafficPolicy to prevent confusion from ineffective field. - apiservice.ClearExternalTrafficPolicy(service) + service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("") } } @@ -246,10 +246,10 @@ func externalTrafficPolicyUpdate(oldService, service *api.Service) { // and adjusts HealthCheckNodePort during service update if needed. func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (bool, error) { neededHealthCheckNodePort := apiservice.NeedsHealthCheck(oldService) - oldHealthCheckNodePort := apiservice.GetServiceHealthCheckNodePort(oldService) + oldHealthCheckNodePort := oldService.Spec.HealthCheckNodePort needsHealthCheckNodePort := apiservice.NeedsHealthCheck(service) - newHealthCheckNodePort := apiservice.GetServiceHealthCheckNodePort(service) + newHealthCheckNodePort := service.Spec.HealthCheckNodePort switch { // Case 1: Transition from don't need HealthCheckNodePort to needs HealthCheckNodePort. @@ -272,7 +272,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo } glog.Infof("Freed health check nodePort: %d", oldHealthCheckNodePort) // Clear the HealthCheckNodePort field. - apiservice.SetServiceHealthCheckNodePort(service, 0) + service.Spec.HealthCheckNodePort = 0 // Case 3: Remain in needs HealthCheckNodePort. // Reject changing the value of the HealthCheckNodePort field. @@ -475,7 +475,7 @@ func findRequestedNodePort(port int, servicePorts []api.ServicePort) int { // allocateHealthCheckNodePort allocates health check node port to service. func (rs *REST) allocateHealthCheckNodePort(service *api.Service) error { - healthCheckNodePort := apiservice.GetServiceHealthCheckNodePort(service) + healthCheckNodePort := service.Spec.HealthCheckNodePort if healthCheckNodePort != 0 { // If the request has a health check nodePort in mind, attempt to reserve it. err := rs.serviceNodePorts.Allocate(int(healthCheckNodePort)) @@ -490,7 +490,7 @@ func (rs *REST) allocateHealthCheckNodePort(service *api.Service) error { if err != nil { return fmt.Errorf("failed to allocate a HealthCheck NodePort %v: %v", healthCheckNodePort, err) } - apiservice.SetServiceHealthCheckNodePort(service, int32(healthCheckNodePort)) + service.Spec.HealthCheckNodePort = int32(healthCheckNodePort) glog.Infof("Reserved allocated nodePort: %d", healthCheckNodePort) } return nil diff --git a/pkg/registry/core/service/rest_test.go b/pkg/registry/core/service/rest_test.go index 6d3d8b738c3..a3fba863597 100644 --- a/pkg/registry/core/service/rest_test.go +++ b/pkg/registry/core/service/rest_test.go @@ -993,7 +993,7 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing. if !service.NeedsHealthCheck(created_service) { t.Errorf("Expecting health check needed, returned health check not needed instead") } - port := service.GetServiceHealthCheckNodePort(created_service) + port := created_service.Spec.HealthCheckNodePort if port == 0 { t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort") } else { @@ -1031,7 +1031,7 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test if !service.NeedsHealthCheck(created_service) { t.Errorf("Expecting health check needed, returned health check not needed instead") } - port := service.GetServiceHealthCheckNodePort(created_service) + port := created_service.Spec.HealthCheckNodePort if port == 0 { t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort") } @@ -1098,7 +1098,7 @@ func TestServiceRegistryExternalTrafficGlobal(t *testing.T) { t.Errorf("Expecting health check not needed, returned health check needed instead") } // Make sure the service does not have the health check node port allocated - port := service.GetServiceHealthCheckNodePort(created_service) + port := created_service.Spec.HealthCheckNodePort if port != 0 { // Release the node port at the end of the test case. storage.serviceNodePorts.Release(int(port)) diff --git a/test/e2e/framework/BUILD b/test/e2e/framework/BUILD index 972c0b5db56..1b90a0fd1b0 100644 --- a/test/e2e/framework/BUILD +++ b/test/e2e/framework/BUILD @@ -48,7 +48,6 @@ go_library( "//pkg/api/v1/helper:go_default_library", "//pkg/api/v1/node:go_default_library", "//pkg/api/v1/pod:go_default_library", - "//pkg/api/v1/service:go_default_library", "//pkg/apis/batch:go_default_library", "//pkg/apis/componentconfig:go_default_library", "//pkg/apis/extensions:go_default_library", diff --git a/test/e2e/framework/firewall_util.go b/test/e2e/framework/firewall_util.go index 3fea73df8b8..d253fd87806 100644 --- a/test/e2e/framework/firewall_util.go +++ b/test/e2e/framework/firewall_util.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" - apiservice "k8s.io/kubernetes/pkg/api/v1/service" "k8s.io/kubernetes/pkg/cloudprovider" gcecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/gce" @@ -87,7 +86,7 @@ func ConstructHealthCheckFirewallForLBService(clusterID string, svc *v1.Service, fw.SourceRanges = gcecloud.LoadBalancerSrcRanges() healthCheckPort := gcecloud.GetNodesHealthCheckPort() if !isNodesHealthCheck { - healthCheckPort = apiservice.GetServiceHealthCheckNodePort(svc) + healthCheckPort = svc.Spec.HealthCheckNodePort } fw.Allowed = []*compute.FirewallAllowed{ { diff --git a/test/e2e/network/BUILD b/test/e2e/network/BUILD index 4d33ef3873b..56ffad73220 100644 --- a/test/e2e/network/BUILD +++ b/test/e2e/network/BUILD @@ -31,7 +31,6 @@ go_library( deps = [ "//pkg/api:go_default_library", "//pkg/api/testapi:go_default_library", - "//pkg/api/v1/service:go_default_library", "//pkg/apis/networking:go_default_library", "//pkg/client/clientset_generated/internalclientset:go_default_library", "//pkg/cloudprovider:go_default_library", diff --git a/test/e2e/network/service.go b/test/e2e/network/service.go index 6de1f54c945..eee7dc663a1 100644 --- a/test/e2e/network/service.go +++ b/test/e2e/network/service.go @@ -29,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" - "k8s.io/kubernetes/pkg/api/v1/service" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" "k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/controller/endpoint" @@ -1454,7 +1453,7 @@ var _ = SIGDescribe("ESIPP [Slow]", func() { svc := jig.CreateOnlyLocalLoadBalancerService(namespace, serviceName, loadBalancerCreateTimeout, true, nil) serviceLBNames = append(serviceLBNames, cloudprovider.GetLoadBalancerName(svc)) - healthCheckNodePort := int(service.GetServiceHealthCheckNodePort(svc)) + healthCheckNodePort := int(svc.Spec.HealthCheckNodePort) if healthCheckNodePort == 0 { framework.Failf("Service HealthCheck NodePort was not allocated") } @@ -1531,7 +1530,7 @@ var _ = SIGDescribe("ESIPP [Slow]", func() { Expect(cs.Core().Services(svc.Namespace).Delete(svc.Name, nil)).NotTo(HaveOccurred()) }() - healthCheckNodePort := int(service.GetServiceHealthCheckNodePort(svc)) + healthCheckNodePort := int(svc.Spec.HealthCheckNodePort) if healthCheckNodePort == 0 { framework.Failf("Service HealthCheck NodePort was not allocated") } @@ -1636,13 +1635,13 @@ var _ = SIGDescribe("ESIPP [Slow]", func() { }() // save the health check node port because it disappears when ESIPP is turned off. - healthCheckNodePort := int(service.GetServiceHealthCheckNodePort(svc)) + healthCheckNodePort := int(svc.Spec.HealthCheckNodePort) By("turning ESIPP off") svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) { svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeCluster }) - if service.GetServiceHealthCheckNodePort(svc) > 0 { + if svc.Spec.HealthCheckNodePort > 0 { framework.Failf("Service HealthCheck NodePort still present") }