Merge pull request #50224 from xiangpengzhao/remove-beta-annotations
Automatic merge from submit-queue Remove deprecated ESIPP beta annotations **What this PR does / why we need it**: Remove deprecated ESIPP beta annotations. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50187 **Special notes for your reviewer**: /assign @MrHohn /sig network **Release note**: ```release-note Beta annotations `service.beta.kubernetes.io/external-traffic` and `service.beta.kubernetes.io/healthcheck-nodeport` have been removed. Please use fields `service.spec.externalTrafficPolicy` and `service.spec.healthCheckNodePort` instead. ```
This commit is contained in:
@@ -115,10 +115,7 @@ func SetDefaults_Service(obj *v1.Service) {
|
||||
}
|
||||
// Defaults ExternalTrafficPolicy field for NodePort / LoadBalancer service
|
||||
// to Global for consistency.
|
||||
if _, ok := obj.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||
// Don't default this field if beta annotation exists.
|
||||
return
|
||||
} else if (obj.Spec.Type == v1.ServiceTypeNodePort ||
|
||||
if (obj.Spec.Type == v1.ServiceTypeNodePort ||
|
||||
obj.Spec.Type == v1.ServiceTypeLoadBalancer) &&
|
||||
obj.Spec.ExternalTrafficPolicy == "" {
|
||||
obj.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeCluster
|
||||
|
@@ -896,18 +896,6 @@ func TestSetDefaulServiceExternalTraffic(t *testing.T) {
|
||||
if out.Spec.ExternalTrafficPolicy != v1.ServiceExternalTrafficPolicyTypeCluster {
|
||||
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) {
|
||||
|
@@ -14,7 +14,6 @@ go_library(
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/util/net/sets:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -26,9 +25,7 @@ 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",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
@@ -18,13 +18,10 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
netsets "k8s.io/kubernetes/pkg/util/net/sets"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -76,25 +73,10 @@ func RequestsOnlyLocalTraffic(service *v1.Service) bool {
|
||||
service.Spec.Type != v1.ServiceTypeNodePort {
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -102,56 +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 {
|
||||
// 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
|
||||
}
|
||||
|
||||
// ClearExternalTrafficPolicy resets the ExternalTrafficPolicy field.
|
||||
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("")
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
@@ -17,16 +17,11 @@ limitations under the License.
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
netsets "k8s.io/kubernetes/pkg/util/net/sets"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
@@ -218,200 +213,4 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
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) {
|
||||
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),
|
||||
},
|
||||
})
|
||||
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) {
|
||||
testCases := []struct {
|
||||
inputService *v1.Service
|
||||
}{
|
||||
// First class fields cases.
|
||||
{
|
||||
&v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Type: v1.ServiceTypeClusterIP,
|
||||
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
|
||||
},
|
||||
},
|
||||
},
|
||||
// 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 {
|
||||
ClearExternalTrafficPolicy(tc.inputService)
|
||||
if _, ok := tc.inputService.Annotations[v1.BetaAnnotationExternalTraffic]; ok ||
|
||||
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
|
||||
beta bool
|
||||
}{
|
||||
// First class fields cases.
|
||||
{
|
||||
&v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Type: v1.ServiceTypeClusterIP,
|
||||
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
|
||||
},
|
||||
},
|
||||
30012,
|
||||
false,
|
||||
},
|
||||
{
|
||||
&v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Type: v1.ServiceTypeClusterIP,
|
||||
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
|
||||
},
|
||||
},
|
||||
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 {
|
||||
SetServiceHealthCheckNodePort(tc.inputService, tc.hcNodePort)
|
||||
if !tc.beta {
|
||||
if 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user