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:
@@ -183,7 +183,7 @@ func (rs *REST) Delete(ctx genericapirequest.Context, id string) (runtime.Object
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.ExternalTrafficLocalOnly) &&
|
||||
apiservice.NeedsHealthCheck(service) {
|
||||
nodePort := apiservice.GetServiceHealthCheckNodePort(service)
|
||||
nodePort := service.Spec.HealthCheckNodePort
|
||||
if nodePort > 0 {
|
||||
err := rs.serviceNodePorts.Release(int(nodePort))
|
||||
if err != nil {
|
||||
@@ -238,7 +238,7 @@ func externalTrafficPolicyUpdate(oldService, service *api.Service) {
|
||||
}
|
||||
if neededExternalTraffic && !needsExternalTraffic {
|
||||
// Clear ExternalTrafficPolicy to prevent confusion from ineffective field.
|
||||
apiservice.ClearExternalTrafficPolicy(service)
|
||||
service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,10 +246,10 @@ func externalTrafficPolicyUpdate(oldService, service *api.Service) {
|
||||
// and adjusts HealthCheckNodePort during service update if needed.
|
||||
func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (bool, error) {
|
||||
neededHealthCheckNodePort := apiservice.NeedsHealthCheck(oldService)
|
||||
oldHealthCheckNodePort := apiservice.GetServiceHealthCheckNodePort(oldService)
|
||||
oldHealthCheckNodePort := oldService.Spec.HealthCheckNodePort
|
||||
|
||||
needsHealthCheckNodePort := apiservice.NeedsHealthCheck(service)
|
||||
newHealthCheckNodePort := apiservice.GetServiceHealthCheckNodePort(service)
|
||||
newHealthCheckNodePort := service.Spec.HealthCheckNodePort
|
||||
|
||||
switch {
|
||||
// Case 1: Transition from don't need HealthCheckNodePort to needs HealthCheckNodePort.
|
||||
@@ -272,19 +272,14 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
|
||||
}
|
||||
glog.Infof("Freed health check nodePort: %d", oldHealthCheckNodePort)
|
||||
// Clear the HealthCheckNodePort field.
|
||||
apiservice.SetServiceHealthCheckNodePort(service, 0)
|
||||
service.Spec.HealthCheckNodePort = 0
|
||||
|
||||
// Case 3: Remain in needs HealthCheckNodePort.
|
||||
// Reject changing the value of the HealthCheckNodePort field.
|
||||
case neededHealthCheckNodePort && needsHealthCheckNodePort:
|
||||
if oldHealthCheckNodePort != newHealthCheckNodePort {
|
||||
glog.Warningf("Attempt to change value of health check node port DENIED")
|
||||
var fldPath *field.Path
|
||||
if _, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
fldPath = field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort)
|
||||
} else {
|
||||
fldPath = field.NewPath("spec", "healthCheckNodePort")
|
||||
}
|
||||
fldPath := field.NewPath("spec", "healthCheckNodePort")
|
||||
el := field.ErrorList{field.Invalid(fldPath, newHealthCheckNodePort,
|
||||
"cannot change healthCheckNodePort on loadBalancer service with externalTraffic=Local during update")}
|
||||
return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
|
||||
@@ -480,7 +475,7 @@ func findRequestedNodePort(port int, servicePorts []api.ServicePort) int {
|
||||
|
||||
// allocateHealthCheckNodePort allocates health check node port to service.
|
||||
func (rs *REST) allocateHealthCheckNodePort(service *api.Service) error {
|
||||
healthCheckNodePort := apiservice.GetServiceHealthCheckNodePort(service)
|
||||
healthCheckNodePort := service.Spec.HealthCheckNodePort
|
||||
if healthCheckNodePort != 0 {
|
||||
// If the request has a health check nodePort in mind, attempt to reserve it.
|
||||
err := rs.serviceNodePorts.Allocate(int(healthCheckNodePort))
|
||||
@@ -495,7 +490,7 @@ func (rs *REST) allocateHealthCheckNodePort(service *api.Service) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to allocate a HealthCheck NodePort %v: %v", healthCheckNodePort, err)
|
||||
}
|
||||
apiservice.SetServiceHealthCheckNodePort(service, int32(healthCheckNodePort))
|
||||
service.Spec.HealthCheckNodePort = int32(healthCheckNodePort)
|
||||
glog.Infof("Reserved allocated nodePort: %d", healthCheckNodePort)
|
||||
}
|
||||
return nil
|
||||
|
@@ -19,7 +19,6 @@ package service
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -994,47 +993,7 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing.
|
||||
if !service.NeedsHealthCheck(created_service) {
|
||||
t.Errorf("Expecting health check needed, returned health check not needed instead")
|
||||
}
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
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 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)
|
||||
port := created_service.Spec.HealthCheckNodePort
|
||||
if port == 0 {
|
||||
t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
|
||||
} else {
|
||||
@@ -1072,54 +1031,7 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
|
||||
if !service.NeedsHealthCheck(created_service) {
|
||||
t.Errorf("Expecting health check needed, returned health check not needed instead")
|
||||
}
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
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 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)
|
||||
port := created_service.Spec.HealthCheckNodePort
|
||||
if port == 0 {
|
||||
t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
|
||||
}
|
||||
@@ -1159,36 +1071,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortNegative(t *testing.T)
|
||||
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.
|
||||
func TestServiceRegistryExternalTrafficGlobal(t *testing.T) {
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
@@ -1216,7 +1098,7 @@ func TestServiceRegistryExternalTrafficGlobal(t *testing.T) {
|
||||
t.Errorf("Expecting health check not needed, returned health check needed instead")
|
||||
}
|
||||
// Make sure the service does not have the health check node port allocated
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
port := created_service.Spec.HealthCheckNodePort
|
||||
if port != 0 {
|
||||
// Release the node port at the end of the test case.
|
||||
storage.serviceNodePorts.Release(int(port))
|
||||
@@ -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) {
|
||||
storage, _ := NewTestREST(t, nil)
|
||||
|
||||
|
Reference in New Issue
Block a user