mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Merge pull request #33957 from bprashanth/esipp-beta
Automatic merge from submit-queue Loadbalanced client src ip preservation enters beta Sounds like we're going to try out the proposal (https://github.com/kubernetes/kubernetes/issues/30819#issuecomment-249877334) for annotations -> fields on just one feature in 1.5 (scheduler). Or do we want to just convert to fields right now?
This commit is contained in:
@@ -161,10 +161,10 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
||||
if shouldCheckOrAssignHealthCheckNodePort(service) {
|
||||
var healthCheckNodePort int
|
||||
var err error
|
||||
if l, ok := service.Annotations[apiservice.AnnotationHealthCheckNodePort]; ok {
|
||||
if l, ok := service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
healthCheckNodePort, err = strconv.Atoi(l)
|
||||
if err != nil || healthCheckNodePort <= 0 {
|
||||
return nil, errors.NewInternalError(fmt.Errorf("Failed to parse annotation %v: %v", apiservice.AnnotationHealthCheckNodePort, err))
|
||||
return nil, errors.NewInternalError(fmt.Errorf("Failed to parse annotation %v: %v", apiservice.BetaAnnotationHealthCheckNodePort, err))
|
||||
}
|
||||
}
|
||||
if healthCheckNodePort > 0 {
|
||||
@@ -183,7 +183,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
||||
return nil, errors.NewInternalError(fmt.Errorf("failed to allocate a nodePort: %v", err))
|
||||
}
|
||||
// Insert the newly allocated health check port as an annotation (plan of record for Alpha)
|
||||
service.Annotations[apiservice.AnnotationHealthCheckNodePort] = fmt.Sprintf("%d", healthCheckNodePort)
|
||||
service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", healthCheckNodePort)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
|
||||
errmsg := fmt.Sprintf("Failed to allocate requested HealthCheck nodePort %v:%v",
|
||||
requestedHealthCheckNodePort, err)
|
||||
el := field.ErrorList{field.Invalid(field.NewPath("metadata", "annotations"),
|
||||
apiservice.AnnotationHealthCheckNodePort, errmsg)}
|
||||
apiservice.BetaAnnotationHealthCheckNodePort, errmsg)}
|
||||
return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
|
||||
}
|
||||
glog.Infof("Reserved user requested nodePort: %d", requestedHealthCheckNodePort)
|
||||
@@ -327,7 +327,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
|
||||
return false, errors.NewInternalError(fmt.Errorf("failed to allocate a nodePort: %v", err))
|
||||
}
|
||||
// Insert the newly allocated health check port as an annotation (plan of record for Alpha)
|
||||
service.Annotations[apiservice.AnnotationHealthCheckNodePort] = fmt.Sprintf("%d", healthCheckNodePort)
|
||||
service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", healthCheckNodePort)
|
||||
glog.Infof("Reserved health check nodePort: %d", healthCheckNodePort)
|
||||
}
|
||||
|
||||
@@ -338,29 +338,30 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
|
||||
glog.Warningf("Error releasing service health check %s node port %d: %v", service.Name, oldHealthCheckNodePort, err)
|
||||
return false, errors.NewInternalError(fmt.Errorf("failed to free health check nodePort: %v", err))
|
||||
} else {
|
||||
delete(service.Annotations, apiservice.AnnotationHealthCheckNodePort)
|
||||
delete(service.Annotations, apiservice.BetaAnnotationHealthCheckNodePort)
|
||||
delete(service.Annotations, apiservice.AlphaAnnotationHealthCheckNodePort)
|
||||
glog.Infof("Freed health check nodePort: %d", oldHealthCheckNodePort)
|
||||
}
|
||||
|
||||
case !oldServiceHasHealthCheckNodePort && !assignHealthCheckNodePort:
|
||||
if _, ok := service.Annotations[apiservice.AnnotationHealthCheckNodePort]; ok {
|
||||
if _, ok := service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
glog.Warningf("Attempt to insert health check node port annotation DENIED")
|
||||
el := field.ErrorList{field.Invalid(field.NewPath("metadata", "annotations"),
|
||||
apiservice.AnnotationHealthCheckNodePort, "Cannot insert healthcheck nodePort annotation")}
|
||||
apiservice.BetaAnnotationHealthCheckNodePort, "Cannot insert healthcheck nodePort annotation")}
|
||||
return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
|
||||
}
|
||||
|
||||
case oldServiceHasHealthCheckNodePort && assignHealthCheckNodePort:
|
||||
if _, ok := service.Annotations[apiservice.AnnotationHealthCheckNodePort]; !ok {
|
||||
if _, ok := service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]; !ok {
|
||||
glog.Warningf("Attempt to delete health check node port annotation DENIED")
|
||||
el := field.ErrorList{field.Invalid(field.NewPath("metadata", "annotations"),
|
||||
apiservice.AnnotationHealthCheckNodePort, "Cannot delete healthcheck nodePort annotation")}
|
||||
apiservice.BetaAnnotationHealthCheckNodePort, "Cannot delete healthcheck nodePort annotation")}
|
||||
return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
|
||||
}
|
||||
if oldHealthCheckNodePort != requestedHealthCheckNodePort {
|
||||
glog.Warningf("Attempt to change value of health check node port annotation DENIED")
|
||||
el := field.ErrorList{field.Invalid(field.NewPath("metadata", "annotations"),
|
||||
apiservice.AnnotationHealthCheckNodePort, "Cannot change healthcheck nodePort during update")}
|
||||
apiservice.BetaAnnotationHealthCheckNodePort, "Cannot change healthcheck nodePort during update")}
|
||||
return false, errors.NewInvalid(api.Kind("Service"), service.Name, el)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -955,7 +955,7 @@ func TestServiceRegistryExternalTrafficAnnotationHealthCheckNodePortAllocation(t
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.AnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@@ -975,25 +975,25 @@ func TestServiceRegistryExternalTrafficAnnotationHealthCheckNodePortAllocation(t
|
||||
}
|
||||
created_service := created_svc.(*api.Service)
|
||||
if !service.NeedsHealthCheck(created_service) {
|
||||
t.Errorf("Unexpected missing annotation %s", service.AnnotationExternalTraffic)
|
||||
t.Errorf("Unexpected missing annotation %s", service.BetaAnnotationExternalTraffic)
|
||||
}
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
if port == 0 {
|
||||
t.Errorf("Failed to allocate and create the health check node port annotation %s", service.AnnotationHealthCheckNodePort)
|
||||
t.Errorf("Failed to allocate and create the health check node port annotation %s", service.BetaAnnotationHealthCheckNodePort)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Validate using the user specified nodePort when the externalTraffic=OnlyLocal annotation is set
|
||||
// and type is LoadBalancer
|
||||
func TestServiceRegistryExternalTrafficAnnotationHealthCheckNodePortUserAllocation(t *testing.T) {
|
||||
func TestServiceRegistryExternalTrafficBetaAnnotationHealthCheckNodePortUserAllocation(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
storage, _ := NewTestREST(t, nil)
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.AnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.AnnotationHealthCheckNodePort: "30200",
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationHealthCheckNodePort: "30200",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@@ -1013,11 +1013,11 @@ func TestServiceRegistryExternalTrafficAnnotationHealthCheckNodePortUserAllocati
|
||||
}
|
||||
created_service := created_svc.(*api.Service)
|
||||
if !service.NeedsHealthCheck(created_service) {
|
||||
t.Errorf("Unexpected missing annotation %s", service.AnnotationExternalTraffic)
|
||||
t.Errorf("Unexpected missing annotation %s", service.BetaAnnotationExternalTraffic)
|
||||
}
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
if port == 0 {
|
||||
t.Errorf("Failed to allocate and create the health check node port annotation %s", service.AnnotationHealthCheckNodePort)
|
||||
t.Errorf("Failed to allocate and create the health check node port annotation %s", service.BetaAnnotationHealthCheckNodePort)
|
||||
}
|
||||
if port != 30200 {
|
||||
t.Errorf("Failed to allocate requested nodePort expected 30200, got %d", port)
|
||||
@@ -1031,8 +1031,8 @@ func TestServiceRegistryExternalTrafficAnnotationNegative(t *testing.T) {
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.AnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.AnnotationHealthCheckNodePort: "-1",
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationHealthCheckNodePort: "-1",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@@ -1060,7 +1060,7 @@ func TestServiceRegistryExternalTrafficAnnotationGlobal(t *testing.T) {
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.AnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@@ -1081,12 +1081,12 @@ func TestServiceRegistryExternalTrafficAnnotationGlobal(t *testing.T) {
|
||||
created_service := created_svc.(*api.Service)
|
||||
// Make sure the service does not have the annotation
|
||||
if service.NeedsHealthCheck(created_service) {
|
||||
t.Errorf("Unexpected value for annotation %s", service.AnnotationExternalTraffic)
|
||||
t.Errorf("Unexpected value for annotation %s", service.BetaAnnotationExternalTraffic)
|
||||
}
|
||||
// Make sure the service does not have the health check node port allocated
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
if port != 0 {
|
||||
t.Errorf("Unexpected allocation of health check node port annotation %s", service.AnnotationHealthCheckNodePort)
|
||||
t.Errorf("Unexpected allocation of health check node port annotation %s", service.BetaAnnotationHealthCheckNodePort)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1097,7 +1097,7 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.AnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@@ -1119,6 +1119,6 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
|
||||
// Make sure that ClusterIP services do not have the health check node port allocated
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
if port != 0 {
|
||||
t.Errorf("Unexpected allocation of health check node port annotation %s", service.AnnotationHealthCheckNodePort)
|
||||
t.Errorf("Unexpected allocation of health check node port annotation %s", service.BetaAnnotationHealthCheckNodePort)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user