mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Remove deprecated ESIPP beta annotations
This commit is contained in:
		@@ -89,20 +89,4 @@ const (
 | 
				
			|||||||
	//
 | 
						//
 | 
				
			||||||
	// Not all cloud providers support this annotation, though AWS & GCE do.
 | 
						// Not all cloud providers support this annotation, though AWS & GCE do.
 | 
				
			||||||
	AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
 | 
						AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// AnnotationValueExternalTrafficLocal Value of annotation to specify local endpoints behavior.
 | 
					 | 
				
			||||||
	AnnotationValueExternalTrafficLocal = "OnlyLocal"
 | 
					 | 
				
			||||||
	// AnnotationValueExternalTrafficGlobal Value of annotation to specify global (legacy) behavior.
 | 
					 | 
				
			||||||
	AnnotationValueExternalTrafficGlobal = "Global"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// TODO: The beta annotations have been deprecated, remove them when we release k8s 1.8.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// BetaAnnotationHealthCheckNodePort Annotation specifying the healthcheck nodePort for the service.
 | 
					 | 
				
			||||||
	// If not specified, annotation is created by the service api backend with the allocated nodePort.
 | 
					 | 
				
			||||||
	// Will use user-specified nodePort value if specified by the client.
 | 
					 | 
				
			||||||
	BetaAnnotationHealthCheckNodePort = "service.beta.kubernetes.io/healthcheck-nodeport"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// BetaAnnotationExternalTraffic An annotation that denotes if this Service desires to route
 | 
					 | 
				
			||||||
	// external traffic to local endpoints only. This preserves Source IP and avoids a second hop.
 | 
					 | 
				
			||||||
	BetaAnnotationExternalTraffic = "service.beta.kubernetes.io/external-traffic"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,6 @@ go_library(
 | 
				
			|||||||
    deps = [
 | 
					    deps = [
 | 
				
			||||||
        "//pkg/api:go_default_library",
 | 
					        "//pkg/api:go_default_library",
 | 
				
			||||||
        "//pkg/util/net/sets:go_default_library",
 | 
					        "//pkg/util/net/sets:go_default_library",
 | 
				
			||||||
        "//vendor/github.com/golang/glog:go_default_library",
 | 
					 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -28,7 +27,6 @@ go_test(
 | 
				
			|||||||
        "//pkg/api:go_default_library",
 | 
					        "//pkg/api:go_default_library",
 | 
				
			||||||
        "//pkg/util/net/sets:go_default_library",
 | 
					        "//pkg/util/net/sets:go_default_library",
 | 
				
			||||||
        "//vendor/github.com/davecgh/go-spew/spew:go_default_library",
 | 
					        "//vendor/github.com/davecgh/go-spew/spew:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
					 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,13 +18,10 @@ package service
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
						netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/golang/glog"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -77,20 +74,6 @@ func RequestsOnlyLocalTraffic(service *api.Service) bool {
 | 
				
			|||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if l, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		switch l {
 | 
					 | 
				
			||||||
		case api.AnnotationValueExternalTrafficLocal:
 | 
					 | 
				
			||||||
			return true
 | 
					 | 
				
			||||||
		case api.AnnotationValueExternalTrafficGlobal:
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			glog.Errorf("Invalid value for annotation %v: %v", api.BetaAnnotationExternalTraffic, l)
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyTypeLocal
 | 
						return service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyTypeLocal
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -104,45 +87,16 @@ func NeedsHealthCheck(service *api.Service) bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// GetServiceHealthCheckNodePort Return health check node port for service, if one exists
 | 
					// GetServiceHealthCheckNodePort Return health check node port for service, if one exists
 | 
				
			||||||
func GetServiceHealthCheckNodePort(service *api.Service) int32 {
 | 
					func GetServiceHealthCheckNodePort(service *api.Service) int32 {
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if l, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
 | 
					 | 
				
			||||||
		p, err := strconv.Atoi(l)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			glog.Errorf("Failed to parse annotation %v: %v", api.BetaAnnotationHealthCheckNodePort, err)
 | 
					 | 
				
			||||||
			return 0
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return int32(p)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return service.Spec.HealthCheckNodePort
 | 
						return service.Spec.HealthCheckNodePort
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field.
 | 
					// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field.
 | 
				
			||||||
func ClearExternalTrafficPolicy(service *api.Service) {
 | 
					func ClearExternalTrafficPolicy(service *api.Service) {
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if _, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		delete(service.Annotations, api.BetaAnnotationExternalTraffic)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("")
 | 
						service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SetServiceHealthCheckNodePort sets the given health check node port on service.
 | 
					// SetServiceHealthCheckNodePort sets the given health check node port on service.
 | 
				
			||||||
// It does not check whether this service needs healthCheckNodePort.
 | 
					// It does not check whether this service needs healthCheckNodePort.
 | 
				
			||||||
func SetServiceHealthCheckNodePort(service *api.Service, hcNodePort int32) {
 | 
					func SetServiceHealthCheckNodePort(service *api.Service, hcNodePort int32) {
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if _, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		if hcNodePort == 0 {
 | 
					 | 
				
			||||||
			delete(service.Annotations, api.BetaAnnotationHealthCheckNodePort)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			service.Annotations[api.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	service.Spec.HealthCheckNodePort = hcNodePort
 | 
						service.Spec.HealthCheckNodePort = hcNodePort
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,16 +17,13 @@ limitations under the License.
 | 
				
			|||||||
package service
 | 
					package service
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"fmt"
 | 
						"github.com/davecgh/go-spew/spew"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
						netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/davecgh/go-spew/spew"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
 | 
					func TestGetLoadBalancerSourceRanges(t *testing.T) {
 | 
				
			||||||
@@ -218,37 +215,6 @@ func TestNeedsHealthCheck(t *testing.T) {
 | 
				
			|||||||
			ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeLocal,
 | 
								ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeLocal,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					 | 
				
			||||||
	checkNeedsHealthCheck(false, &api.Service{
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic: "invalid",
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	checkNeedsHealthCheck(false, &api.Service{
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	checkNeedsHealthCheck(true, &api.Service{
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetServiceHealthCheckNodePort(t *testing.T) {
 | 
					func TestGetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			||||||
@@ -284,17 +250,6 @@ func TestGetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
			HealthCheckNodePort:   int32(34567),
 | 
								HealthCheckNodePort:   int32(34567),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	checkGetServiceHealthCheckNodePort(34567, &api.Service{
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic:     api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
				api.BetaAnnotationHealthCheckNodePort: "34567",
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClearExternalTrafficPolicy(t *testing.T) {
 | 
					func TestClearExternalTrafficPolicy(t *testing.T) {
 | 
				
			||||||
@@ -310,25 +265,11 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		// Beta annotations cases.
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			&api.Service{
 | 
					 | 
				
			||||||
				Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
					Type: api.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
					Annotations: map[string]string{
 | 
					 | 
				
			||||||
						api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i, tc := range testCases {
 | 
						for i, tc := range testCases {
 | 
				
			||||||
		ClearExternalTrafficPolicy(tc.inputService)
 | 
							ClearExternalTrafficPolicy(tc.inputService)
 | 
				
			||||||
		if _, ok := tc.inputService.Annotations[api.BetaAnnotationExternalTraffic]; ok ||
 | 
							if tc.inputService.Spec.ExternalTrafficPolicy != "" {
 | 
				
			||||||
			tc.inputService.Spec.ExternalTrafficPolicy != "" {
 | 
					 | 
				
			||||||
			t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
 | 
								t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
 | 
				
			||||||
			spew.Dump(tc)
 | 
								spew.Dump(tc)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -339,7 +280,6 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
	testCases := []struct {
 | 
						testCases := []struct {
 | 
				
			||||||
		inputService *api.Service
 | 
							inputService *api.Service
 | 
				
			||||||
		hcNodePort   int32
 | 
							hcNodePort   int32
 | 
				
			||||||
		beta         bool
 | 
					 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		// First class fields cases.
 | 
							// First class fields cases.
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -350,7 +290,6 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			30012,
 | 
								30012,
 | 
				
			||||||
			false,
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			&api.Service{
 | 
								&api.Service{
 | 
				
			||||||
@@ -360,58 +299,13 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			0,
 | 
								0,
 | 
				
			||||||
			false,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		// Beta annotations cases.
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			&api.Service{
 | 
					 | 
				
			||||||
				Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
					Type: api.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
					Annotations: map[string]string{
 | 
					 | 
				
			||||||
						api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			30012,
 | 
					 | 
				
			||||||
			true,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			&api.Service{
 | 
					 | 
				
			||||||
				Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
					Type: api.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
					Annotations: map[string]string{
 | 
					 | 
				
			||||||
						api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			0,
 | 
					 | 
				
			||||||
			true,
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i, tc := range testCases {
 | 
						for i, tc := range testCases {
 | 
				
			||||||
		SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort)
 | 
							SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort)
 | 
				
			||||||
		if !tc.beta {
 | 
					 | 
				
			||||||
		if tc.inputService.Spec.HealthCheckNodePort != tc.hcNodePort {
 | 
							if tc.inputService.Spec.HealthCheckNodePort != tc.hcNodePort {
 | 
				
			||||||
			t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
 | 
								t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			l, ok := tc.inputService.Annotations[api.BetaAnnotationHealthCheckNodePort]
 | 
					 | 
				
			||||||
			if tc.hcNodePort == 0 {
 | 
					 | 
				
			||||||
				if ok {
 | 
					 | 
				
			||||||
					t.Errorf("%v: HealthCheckNodePort set, want it to be cleared", i)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				if !ok {
 | 
					 | 
				
			||||||
					t.Errorf("%v: HealthCheckNodePort unset, want %v", i, tc.hcNodePort)
 | 
					 | 
				
			||||||
				} else if l != fmt.Sprintf("%v", tc.hcNodePort) {
 | 
					 | 
				
			||||||
					t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, l, tc.hcNodePort)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,10 +115,7 @@ func SetDefaults_Service(obj *v1.Service) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	// Defaults ExternalTrafficPolicy field for NodePort / LoadBalancer service
 | 
						// Defaults ExternalTrafficPolicy field for NodePort / LoadBalancer service
 | 
				
			||||||
	// to Global for consistency.
 | 
						// to Global for consistency.
 | 
				
			||||||
	if _, ok := obj.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
 | 
						if (obj.Spec.Type == v1.ServiceTypeNodePort ||
 | 
				
			||||||
		// Don't default this field if beta annotation exists.
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	} else if (obj.Spec.Type == v1.ServiceTypeNodePort ||
 | 
					 | 
				
			||||||
		obj.Spec.Type == v1.ServiceTypeLoadBalancer) &&
 | 
							obj.Spec.Type == v1.ServiceTypeLoadBalancer) &&
 | 
				
			||||||
		obj.Spec.ExternalTrafficPolicy == "" {
 | 
							obj.Spec.ExternalTrafficPolicy == "" {
 | 
				
			||||||
		obj.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeCluster
 | 
							obj.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeCluster
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -896,18 +896,6 @@ func TestSetDefaulServiceExternalTraffic(t *testing.T) {
 | 
				
			|||||||
	if out.Spec.ExternalTrafficPolicy != v1.ServiceExternalTrafficPolicyTypeCluster {
 | 
						if out.Spec.ExternalTrafficPolicy != v1.ServiceExternalTrafficPolicyTypeCluster {
 | 
				
			||||||
		t.Errorf("Expected ExternalTrafficPolicy to be %v, got %v", v1.ServiceExternalTrafficPolicyTypeCluster, out.Spec.ExternalTrafficPolicy)
 | 
							t.Errorf("Expected ExternalTrafficPolicy to be %v, got %v", v1.ServiceExternalTrafficPolicyTypeCluster, out.Spec.ExternalTrafficPolicy)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	in = &v1.Service{
 | 
					 | 
				
			||||||
		Spec: v1.ServiceSpec{Type: v1.ServiceTypeLoadBalancer},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	obj = roundTrip(t, runtime.Object(in))
 | 
					 | 
				
			||||||
	out = obj.(*v1.Service)
 | 
					 | 
				
			||||||
	if out.Spec.ExternalTrafficPolicy != "" {
 | 
					 | 
				
			||||||
		t.Errorf("Expected ExternalTrafficPolicy to be empty, got %v", out.Spec.ExternalTrafficPolicy)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSetDefaultNamespace(t *testing.T) {
 | 
					func TestSetDefaultNamespace(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,6 @@ go_library(
 | 
				
			|||||||
    tags = ["automanaged"],
 | 
					    tags = ["automanaged"],
 | 
				
			||||||
    deps = [
 | 
					    deps = [
 | 
				
			||||||
        "//pkg/util/net/sets:go_default_library",
 | 
					        "//pkg/util/net/sets:go_default_library",
 | 
				
			||||||
        "//vendor/github.com/golang/glog:go_default_library",
 | 
					 | 
				
			||||||
        "//vendor/k8s.io/api/core/v1:go_default_library",
 | 
					        "//vendor/k8s.io/api/core/v1:go_default_library",
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -28,7 +27,6 @@ go_test(
 | 
				
			|||||||
        "//pkg/util/net/sets:go_default_library",
 | 
					        "//pkg/util/net/sets:go_default_library",
 | 
				
			||||||
        "//vendor/github.com/davecgh/go-spew/spew:go_default_library",
 | 
					        "//vendor/github.com/davecgh/go-spew/spew:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/api/core/v1:go_default_library",
 | 
					        "//vendor/k8s.io/api/core/v1:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
					 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,13 +18,10 @@ package service
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/api/core/v1"
 | 
						"k8s.io/api/core/v1"
 | 
				
			||||||
	netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
						netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/golang/glog"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -76,21 +73,6 @@ func RequestsOnlyLocalTraffic(service *v1.Service) bool {
 | 
				
			|||||||
		service.Spec.Type != v1.ServiceTypeNodePort {
 | 
							service.Spec.Type != v1.ServiceTypeNodePort {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if l, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		switch l {
 | 
					 | 
				
			||||||
		case v1.AnnotationValueExternalTrafficLocal:
 | 
					 | 
				
			||||||
			return true
 | 
					 | 
				
			||||||
		case v1.AnnotationValueExternalTrafficGlobal:
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			glog.Errorf("Invalid value for annotation %v: %v", v1.BetaAnnotationExternalTraffic, l)
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return service.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeLocal
 | 
						return service.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeLocal
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -104,45 +86,17 @@ func NeedsHealthCheck(service *v1.Service) bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// GetServiceHealthCheckNodePort Return health check node port for service, if one exists
 | 
					// GetServiceHealthCheckNodePort Return health check node port for service, if one exists
 | 
				
			||||||
func GetServiceHealthCheckNodePort(service *v1.Service) int32 {
 | 
					func GetServiceHealthCheckNodePort(service *v1.Service) int32 {
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if l, ok := service.Annotations[v1.BetaAnnotationHealthCheckNodePort]; ok {
 | 
					 | 
				
			||||||
		p, err := strconv.Atoi(l)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			glog.Errorf("Failed to parse annotation %v: %v", v1.BetaAnnotationHealthCheckNodePort, err)
 | 
					 | 
				
			||||||
			return 0
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return int32(p)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return service.Spec.HealthCheckNodePort
 | 
						return service.Spec.HealthCheckNodePort
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field.
 | 
					// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field.
 | 
				
			||||||
func ClearExternalTrafficPolicy(service *v1.Service) {
 | 
					func ClearExternalTrafficPolicy(service *v1.Service) {
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so existing
 | 
					 | 
				
			||||||
	// Services continue to work till the user decides to transition to the first class field.
 | 
					 | 
				
			||||||
	if _, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		delete(service.Annotations, v1.BetaAnnotationExternalTraffic)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	service.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyType("")
 | 
						service.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyType("")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SetServiceHealthCheckNodePort sets the given health check node port on service.
 | 
					// SetServiceHealthCheckNodePort sets the given health check node port on service.
 | 
				
			||||||
// It does not check whether this service needs healthCheckNodePort.
 | 
					// It does not check whether this service needs healthCheckNodePort.
 | 
				
			||||||
func SetServiceHealthCheckNodePort(service *v1.Service, hcNodePort int32) {
 | 
					func SetServiceHealthCheckNodePort(service *v1.Service, hcNodePort int32) {
 | 
				
			||||||
	// First check the beta annotation and then the first class field. This is so that
 | 
					 | 
				
			||||||
	// existing Services continue to work till the user decides to transition to the
 | 
					 | 
				
			||||||
	// first class field.
 | 
					 | 
				
			||||||
	if _, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		if hcNodePort == 0 {
 | 
					 | 
				
			||||||
			delete(service.Annotations, v1.BetaAnnotationHealthCheckNodePort)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			service.Annotations[v1.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	service.Spec.HealthCheckNodePort = hcNodePort
 | 
						service.Spec.HealthCheckNodePort = hcNodePort
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,16 +17,13 @@ limitations under the License.
 | 
				
			|||||||
package service
 | 
					package service
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"fmt"
 | 
						"github.com/davecgh/go-spew/spew"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/api/core/v1"
 | 
						"k8s.io/api/core/v1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
					 | 
				
			||||||
	netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
						netsets "k8s.io/kubernetes/pkg/util/net/sets"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/davecgh/go-spew/spew"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
 | 
					func TestGetLoadBalancerSourceRanges(t *testing.T) {
 | 
				
			||||||
@@ -218,37 +215,6 @@ func TestNeedsHealthCheck(t *testing.T) {
 | 
				
			|||||||
			ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal,
 | 
								ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					 | 
				
			||||||
	checkNeedsHealthCheck(false, &v1.Service{
 | 
					 | 
				
			||||||
		Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: v1.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				v1.BetaAnnotationExternalTraffic: "invalid",
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	checkNeedsHealthCheck(false, &v1.Service{
 | 
					 | 
				
			||||||
		Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: v1.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	checkNeedsHealthCheck(true, &v1.Service{
 | 
					 | 
				
			||||||
		Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: v1.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetServiceHealthCheckNodePort(t *testing.T) {
 | 
					func TestGetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			||||||
@@ -284,17 +250,6 @@ func TestGetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
			HealthCheckNodePort:   int32(34567),
 | 
								HealthCheckNodePort:   int32(34567),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	checkGetServiceHealthCheckNodePort(34567, &v1.Service{
 | 
					 | 
				
			||||||
		Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
			Type: v1.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				v1.BetaAnnotationExternalTraffic:     v1.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
				v1.BetaAnnotationHealthCheckNodePort: "34567",
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClearExternalTrafficPolicy(t *testing.T) {
 | 
					func TestClearExternalTrafficPolicy(t *testing.T) {
 | 
				
			||||||
@@ -310,25 +265,11 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		// Beta annotations cases.
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			&v1.Service{
 | 
					 | 
				
			||||||
				Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
					Type: v1.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
					Annotations: map[string]string{
 | 
					 | 
				
			||||||
						v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i, tc := range testCases {
 | 
						for i, tc := range testCases {
 | 
				
			||||||
		ClearExternalTrafficPolicy(tc.inputService)
 | 
							ClearExternalTrafficPolicy(tc.inputService)
 | 
				
			||||||
		if _, ok := tc.inputService.Annotations[v1.BetaAnnotationExternalTraffic]; ok ||
 | 
							if tc.inputService.Spec.ExternalTrafficPolicy != "" {
 | 
				
			||||||
			tc.inputService.Spec.ExternalTrafficPolicy != "" {
 | 
					 | 
				
			||||||
			t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
 | 
								t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
 | 
				
			||||||
			spew.Dump(tc)
 | 
								spew.Dump(tc)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -339,7 +280,6 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
	testCases := []struct {
 | 
						testCases := []struct {
 | 
				
			||||||
		inputService *v1.Service
 | 
							inputService *v1.Service
 | 
				
			||||||
		hcNodePort   int32
 | 
							hcNodePort   int32
 | 
				
			||||||
		beta         bool
 | 
					 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		// First class fields cases.
 | 
							// First class fields cases.
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -350,7 +290,6 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			30012,
 | 
								30012,
 | 
				
			||||||
			false,
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			&v1.Service{
 | 
								&v1.Service{
 | 
				
			||||||
@@ -360,58 +299,13 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			0,
 | 
								0,
 | 
				
			||||||
			false,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		// Beta annotations cases.
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			&v1.Service{
 | 
					 | 
				
			||||||
				Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
					Type: v1.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
					Annotations: map[string]string{
 | 
					 | 
				
			||||||
						v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			30012,
 | 
					 | 
				
			||||||
			true,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			&v1.Service{
 | 
					 | 
				
			||||||
				Spec: v1.ServiceSpec{
 | 
					 | 
				
			||||||
					Type: v1.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
					Annotations: map[string]string{
 | 
					 | 
				
			||||||
						v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			0,
 | 
					 | 
				
			||||||
			true,
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i, tc := range testCases {
 | 
						for i, tc := range testCases {
 | 
				
			||||||
		SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort)
 | 
							SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort)
 | 
				
			||||||
		if !tc.beta {
 | 
					 | 
				
			||||||
		if tc.inputService.Spec.HealthCheckNodePort != tc.hcNodePort {
 | 
							if tc.inputService.Spec.HealthCheckNodePort != tc.hcNodePort {
 | 
				
			||||||
			t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
 | 
								t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			l, ok := tc.inputService.Annotations[v1.BetaAnnotationHealthCheckNodePort]
 | 
					 | 
				
			||||||
			if tc.hcNodePort == 0 {
 | 
					 | 
				
			||||||
				if ok {
 | 
					 | 
				
			||||||
					t.Errorf("%v: HealthCheckNodePort set, want it to be cleared", i)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				if !ok {
 | 
					 | 
				
			||||||
					t.Errorf("%v: HealthCheckNodePort unset, want %v", i, tc.hcNodePort)
 | 
					 | 
				
			||||||
				} else if l != fmt.Sprintf("%v", tc.hcNodePort) {
 | 
					 | 
				
			||||||
					t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, l, tc.hcNodePort)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,7 +24,6 @@ import (
 | 
				
			|||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
@@ -2964,7 +2963,6 @@ func ValidateService(service *api.Service) field.ErrorList {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	allErrs = append(allErrs, validateServiceExternalTrafficFieldsValue(service)...)
 | 
						allErrs = append(allErrs, validateServiceExternalTrafficFieldsValue(service)...)
 | 
				
			||||||
	allErrs = append(allErrs, validateServiceExternalTrafficAPIVersion(service)...)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return allErrs
 | 
						return allErrs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -3012,25 +3010,6 @@ func validateServicePort(sp *api.ServicePort, requireName, isHeadlessService boo
 | 
				
			|||||||
func validateServiceExternalTrafficFieldsValue(service *api.Service) field.ErrorList {
 | 
					func validateServiceExternalTrafficFieldsValue(service *api.Service) field.ErrorList {
 | 
				
			||||||
	allErrs := field.ErrorList{}
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check beta annotations.
 | 
					 | 
				
			||||||
	if l, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
 | 
					 | 
				
			||||||
		if l != api.AnnotationValueExternalTrafficLocal &&
 | 
					 | 
				
			||||||
			l != api.AnnotationValueExternalTrafficGlobal {
 | 
					 | 
				
			||||||
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationExternalTraffic), l,
 | 
					 | 
				
			||||||
				fmt.Sprintf("ExternalTraffic must be %v or %v", api.AnnotationValueExternalTrafficLocal, api.AnnotationValueExternalTrafficGlobal)))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if l, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
 | 
					 | 
				
			||||||
		p, err := strconv.Atoi(l)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort), l,
 | 
					 | 
				
			||||||
				"HealthCheckNodePort must be a valid port number"))
 | 
					 | 
				
			||||||
		} else if p <= 0 {
 | 
					 | 
				
			||||||
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort), l,
 | 
					 | 
				
			||||||
				"HealthCheckNodePort must be greater than 0"))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Check first class fields.
 | 
						// Check first class fields.
 | 
				
			||||||
	if service.Spec.ExternalTrafficPolicy != "" &&
 | 
						if service.Spec.ExternalTrafficPolicy != "" &&
 | 
				
			||||||
		service.Spec.ExternalTrafficPolicy != api.ServiceExternalTrafficPolicyTypeCluster &&
 | 
							service.Spec.ExternalTrafficPolicy != api.ServiceExternalTrafficPolicyTypeCluster &&
 | 
				
			||||||
@@ -3046,54 +3025,6 @@ func validateServiceExternalTrafficFieldsValue(service *api.Service) field.Error
 | 
				
			|||||||
	return allErrs
 | 
						return allErrs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// serviceExternalTrafficStatus stores flags indicating whether ExternalTraffic
 | 
					 | 
				
			||||||
// related beta annotations and GA fields are set on service.
 | 
					 | 
				
			||||||
type serviceExternalTrafficStatus struct {
 | 
					 | 
				
			||||||
	betaExternalTrafficIsSet bool
 | 
					 | 
				
			||||||
	betaHealthCheckIsSet     bool
 | 
					 | 
				
			||||||
	gaExternalTrafficIsSet   bool
 | 
					 | 
				
			||||||
	gaHealthCheckIsSet       bool
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (s *serviceExternalTrafficStatus) useBetaExternalTrafficWithGA() bool {
 | 
					 | 
				
			||||||
	return s.betaExternalTrafficIsSet && (s.gaExternalTrafficIsSet || s.gaHealthCheckIsSet)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (s *serviceExternalTrafficStatus) useBetaHealthCheckWithGA() bool {
 | 
					 | 
				
			||||||
	return s.betaHealthCheckIsSet && (s.gaExternalTrafficIsSet || s.gaHealthCheckIsSet)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getServiceExternalTrafficStatus(service *api.Service) *serviceExternalTrafficStatus {
 | 
					 | 
				
			||||||
	s := serviceExternalTrafficStatus{}
 | 
					 | 
				
			||||||
	_, s.betaExternalTrafficIsSet = service.Annotations[api.BetaAnnotationExternalTraffic]
 | 
					 | 
				
			||||||
	_, s.betaHealthCheckIsSet = service.Annotations[api.BetaAnnotationHealthCheckNodePort]
 | 
					 | 
				
			||||||
	s.gaExternalTrafficIsSet = service.Spec.ExternalTrafficPolicy != ""
 | 
					 | 
				
			||||||
	s.gaHealthCheckIsSet = service.Spec.HealthCheckNodePort != 0
 | 
					 | 
				
			||||||
	return &s
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// validateServiceExternalTrafficAPIVersion checks if user mixes ExternalTraffic
 | 
					 | 
				
			||||||
// API versions.
 | 
					 | 
				
			||||||
func validateServiceExternalTrafficAPIVersion(service *api.Service) field.ErrorList {
 | 
					 | 
				
			||||||
	allErrs := field.ErrorList{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	status := getServiceExternalTrafficStatus(service)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if status.useBetaExternalTrafficWithGA() {
 | 
					 | 
				
			||||||
		fieldPath := field.NewPath("metadata", "annotations").Key(api.BetaAnnotationExternalTraffic)
 | 
					 | 
				
			||||||
		msg := fmt.Sprintf("please replace the beta annotation with 'ExternalTrafficPolicy' field")
 | 
					 | 
				
			||||||
		allErrs = append(allErrs, field.Invalid(fieldPath, api.BetaAnnotationExternalTraffic, msg))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if status.useBetaHealthCheckWithGA() {
 | 
					 | 
				
			||||||
		fieldPath := field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort)
 | 
					 | 
				
			||||||
		msg := fmt.Sprintf("please replace the beta annotation with 'HealthCheckNodePort' field")
 | 
					 | 
				
			||||||
		allErrs = append(allErrs, field.Invalid(fieldPath, api.BetaAnnotationHealthCheckNodePort, msg))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	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
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6450,48 +6450,6 @@ func TestValidateService(t *testing.T) {
 | 
				
			|||||||
			numErrs: 1,
 | 
								numErrs: 1,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		// ESIPP section begins.
 | 
							// ESIPP section begins.
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "LoadBalancer allows onlyLocal beta annotations",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 0,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "invalid externalTraffic beta annotation",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = "invalid"
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "nagative healthCheckNodePort beta annotation",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "-1"
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "invalid healthCheckNodePort beta annotation",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "whatisthis"
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "valid healthCheckNodePort beta annotation",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "31100"
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 0,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "invalid externalTraffic field",
 | 
								name: "invalid externalTraffic field",
 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
								tweakSvc: func(s *api.Service) {
 | 
				
			||||||
@@ -6518,33 +6476,6 @@ func TestValidateService(t *testing.T) {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			numErrs: 0,
 | 
								numErrs: 0,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "disallows use ExternalTraffic beta annotation with first class field",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				s.Spec.HealthCheckNodePort = 3001
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "disallows duplicated ExternalTraffic beta annotation with first class field",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "disallows use HealthCheckNodePort beta annotation with first class field",
 | 
					 | 
				
			||||||
			tweakSvc: func(s *api.Service) {
 | 
					 | 
				
			||||||
				s.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
					 | 
				
			||||||
				s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		// ESIPP section ends.
 | 
							// ESIPP section ends.
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -8005,50 +7936,6 @@ func TestValidateServiceUpdate(t *testing.T) {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			numErrs: 1,
 | 
								numErrs: 1,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "Service allows removing onlyLocal beta annotations",
 | 
					 | 
				
			||||||
			tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 0,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "Service allows modifying onlyLocal beta annotations",
 | 
					 | 
				
			||||||
			tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
					 | 
				
			||||||
				oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
 | 
					 | 
				
			||||||
				newSvc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				newSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficGlobal
 | 
					 | 
				
			||||||
				newSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort]
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 0,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "Service disallows promoting one of the onlyLocal pair to GA",
 | 
					 | 
				
			||||||
			tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
					 | 
				
			||||||
				oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
 | 
					 | 
				
			||||||
				newSvc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
					 | 
				
			||||||
				newSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort]
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 1,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "Service allows changing both onlyLocal annotations from beta to GA",
 | 
					 | 
				
			||||||
			tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
					 | 
				
			||||||
				oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
					 | 
				
			||||||
				oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
 | 
					 | 
				
			||||||
				newSvc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
					 | 
				
			||||||
				newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
					 | 
				
			||||||
				newSvc.Spec.HealthCheckNodePort = 3001
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			numErrs: 0,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "`None` ClusterIP cannot be changed",
 | 
								name: "`None` ClusterIP cannot be changed",
 | 
				
			||||||
			tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
								tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -867,7 +867,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
 | 
				
			|||||||
			svc.Status.LoadBalancer.Ingress = []api.LoadBalancerIngress{{
 | 
								svc.Status.LoadBalancer.Ingress = []api.LoadBalancerIngress{{
 | 
				
			||||||
				IP: svcLBIP,
 | 
									IP: svcLBIP,
 | 
				
			||||||
			}}
 | 
								}}
 | 
				
			||||||
			svc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
								svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -958,7 +958,7 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
 | 
				
			|||||||
				Protocol: api.ProtocolTCP,
 | 
									Protocol: api.ProtocolTCP,
 | 
				
			||||||
				NodePort: int32(svcNodePort),
 | 
									NodePort: int32(svcNodePort),
 | 
				
			||||||
			}}
 | 
								}}
 | 
				
			||||||
			svc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
 | 
								svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1069,10 +1069,6 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
		makeTestService("somewhere", "only-local-load-balancer", func(svc *api.Service) {
 | 
							makeTestService("somewhere", "only-local-load-balancer", func(svc *api.Service) {
 | 
				
			||||||
			svc.ObjectMeta.Annotations = map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic:     api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
				api.BetaAnnotationHealthCheckNodePort: "345",
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			svc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
								svc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
				
			||||||
			svc.Spec.ClusterIP = "172.16.55.12"
 | 
								svc.Spec.ClusterIP = "172.16.55.12"
 | 
				
			||||||
			svc.Spec.LoadBalancerIP = "5.6.7.8"
 | 
								svc.Spec.LoadBalancerIP = "5.6.7.8"
 | 
				
			||||||
@@ -1083,6 +1079,8 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
 | 
				
			|||||||
					{IP: "10.1.2.3"},
 | 
										{IP: "10.1.2.3"},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
				
			||||||
 | 
								svc.Spec.HealthCheckNodePort = 345
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1214,10 +1212,6 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
 | 
				
			|||||||
		svc.Spec.Ports = addTestPort(svc.Spec.Ports, "somethingelse", "TCP", 1235, 5321, 0)
 | 
							svc.Spec.Ports = addTestPort(svc.Spec.Ports, "somethingelse", "TCP", 1235, 5321, 0)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	servicev2 := makeTestService("somewhere", "some-service", func(svc *api.Service) {
 | 
						servicev2 := makeTestService("somewhere", "some-service", func(svc *api.Service) {
 | 
				
			||||||
		svc.ObjectMeta.Annotations = map[string]string{
 | 
					 | 
				
			||||||
			api.BetaAnnotationExternalTraffic:     api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
			api.BetaAnnotationHealthCheckNodePort: "345",
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		svc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
							svc.Spec.Type = api.ServiceTypeLoadBalancer
 | 
				
			||||||
		svc.Spec.ClusterIP = "172.16.55.4"
 | 
							svc.Spec.ClusterIP = "172.16.55.4"
 | 
				
			||||||
		svc.Spec.LoadBalancerIP = "5.6.7.8"
 | 
							svc.Spec.LoadBalancerIP = "5.6.7.8"
 | 
				
			||||||
@@ -1228,6 +1222,8 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
 | 
				
			|||||||
				{IP: "10.1.2.3"},
 | 
									{IP: "10.1.2.3"},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
 | 
				
			||||||
 | 
							svc.Spec.HealthCheckNodePort = 345
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fp.OnServiceAdd(servicev1)
 | 
						fp.OnServiceAdd(servicev1)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -279,12 +279,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
 | 
				
			|||||||
	case neededHealthCheckNodePort && needsHealthCheckNodePort:
 | 
						case neededHealthCheckNodePort && needsHealthCheckNodePort:
 | 
				
			||||||
		if oldHealthCheckNodePort != newHealthCheckNodePort {
 | 
							if oldHealthCheckNodePort != newHealthCheckNodePort {
 | 
				
			||||||
			glog.Warningf("Attempt to change value of health check node port DENIED")
 | 
								glog.Warningf("Attempt to change value of health check node port DENIED")
 | 
				
			||||||
			var fldPath *field.Path
 | 
								fldPath := field.NewPath("spec", "healthCheckNodePort")
 | 
				
			||||||
			if _, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
 | 
					 | 
				
			||||||
				fldPath = field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort)
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				fldPath = field.NewPath("spec", "healthCheckNodePort")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			el := field.ErrorList{field.Invalid(fldPath, newHealthCheckNodePort,
 | 
								el := field.ErrorList{field.Invalid(fldPath, newHealthCheckNodePort,
 | 
				
			||||||
				"cannot change healthCheckNodePort on loadBalancer service with externalTraffic=Local during update")}
 | 
									"cannot change healthCheckNodePort on loadBalancer service with externalTraffic=Local during update")}
 | 
				
			||||||
			return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
 | 
								return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ package service
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -1003,46 +1002,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing.
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate allocation of a nodePort when ExternalTraffic beta annotation is set to OnlyLocal
 | 
					 | 
				
			||||||
// and type is LoadBalancer.
 | 
					 | 
				
			||||||
func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocationBeta(t *testing.T) {
 | 
					 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
					 | 
				
			||||||
	storage, _ := NewTestREST(t, nil)
 | 
					 | 
				
			||||||
	svc := &api.Service{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Name: "external-lb-esipp",
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Selector:        map[string]string{"bar": "baz"},
 | 
					 | 
				
			||||||
			SessionAffinity: api.ServiceAffinityNone,
 | 
					 | 
				
			||||||
			Type:            api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
			Ports: []api.ServicePort{{
 | 
					 | 
				
			||||||
				Port:       6502,
 | 
					 | 
				
			||||||
				Protocol:   api.ProtocolTCP,
 | 
					 | 
				
			||||||
				TargetPort: intstr.FromInt(6502),
 | 
					 | 
				
			||||||
			}},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_svc, err := storage.Create(ctx, svc, false)
 | 
					 | 
				
			||||||
	if created_svc == nil || err != nil {
 | 
					 | 
				
			||||||
		t.Errorf("Unexpected failure creating service %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_service := created_svc.(*api.Service)
 | 
					 | 
				
			||||||
	if !service.NeedsHealthCheck(created_service) {
 | 
					 | 
				
			||||||
		t.Errorf("Expecting health check needed, returned health check not needed instead")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	port := service.GetServiceHealthCheckNodePort(created_service)
 | 
					 | 
				
			||||||
	if port == 0 {
 | 
					 | 
				
			||||||
		t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		// Release the node port at the end of the test case.
 | 
					 | 
				
			||||||
		storage.serviceNodePorts.Release(int(port))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
 | 
					// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
 | 
				
			||||||
// and type is LoadBalancer.
 | 
					// and type is LoadBalancer.
 | 
				
			||||||
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *testing.T) {
 | 
					func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *testing.T) {
 | 
				
			||||||
@@ -1086,53 +1045,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate using the user specified nodePort when ExternalTraffic beta annotation is set to OnlyLocal
 | 
					 | 
				
			||||||
// and type is LoadBalancer.
 | 
					 | 
				
			||||||
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocationBeta(t *testing.T) {
 | 
					 | 
				
			||||||
	randomNodePort := generateRandomNodePort()
 | 
					 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
					 | 
				
			||||||
	storage, _ := NewTestREST(t, nil)
 | 
					 | 
				
			||||||
	svc := &api.Service{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Name: "external-lb-esipp",
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic:     api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
				api.BetaAnnotationHealthCheckNodePort: fmt.Sprintf("%v", randomNodePort),
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Selector:        map[string]string{"bar": "baz"},
 | 
					 | 
				
			||||||
			SessionAffinity: api.ServiceAffinityNone,
 | 
					 | 
				
			||||||
			Type:            api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
			Ports: []api.ServicePort{{
 | 
					 | 
				
			||||||
				Port:       6502,
 | 
					 | 
				
			||||||
				Protocol:   api.ProtocolTCP,
 | 
					 | 
				
			||||||
				TargetPort: intstr.FromInt(6502),
 | 
					 | 
				
			||||||
			}},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_svc, err := storage.Create(ctx, svc, false)
 | 
					 | 
				
			||||||
	if created_svc == nil || err != nil {
 | 
					 | 
				
			||||||
		t.Fatalf("Unexpected failure creating service :%v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_service := created_svc.(*api.Service)
 | 
					 | 
				
			||||||
	if !service.NeedsHealthCheck(created_service) {
 | 
					 | 
				
			||||||
		t.Errorf("Expecting health check needed, returned health check not needed instead")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	port := service.GetServiceHealthCheckNodePort(created_service)
 | 
					 | 
				
			||||||
	if port == 0 {
 | 
					 | 
				
			||||||
		t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if port != randomNodePort {
 | 
					 | 
				
			||||||
		t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if port != 0 {
 | 
					 | 
				
			||||||
		// Release the node port at the end of the test case.
 | 
					 | 
				
			||||||
		storage.serviceNodePorts.Release(int(port))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Validate that the service creation fails when the requested port number is -1.
 | 
					// Validate that the service creation fails when the requested port number is -1.
 | 
				
			||||||
func TestServiceRegistryExternalTrafficHealthCheckNodePortNegative(t *testing.T) {
 | 
					func TestServiceRegistryExternalTrafficHealthCheckNodePortNegative(t *testing.T) {
 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
						ctx := genericapirequest.NewDefaultContext()
 | 
				
			||||||
@@ -1159,36 +1071,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortNegative(t *testing.T)
 | 
				
			|||||||
	t.Errorf("Unexpected creation of service with invalid HealthCheckNodePort specified")
 | 
						t.Errorf("Unexpected creation of service with invalid HealthCheckNodePort specified")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate that the service creation fails when the requested port number in beta annotation is -1.
 | 
					 | 
				
			||||||
func TestServiceRegistryExternalTrafficHealthCheckNodePortNegativeBeta(t *testing.T) {
 | 
					 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
					 | 
				
			||||||
	storage, _ := NewTestREST(t, nil)
 | 
					 | 
				
			||||||
	svc := &api.Service{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Name: "external-lb-esipp",
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic:     api.AnnotationValueExternalTrafficLocal,
 | 
					 | 
				
			||||||
				api.BetaAnnotationHealthCheckNodePort: "-1",
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Selector:        map[string]string{"bar": "baz"},
 | 
					 | 
				
			||||||
			SessionAffinity: api.ServiceAffinityNone,
 | 
					 | 
				
			||||||
			Type:            api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
			Ports: []api.ServicePort{{
 | 
					 | 
				
			||||||
				Port:       6502,
 | 
					 | 
				
			||||||
				Protocol:   api.ProtocolTCP,
 | 
					 | 
				
			||||||
				TargetPort: intstr.FromInt(6502),
 | 
					 | 
				
			||||||
			}},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_svc, err := storage.Create(ctx, svc, false)
 | 
					 | 
				
			||||||
	if created_svc == nil || err != nil {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	t.Errorf("Unexpected creation of service with invalid HealthCheckNodePort specified")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Validate that the health check nodePort is not allocated when ExternalTrafficPolicy is set to Global.
 | 
					// Validate that the health check nodePort is not allocated when ExternalTrafficPolicy is set to Global.
 | 
				
			||||||
func TestServiceRegistryExternalTrafficGlobal(t *testing.T) {
 | 
					func TestServiceRegistryExternalTrafficGlobal(t *testing.T) {
 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
						ctx := genericapirequest.NewDefaultContext()
 | 
				
			||||||
@@ -1224,80 +1106,6 @@ func TestServiceRegistryExternalTrafficGlobal(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate that the health check nodePort is not allocated when ExternalTraffic beta annotation is set to Global.
 | 
					 | 
				
			||||||
func TestServiceRegistryExternalTrafficGlobalBeta(t *testing.T) {
 | 
					 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
					 | 
				
			||||||
	storage, _ := NewTestREST(t, nil)
 | 
					 | 
				
			||||||
	svc := &api.Service{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Name: "external-lb-esipp",
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Selector:        map[string]string{"bar": "baz"},
 | 
					 | 
				
			||||||
			SessionAffinity: api.ServiceAffinityNone,
 | 
					 | 
				
			||||||
			Type:            api.ServiceTypeLoadBalancer,
 | 
					 | 
				
			||||||
			Ports: []api.ServicePort{{
 | 
					 | 
				
			||||||
				Port:       6502,
 | 
					 | 
				
			||||||
				Protocol:   api.ProtocolTCP,
 | 
					 | 
				
			||||||
				TargetPort: intstr.FromInt(6502),
 | 
					 | 
				
			||||||
			}},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_svc, err := storage.Create(ctx, svc, false)
 | 
					 | 
				
			||||||
	if created_svc == nil || err != nil {
 | 
					 | 
				
			||||||
		t.Errorf("Unexpected failure creating service %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_service := created_svc.(*api.Service)
 | 
					 | 
				
			||||||
	if service.NeedsHealthCheck(created_service) {
 | 
					 | 
				
			||||||
		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)
 | 
					 | 
				
			||||||
	if port != 0 {
 | 
					 | 
				
			||||||
		// Release the node port at the end of the test case.
 | 
					 | 
				
			||||||
		storage.serviceNodePorts.Release(int(port))
 | 
					 | 
				
			||||||
		t.Errorf("Unexpected allocation of health check node port: %v", port)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Validate that the health check nodePort is not allocated when service type is ClusterIP
 | 
					 | 
				
			||||||
func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
 | 
					 | 
				
			||||||
	ctx := genericapirequest.NewDefaultContext()
 | 
					 | 
				
			||||||
	storage, _ := NewTestREST(t, nil)
 | 
					 | 
				
			||||||
	svc := &api.Service{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{Name: "external-lb-esipp",
 | 
					 | 
				
			||||||
			Annotations: map[string]string{
 | 
					 | 
				
			||||||
				api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
					 | 
				
			||||||
			Selector:        map[string]string{"bar": "baz"},
 | 
					 | 
				
			||||||
			SessionAffinity: api.ServiceAffinityNone,
 | 
					 | 
				
			||||||
			Type:            api.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
			Ports: []api.ServicePort{{
 | 
					 | 
				
			||||||
				Port:       6502,
 | 
					 | 
				
			||||||
				Protocol:   api.ProtocolTCP,
 | 
					 | 
				
			||||||
				TargetPort: intstr.FromInt(6502),
 | 
					 | 
				
			||||||
			}},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_svc, err := storage.Create(ctx, svc, false)
 | 
					 | 
				
			||||||
	if created_svc == nil || err != nil {
 | 
					 | 
				
			||||||
		t.Errorf("Unexpected failure creating service %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	created_service := created_svc.(*api.Service)
 | 
					 | 
				
			||||||
	// Make sure that ClusterIP services do not have the health check node port allocated
 | 
					 | 
				
			||||||
	port := service.GetServiceHealthCheckNodePort(created_service)
 | 
					 | 
				
			||||||
	if port != 0 {
 | 
					 | 
				
			||||||
		// Release the node port at the end of the test case.
 | 
					 | 
				
			||||||
		storage.serviceNodePorts.Release(int(port))
 | 
					 | 
				
			||||||
		t.Errorf("Unexpected allocation of health check node port annotation %s", api.BetaAnnotationHealthCheckNodePort)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestInitClusterIP(t *testing.T) {
 | 
					func TestInitClusterIP(t *testing.T) {
 | 
				
			||||||
	storage, _ := NewTestREST(t, nil)
 | 
						storage, _ := NewTestREST(t, nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,20 +89,4 @@ const (
 | 
				
			|||||||
	//
 | 
						//
 | 
				
			||||||
	// Not all cloud providers support this annotation, though AWS & GCE do.
 | 
						// Not all cloud providers support this annotation, though AWS & GCE do.
 | 
				
			||||||
	AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
 | 
						AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// AnnotationValueExternalTrafficLocal Value of annotation to specify local endpoints behavior.
 | 
					 | 
				
			||||||
	AnnotationValueExternalTrafficLocal = "OnlyLocal"
 | 
					 | 
				
			||||||
	// AnnotationValueExternalTrafficGlobal Value of annotation to specify global (legacy) behavior.
 | 
					 | 
				
			||||||
	AnnotationValueExternalTrafficGlobal = "Global"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// TODO: The beta annotations have been deprecated, remove them when we release k8s 1.8.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// BetaAnnotationHealthCheckNodePort Annotation specifying the healthcheck nodePort for the service.
 | 
					 | 
				
			||||||
	// If not specified, annotation is created by the service api backend with the allocated nodePort.
 | 
					 | 
				
			||||||
	// Will use user-specified nodePort value if specified by the client.
 | 
					 | 
				
			||||||
	BetaAnnotationHealthCheckNodePort = "service.beta.kubernetes.io/healthcheck-nodeport"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// BetaAnnotationExternalTraffic An annotation that denotes if this Service desires to route
 | 
					 | 
				
			||||||
	// external traffic to local endpoints only. This preserves Source IP and avoids a second hop.
 | 
					 | 
				
			||||||
	BetaAnnotationExternalTraffic = "service.beta.kubernetes.io/external-traffic"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user