mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Mixed protocol support for Services with type=LoadBalancer (#94028)
* Mixed protocol support for Services with type=LoadBalancer KEP: https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20200103-mixed-protocol-lb.md Add new feature gate to control the support of mixed protocols in Services with type=LoadBalancer Add new fields to the ServiceStatus Add Ports to the LoadBalancerIngress, so cloud provider implementations can report the status of the requested load balanc er ports Add ServiceCondition to the ServiceStatus so Service controllers can indicate the conditions of the Service * regenerate conflicting stuff
This commit is contained in:
parent
0081e0ebf5
commit
c970a46bc1
81
api/openapi-spec/swagger.json
generated
81
api/openapi-spec/swagger.json
generated
@ -7337,6 +7337,14 @@
|
||||
"ip": {
|
||||
"description": "IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)",
|
||||
"type": "string"
|
||||
},
|
||||
"ports": {
|
||||
"description": "Ports is a list of records of service ports If used, every port defined in the service should have an entry in it",
|
||||
"items": {
|
||||
"$ref": "#/definitions/io.k8s.api.core.v1.PortStatus"
|
||||
},
|
||||
"type": "array",
|
||||
"x-kubernetes-list-type": "atomic"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
@ -9081,6 +9089,28 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"io.k8s.api.core.v1.PortStatus": {
|
||||
"properties": {
|
||||
"error": {
|
||||
"description": "Error is to record the problem with the service port The format of the error shall comply with the following rules: - built-in error values shall be specified in this file and those shall use\n CamelCase names\n- cloud provider specific error values must have names that comply with the\n format foo.example.com/CamelCase.",
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"description": "Port is the port number of the service port of which status is recorded here",
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"protocol": {
|
||||
"description": "Protocol is the protocol of the service port of which status is recorded here The supported values are: \"TCP\", \"UDP\", \"SCTP\"",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"port",
|
||||
"protocol"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"io.k8s.api.core.v1.PortworxVolumeSource": {
|
||||
"description": "PortworxVolumeSource represents a Portworx volume resource.",
|
||||
"properties": {
|
||||
@ -10362,6 +10392,19 @@
|
||||
"io.k8s.api.core.v1.ServiceStatus": {
|
||||
"description": "ServiceStatus represents the current status of a service.",
|
||||
"properties": {
|
||||
"conditions": {
|
||||
"description": "Current service state",
|
||||
"items": {
|
||||
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Condition"
|
||||
},
|
||||
"type": "array",
|
||||
"x-kubernetes-list-map-keys": [
|
||||
"type"
|
||||
],
|
||||
"x-kubernetes-list-type": "map",
|
||||
"x-kubernetes-patch-merge-key": "type",
|
||||
"x-kubernetes-patch-strategy": "merge"
|
||||
},
|
||||
"loadBalancer": {
|
||||
"$ref": "#/definitions/io.k8s.api.core.v1.LoadBalancerStatus",
|
||||
"description": "LoadBalancer contains the current status of the load-balancer, if one is present."
|
||||
@ -17749,6 +17792,44 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.Condition": {
|
||||
"description": "Condition contains details for one aspect of the current state of this API Resource.",
|
||||
"properties": {
|
||||
"lastTransitionTime": {
|
||||
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Time",
|
||||
"description": "lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable."
|
||||
},
|
||||
"message": {
|
||||
"description": "message is a human readable message indicating details about the transition. This may be an empty string.",
|
||||
"type": "string"
|
||||
},
|
||||
"observedGeneration": {
|
||||
"description": "observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.",
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"reason": {
|
||||
"description": "reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.",
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"description": "status of the condition, one of True, False, Unknown.",
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"description": "type of condition in CamelCase or in foo.example.com/CamelCase.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"status",
|
||||
"lastTransitionTime",
|
||||
"reason",
|
||||
"message"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions": {
|
||||
"description": "DeleteOptions may be provided when deleting an API object.",
|
||||
"properties": {
|
||||
|
@ -3475,12 +3475,23 @@ const (
|
||||
ServiceExternalTrafficPolicyTypeCluster ServiceExternalTrafficPolicyType = "Cluster"
|
||||
)
|
||||
|
||||
// These are the valid conditions of a service.
|
||||
const (
|
||||
// LoadBalancerPortsError represents the condition of the requested ports
|
||||
// on the cloud load balancer instance.
|
||||
LoadBalancerPortsError = "LoadBalancerPortsError"
|
||||
)
|
||||
|
||||
// ServiceStatus represents the current status of a service
|
||||
type ServiceStatus struct {
|
||||
// LoadBalancer contains the current status of the load-balancer,
|
||||
// if one is present.
|
||||
// +optional
|
||||
LoadBalancer LoadBalancerStatus
|
||||
|
||||
// Current service condition
|
||||
// +optional
|
||||
Conditions []metav1.Condition
|
||||
}
|
||||
|
||||
// LoadBalancerStatus represents the status of a load-balancer
|
||||
@ -3503,6 +3514,11 @@ type LoadBalancerIngress struct {
|
||||
// (typically AWS load-balancers)
|
||||
// +optional
|
||||
Hostname string
|
||||
|
||||
// Ports is a list of records of service ports
|
||||
// If used, every port defined in the service should have an entry in it
|
||||
// +optional
|
||||
Ports []PortStatus
|
||||
}
|
||||
|
||||
const (
|
||||
@ -5395,3 +5411,32 @@ type TopologySpreadConstraint struct {
|
||||
// +optional
|
||||
LabelSelector *metav1.LabelSelector
|
||||
}
|
||||
|
||||
// These are the built-in errors for PortStatus.
|
||||
const (
|
||||
// MixedProtocolNotSupported error in PortStatus means that the cloud provider
|
||||
// can't ensure the port on the load balancer because mixed values of protocols
|
||||
// on the same LoadBalancer type of Service are not supported by the cloud provider.
|
||||
MixedProtocolNotSupported = "MixedProtocolNotSupported"
|
||||
)
|
||||
|
||||
// PortStatus represents the error condition of a service port
|
||||
type PortStatus struct {
|
||||
// Port is the port number of the service port of which status is recorded here
|
||||
Port int32
|
||||
// Protocol is the protocol of the service port of which status is recorded here
|
||||
Protocol Protocol
|
||||
// Error is to record the problem with the service port
|
||||
// The format of the error shall comply with the following rules:
|
||||
// - built-in error values shall be specified in this file and those shall use
|
||||
// CamelCase names
|
||||
// - cloud provider specific error values must have names that comply with the
|
||||
// format foo.example.com/CamelCase.
|
||||
// ---
|
||||
// The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
|
||||
// +optional
|
||||
// +kubebuilder:validation:Required
|
||||
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
|
||||
// +kubebuilder:validation:MaxLength=316
|
||||
Error *string
|
||||
}
|
||||
|
38
pkg/apis/core/v1/zz_generated.conversion.go
generated
38
pkg/apis/core/v1/zz_generated.conversion.go
generated
@ -1391,6 +1391,16 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*v1.PortStatus)(nil), (*core.PortStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_PortStatus_To_core_PortStatus(a.(*v1.PortStatus), b.(*core.PortStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*core.PortStatus)(nil), (*v1.PortStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_core_PortStatus_To_v1_PortStatus(a.(*core.PortStatus), b.(*v1.PortStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*v1.PortworxVolumeSource)(nil), (*core.PortworxVolumeSource)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_PortworxVolumeSource_To_core_PortworxVolumeSource(a.(*v1.PortworxVolumeSource), b.(*core.PortworxVolumeSource), scope)
|
||||
}); err != nil {
|
||||
@ -4291,6 +4301,7 @@ func Convert_core_List_To_v1_List(in *core.List, out *v1.List, s conversion.Scop
|
||||
func autoConvert_v1_LoadBalancerIngress_To_core_LoadBalancerIngress(in *v1.LoadBalancerIngress, out *core.LoadBalancerIngress, s conversion.Scope) error {
|
||||
out.IP = in.IP
|
||||
out.Hostname = in.Hostname
|
||||
out.Ports = *(*[]core.PortStatus)(unsafe.Pointer(&in.Ports))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -4302,6 +4313,7 @@ func Convert_v1_LoadBalancerIngress_To_core_LoadBalancerIngress(in *v1.LoadBalan
|
||||
func autoConvert_core_LoadBalancerIngress_To_v1_LoadBalancerIngress(in *core.LoadBalancerIngress, out *v1.LoadBalancerIngress, s conversion.Scope) error {
|
||||
out.IP = in.IP
|
||||
out.Hostname = in.Hostname
|
||||
out.Ports = *(*[]v1.PortStatus)(unsafe.Pointer(&in.Ports))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -6322,6 +6334,30 @@ func autoConvert_core_PodTemplateSpec_To_v1_PodTemplateSpec(in *core.PodTemplate
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1_PortStatus_To_core_PortStatus(in *v1.PortStatus, out *core.PortStatus, s conversion.Scope) error {
|
||||
out.Port = in.Port
|
||||
out.Protocol = core.Protocol(in.Protocol)
|
||||
out.Error = (*string)(unsafe.Pointer(in.Error))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert_v1_PortStatus_To_core_PortStatus is an autogenerated conversion function.
|
||||
func Convert_v1_PortStatus_To_core_PortStatus(in *v1.PortStatus, out *core.PortStatus, s conversion.Scope) error {
|
||||
return autoConvert_v1_PortStatus_To_core_PortStatus(in, out, s)
|
||||
}
|
||||
|
||||
func autoConvert_core_PortStatus_To_v1_PortStatus(in *core.PortStatus, out *v1.PortStatus, s conversion.Scope) error {
|
||||
out.Port = in.Port
|
||||
out.Protocol = v1.Protocol(in.Protocol)
|
||||
out.Error = (*string)(unsafe.Pointer(in.Error))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert_core_PortStatus_To_v1_PortStatus is an autogenerated conversion function.
|
||||
func Convert_core_PortStatus_To_v1_PortStatus(in *core.PortStatus, out *v1.PortStatus, s conversion.Scope) error {
|
||||
return autoConvert_core_PortStatus_To_v1_PortStatus(in, out, s)
|
||||
}
|
||||
|
||||
func autoConvert_v1_PortworxVolumeSource_To_core_PortworxVolumeSource(in *v1.PortworxVolumeSource, out *core.PortworxVolumeSource, s conversion.Scope) error {
|
||||
out.VolumeID = in.VolumeID
|
||||
out.FSType = in.FSType
|
||||
@ -7636,6 +7672,7 @@ func autoConvert_v1_ServiceStatus_To_core_ServiceStatus(in *v1.ServiceStatus, ou
|
||||
if err := Convert_v1_LoadBalancerStatus_To_core_LoadBalancerStatus(&in.LoadBalancer, &out.LoadBalancer, s); err != nil {
|
||||
return err
|
||||
}
|
||||
out.Conditions = *(*[]metav1.Condition)(unsafe.Pointer(&in.Conditions))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -7648,6 +7685,7 @@ func autoConvert_core_ServiceStatus_To_v1_ServiceStatus(in *core.ServiceStatus,
|
||||
if err := Convert_core_LoadBalancerStatus_To_v1_LoadBalancerStatus(&in.LoadBalancer, &out.LoadBalancer, s); err != nil {
|
||||
return err
|
||||
}
|
||||
out.Conditions = *(*[]metav1.Condition)(unsafe.Pointer(&in.Conditions))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ load(
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"conditional_validation.go",
|
||||
"doc.go",
|
||||
"events.go",
|
||||
"validation.go",
|
||||
@ -48,6 +49,7 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"conditional_validation_test.go",
|
||||
"events_test.go",
|
||||
"validation_test.go",
|
||||
],
|
||||
|
61
pkg/apis/core/validation/conditional_validation.go
Normal file
61
pkg/apis/core/validation/conditional_validation.go
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
// ValidateConditionalService validates conditionally valid fields.
|
||||
func ValidateConditionalService(service, oldService *api.Service) field.ErrorList {
|
||||
var errs field.ErrorList
|
||||
|
||||
errs = append(errs, validateMixedProtocolLBService(service, oldService)...)
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
// validateMixedProtocolLBService checks if the old Service has type=LoadBalancer and whether the Service has different Protocols
|
||||
// on its ports. If the MixedProtocolLBService feature flag is disabled the usage of different Protocols in the new Service is
|
||||
// valid only if the old Service has different Protocols, too.
|
||||
func validateMixedProtocolLBService(service, oldService *api.Service) (errs field.ErrorList) {
|
||||
if service.Spec.Type != api.ServiceTypeLoadBalancer {
|
||||
return
|
||||
}
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.MixedProtocolLBService) {
|
||||
return
|
||||
}
|
||||
|
||||
if serviceHasMixedProtocols(service) && !serviceHasMixedProtocols(oldService) {
|
||||
errs = append(errs, field.Invalid(field.NewPath("spec", "ports"), service.Spec.Ports, "may not contain more than 1 protocol when type is 'LoadBalancer'"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func serviceHasMixedProtocols(service *api.Service) bool {
|
||||
if service == nil {
|
||||
return false
|
||||
}
|
||||
protos := map[string]bool{}
|
||||
for _, port := range service.Spec.Ports {
|
||||
protos[string(port.Protocol)] = true
|
||||
}
|
||||
return len(protos) > 1
|
||||
}
|
277
pkg/apis/core/validation/conditional_validation_test.go
Normal file
277
pkg/apis/core/validation/conditional_validation_test.go
Normal file
@ -0,0 +1,277 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
func TestValidateMixedProtocolLBService(t *testing.T) {
|
||||
newLBServiceDifferentProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
newLBServiceSameProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
newNonLBServiceDifferentProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeNodePort,
|
||||
},
|
||||
}
|
||||
newNonLBServiceSameProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeNodePort,
|
||||
},
|
||||
}
|
||||
oldLBServiceDifferentProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
oldLBServiceSameProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
oldNonLBServiceDifferentProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeNodePort,
|
||||
},
|
||||
}
|
||||
oldNonLBServiceSameProtocols := &api.Service{
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
{
|
||||
Protocol: api.ProtocolUDP,
|
||||
},
|
||||
},
|
||||
Type: api.ServiceTypeNodePort,
|
||||
},
|
||||
}
|
||||
cases := map[string]struct {
|
||||
oldService *api.Service
|
||||
newService *api.Service
|
||||
fgEnabled bool
|
||||
expectedError []string
|
||||
}{
|
||||
"Old service is nil, new service has different protocols, feature gate false": {
|
||||
oldService: nil,
|
||||
newService: newLBServiceDifferentProtocols,
|
||||
fgEnabled: false,
|
||||
expectedError: []string{`spec.ports: Invalid value: []core.ServicePort{core.ServicePort{Name:"", Protocol:"TCP", AppProtocol:(*string)(nil), Port:0, TargetPort:intstr.IntOrString{Type:0, IntVal:0, StrVal:""}, NodePort:0}, core.ServicePort{Name:"", Protocol:"UDP", AppProtocol:(*string)(nil), Port:0, TargetPort:intstr.IntOrString{Type:0, IntVal:0, StrVal:""}, NodePort:0}}: may not contain more than 1 protocol when type is 'LoadBalancer'`},
|
||||
},
|
||||
"Old service is nil, new service has different protocols, feature gate true": {
|
||||
oldService: nil,
|
||||
newService: newLBServiceDifferentProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Old service is nil, new service does not have different protocols, feature gate false": {
|
||||
oldService: nil,
|
||||
newService: newLBServiceSameProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Old service is nil, new service does not have different protocols, feature gate true": {
|
||||
oldService: nil,
|
||||
newService: newLBServiceSameProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Old service is nil, new non-LB service has different protocols, feature gate false": {
|
||||
oldService: nil,
|
||||
newService: newNonLBServiceDifferentProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Old service is nil, new non-LB service has different protocols, feature gate true": {
|
||||
oldService: nil,
|
||||
newService: newNonLBServiceDifferentProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Old service is nil, new non-LB service does not have different protocols, feature gate false": {
|
||||
oldService: nil,
|
||||
newService: newNonLBServiceSameProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Old service is nil, new non-LB service does not have different protocols, feature gate true": {
|
||||
oldService: nil,
|
||||
newService: newNonLBServiceSameProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Non-LB services, both services have different protocols, feature gate false": {
|
||||
oldService: oldNonLBServiceDifferentProtocols,
|
||||
newService: newNonLBServiceDifferentProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Non-LB services, old service has same protocols, new service has different protocols, feature gate false": {
|
||||
oldService: oldNonLBServiceSameProtocols,
|
||||
newService: newNonLBServiceDifferentProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Non-LB services, old service has different protocols, new service has identical protocols, feature gate false": {
|
||||
oldService: oldNonLBServiceDifferentProtocols,
|
||||
newService: newNonLBServiceSameProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Non-LB services, both services have same protocols, feature gate false": {
|
||||
oldService: oldNonLBServiceSameProtocols,
|
||||
newService: newNonLBServiceSameProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"Non-LB services, both services have different protocols, feature gate true": {
|
||||
oldService: oldNonLBServiceDifferentProtocols,
|
||||
newService: newNonLBServiceDifferentProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Non-LB services, old service has same protocols, new service has different protocols, feature gate true": {
|
||||
oldService: oldNonLBServiceSameProtocols,
|
||||
newService: newNonLBServiceDifferentProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Non-LB services, old service has different protocols, new service has identical protocols, feature gate true": {
|
||||
oldService: oldNonLBServiceDifferentProtocols,
|
||||
newService: newNonLBServiceSameProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"Non-LB services, both services have same protocols, feature gate true": {
|
||||
oldService: oldNonLBServiceSameProtocols,
|
||||
newService: newNonLBServiceSameProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"LB service, neither service has different protocols, feature gate false": {
|
||||
oldService: oldLBServiceSameProtocols,
|
||||
newService: newLBServiceSameProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"LB service, old service does not have different protocols, new service has different protocols, feature gate false": {
|
||||
oldService: oldLBServiceSameProtocols,
|
||||
newService: newLBServiceDifferentProtocols,
|
||||
fgEnabled: false,
|
||||
expectedError: []string{`spec.ports: Invalid value: []core.ServicePort{core.ServicePort{Name:"", Protocol:"TCP", AppProtocol:(*string)(nil), Port:0, TargetPort:intstr.IntOrString{Type:0, IntVal:0, StrVal:""}, NodePort:0}, core.ServicePort{Name:"", Protocol:"UDP", AppProtocol:(*string)(nil), Port:0, TargetPort:intstr.IntOrString{Type:0, IntVal:0, StrVal:""}, NodePort:0}}: may not contain more than 1 protocol when type is 'LoadBalancer'`},
|
||||
},
|
||||
"LB service, old service has different protocols, new service does not have different protocols, feature gate false": {
|
||||
oldService: oldLBServiceDifferentProtocols,
|
||||
newService: newLBServiceSameProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"LB service, both services have different protocols, feature gate false": {
|
||||
oldService: oldLBServiceDifferentProtocols,
|
||||
newService: newLBServiceDifferentProtocols,
|
||||
fgEnabled: false,
|
||||
},
|
||||
"LB service, neither service has different protocols, feature gate true": {
|
||||
oldService: oldLBServiceSameProtocols,
|
||||
newService: newLBServiceSameProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"LB service, old service has different protocols, new service does not have different protocols, feature gate true": {
|
||||
oldService: oldLBServiceDifferentProtocols,
|
||||
newService: newLBServiceSameProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"LB service, old service does not have different protocols, new service has different protocols, feature gate true": {
|
||||
oldService: oldLBServiceSameProtocols,
|
||||
newService: newLBServiceDifferentProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
"LB service, both services have different protocols, feature gate true": {
|
||||
oldService: oldLBServiceDifferentProtocols,
|
||||
newService: newLBServiceDifferentProtocols,
|
||||
fgEnabled: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.MixedProtocolLBService, tc.fgEnabled)()
|
||||
errs := validateMixedProtocolLBService(tc.newService, tc.oldService)
|
||||
if len(errs) != len(tc.expectedError) {
|
||||
t.Fatalf("unexpected number of errors: %v", errs)
|
||||
}
|
||||
for i := range errs {
|
||||
if !strings.Contains(errs[i].Error(), tc.expectedError[i]) {
|
||||
t.Errorf("unexpected error %d: %v", i, errs[i])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -4249,22 +4249,6 @@ func ValidateService(service *core.Service) field.ErrorList {
|
||||
allErrs = append(allErrs, field.NotSupported(specPath.Child("type"), service.Spec.Type, supportedServiceType.List()))
|
||||
}
|
||||
|
||||
if service.Spec.Type == core.ServiceTypeLoadBalancer {
|
||||
portsPath := specPath.Child("ports")
|
||||
includeProtocols := sets.NewString()
|
||||
for i := range service.Spec.Ports {
|
||||
portPath := portsPath.Index(i)
|
||||
if !supportedPortProtocols.Has(string(service.Spec.Ports[i].Protocol)) {
|
||||
allErrs = append(allErrs, field.Invalid(portPath.Child("protocol"), service.Spec.Ports[i].Protocol, "cannot create an external load balancer with non-TCP/UDP/SCTP ports"))
|
||||
} else {
|
||||
includeProtocols.Insert(string(service.Spec.Ports[i].Protocol))
|
||||
}
|
||||
}
|
||||
if includeProtocols.Len() > 1 {
|
||||
allErrs = append(allErrs, field.Invalid(portsPath, service.Spec.Ports, "cannot create an external load balancer with mix protocols"))
|
||||
}
|
||||
}
|
||||
|
||||
if service.Spec.Type == core.ServiceTypeClusterIP {
|
||||
portsPath := specPath.Child("ports")
|
||||
for i := range service.Spec.Ports {
|
||||
|
@ -10288,12 +10288,12 @@ func TestValidateServiceCreate(t *testing.T) {
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "invalid load balancer with mix protocol",
|
||||
name: "load balancer with mix protocol",
|
||||
tweakSvc: func(s *core.Service) {
|
||||
s.Spec.Type = core.ServiceTypeLoadBalancer
|
||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "q", Port: 12345, Protocol: "UDP", TargetPort: intstr.FromInt(12345)})
|
||||
},
|
||||
numErrs: 1,
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "valid 1",
|
||||
|
39
pkg/apis/core/zz_generated.deepcopy.go
generated
39
pkg/apis/core/zz_generated.deepcopy.go
generated
@ -2146,6 +2146,13 @@ func (in *List) DeepCopyObject() runtime.Object {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LoadBalancerIngress) DeepCopyInto(out *LoadBalancerIngress) {
|
||||
*out = *in
|
||||
if in.Ports != nil {
|
||||
in, out := &in.Ports, &out.Ports
|
||||
*out = make([]PortStatus, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -2165,7 +2172,9 @@ func (in *LoadBalancerStatus) DeepCopyInto(out *LoadBalancerStatus) {
|
||||
if in.Ingress != nil {
|
||||
in, out := &in.Ingress, &out.Ingress
|
||||
*out = make([]LoadBalancerIngress, len(*in))
|
||||
copy(*out, *in)
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -4081,6 +4090,27 @@ func (in *PodTemplateSpec) DeepCopy() *PodTemplateSpec {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PortStatus) DeepCopyInto(out *PortStatus) {
|
||||
*out = *in
|
||||
if in.Error != nil {
|
||||
in, out := &in.Error, &out.Error
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PortStatus.
|
||||
func (in *PortStatus) DeepCopy() *PortStatus {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PortStatus)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PortworxVolumeSource) DeepCopyInto(out *PortworxVolumeSource) {
|
||||
*out = *in
|
||||
@ -5312,6 +5342,13 @@ func (in *ServiceSpec) DeepCopy() *ServiceSpec {
|
||||
func (in *ServiceStatus) DeepCopyInto(out *ServiceStatus) {
|
||||
*out = *in
|
||||
in.LoadBalancer.DeepCopyInto(&out.LoadBalancer)
|
||||
if in.Conditions != nil {
|
||||
in, out := &in.Conditions, &out.Conditions
|
||||
*out = make([]v1.Condition, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apinamingtest "k8s.io/apimachinery/pkg/api/apitesting/naming"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
@ -70,6 +70,7 @@ var typesAllowedTags = map[reflect.Type]bool{
|
||||
reflect.TypeOf(metav1.GroupVersionKind{}): true,
|
||||
reflect.TypeOf(metav1.GroupVersionResource{}): true,
|
||||
reflect.TypeOf(metav1.Status{}): true,
|
||||
reflect.TypeOf(metav1.Condition{}): true,
|
||||
}
|
||||
|
||||
// These fields are limited exceptions to the standard JSON naming structure.
|
||||
|
@ -714,6 +714,12 @@ const (
|
||||
//
|
||||
// Allows control if NodePorts shall be created for services with "type: LoadBalancer" by defining the spec.AllocateLoadBalancerNodePorts field (bool)
|
||||
ServiceLBNodePortControl featuregate.Feature = "ServiceLBNodePortControl"
|
||||
|
||||
// owner: @janosi
|
||||
// alpha: v1.20
|
||||
//
|
||||
// Enables the usage of different protocols in the same Service with type=LoadBalancer
|
||||
MixedProtocolLBService featuregate.Feature = "MixedProtocolLBService"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -821,6 +827,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
||||
KubeletCredentialProviders: {Default: false, PreRelease: featuregate.Alpha},
|
||||
GracefulNodeShutdown: {Default: false, PreRelease: featuregate.Alpha},
|
||||
ServiceLBNodePortControl: {Default: false, PreRelease: featuregate.Alpha},
|
||||
MixedProtocolLBService: {Default: false, PreRelease: featuregate.Alpha},
|
||||
|
||||
// inherited features from generic apiserver, relisted here to get a conflict if it is changed
|
||||
// unintentionally on either side:
|
||||
|
@ -117,6 +117,7 @@ func (strategy svcStrategy) PrepareForUpdate(ctx context.Context, obj, old runti
|
||||
func (strategy svcStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
|
||||
service := obj.(*api.Service)
|
||||
allErrs := validation.ValidateServiceCreate(service)
|
||||
allErrs = append(allErrs, validation.ValidateConditionalService(service, nil)...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
@ -130,6 +131,7 @@ func (svcStrategy) AllowCreateOnUpdate() bool {
|
||||
|
||||
func (strategy svcStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
|
||||
allErrs := validation.ValidateServiceUpdate(obj.(*api.Service), old.(*api.Service))
|
||||
allErrs = append(allErrs, validation.ValidateConditionalService(obj.(*api.Service), old.(*api.Service))...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
@ -184,6 +186,17 @@ func dropServiceDisabledFields(newSvc *api.Service, oldSvc *api.Service) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ServiceLBNodePortControl) {
|
||||
newSvc.Spec.AllocateLoadBalancerNodePorts = nil
|
||||
}
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.MixedProtocolLBService) {
|
||||
if !serviceConditionsInUse(oldSvc) {
|
||||
newSvc.Status.Conditions = nil
|
||||
}
|
||||
if !loadBalancerPortsInUse(oldSvc) {
|
||||
for i := range newSvc.Status.LoadBalancer.Ingress {
|
||||
newSvc.Status.LoadBalancer.Ingress[i].Ports = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if svc.Spec.ServiceIPFamily field is in use
|
||||
@ -207,6 +220,27 @@ func topologyKeysInUse(svc *api.Service) bool {
|
||||
return len(svc.Spec.TopologyKeys) > 0
|
||||
}
|
||||
|
||||
// returns true when the svc.Status.Conditions field is in use.
|
||||
func serviceConditionsInUse(svc *api.Service) bool {
|
||||
if svc == nil {
|
||||
return false
|
||||
}
|
||||
return svc.Status.Conditions != nil
|
||||
}
|
||||
|
||||
// returns true when the svc.Status.LoadBalancer.Ingress.Ports field is in use.
|
||||
func loadBalancerPortsInUse(svc *api.Service) bool {
|
||||
if svc == nil {
|
||||
return false
|
||||
}
|
||||
for _, ing := range svc.Status.LoadBalancer.Ingress {
|
||||
if ing.Ports != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type serviceStatusStrategy struct {
|
||||
Strategy
|
||||
}
|
||||
|
@ -326,17 +326,40 @@ func makeServiceWithIPFamilies(ipfamilies []api.IPFamily, ipFamilyPolicy *api.IP
|
||||
}
|
||||
}
|
||||
|
||||
func makeServiceWithConditions(conditions []metav1.Condition) *api.Service {
|
||||
return &api.Service{
|
||||
Status: api.ServiceStatus{
|
||||
Conditions: conditions,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func makeServiceWithPorts(ports []api.PortStatus) *api.Service {
|
||||
return &api.Service{
|
||||
Status: api.ServiceStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
Ingress: []api.LoadBalancerIngress{
|
||||
{
|
||||
Ports: ports,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropDisabledField(t *testing.T) {
|
||||
requireDualStack := api.IPFamilyPolicyRequireDualStack
|
||||
preferDualStack := api.IPFamilyPolicyPreferDualStack
|
||||
singleStack := api.IPFamilyPolicySingleStack
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
enableDualStack bool
|
||||
svc *api.Service
|
||||
oldSvc *api.Service
|
||||
compareSvc *api.Service
|
||||
name string
|
||||
enableDualStack bool
|
||||
enableMixedProtocol bool
|
||||
svc *api.Service
|
||||
oldSvc *api.Service
|
||||
compareSvc *api.Service
|
||||
}{
|
||||
{
|
||||
name: "not dual stack, field not used",
|
||||
@ -396,12 +419,126 @@ func TestDropDisabledField(t *testing.T) {
|
||||
oldSvc: nil,
|
||||
compareSvc: makeServiceWithIPFamilies(nil, &singleStack),
|
||||
},
|
||||
|
||||
/* svc.Status.Conditions */
|
||||
{
|
||||
name: "mixed protocol not enabled, field not used in old, not used in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithConditions(nil),
|
||||
oldSvc: makeServiceWithConditions(nil),
|
||||
compareSvc: makeServiceWithConditions(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol not enabled, field used in old and in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
oldSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
compareSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol not enabled, field not used in old, used in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
oldSvc: makeServiceWithConditions(nil),
|
||||
compareSvc: makeServiceWithConditions(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol not enabled, field used in old, not used in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithConditions(nil),
|
||||
oldSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
compareSvc: makeServiceWithConditions(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field not used in old, not used in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithConditions(nil),
|
||||
oldSvc: makeServiceWithConditions(nil),
|
||||
compareSvc: makeServiceWithConditions(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field used in old and in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
oldSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
compareSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field not used in old, used in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
oldSvc: makeServiceWithConditions(nil),
|
||||
compareSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field used in old, not used in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithConditions(nil),
|
||||
oldSvc: makeServiceWithConditions([]metav1.Condition{}),
|
||||
compareSvc: makeServiceWithConditions(nil),
|
||||
},
|
||||
/* svc.Status.LoadBalancer.Ingress.Ports */
|
||||
{
|
||||
name: "mixed protocol not enabled, field not used in old, not used in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithPorts(nil),
|
||||
oldSvc: makeServiceWithPorts(nil),
|
||||
compareSvc: makeServiceWithPorts(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol not enabled, field used in old and in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
oldSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
compareSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol not enabled, field not used in old, used in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
oldSvc: makeServiceWithPorts(nil),
|
||||
compareSvc: makeServiceWithPorts(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol not enabled, field used in old, not used in new",
|
||||
enableMixedProtocol: false,
|
||||
svc: makeServiceWithPorts(nil),
|
||||
oldSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
compareSvc: makeServiceWithPorts(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field not used in old, not used in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithPorts(nil),
|
||||
oldSvc: makeServiceWithPorts(nil),
|
||||
compareSvc: makeServiceWithPorts(nil),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field used in old and in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
oldSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
compareSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field not used in old, used in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
oldSvc: makeServiceWithPorts(nil),
|
||||
compareSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
},
|
||||
{
|
||||
name: "mixed protocol enabled, field used in old, not used in new",
|
||||
enableMixedProtocol: true,
|
||||
svc: makeServiceWithPorts(nil),
|
||||
oldSvc: makeServiceWithPorts([]api.PortStatus{}),
|
||||
compareSvc: makeServiceWithPorts(nil),
|
||||
},
|
||||
/* add more tests for other dropped fields as needed */
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
func() {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.IPv6DualStack, tc.enableDualStack)()
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.MixedProtocolLBService, tc.enableMixedProtocol)()
|
||||
old := tc.oldSvc.DeepCopy()
|
||||
|
||||
// to test against user using IPFamily not set on cluster
|
||||
|
2231
staging/src/k8s.io/api/core/v1/generated.pb.go
generated
2231
staging/src/k8s.io/api/core/v1/generated.pb.go
generated
File diff suppressed because it is too large
Load Diff
@ -2036,6 +2036,12 @@ message LoadBalancerIngress {
|
||||
// (typically AWS load-balancers)
|
||||
// +optional
|
||||
optional string hostname = 2;
|
||||
|
||||
// Ports is a list of records of service ports
|
||||
// If used, every port defined in the service should have an entry in it
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
repeated PortStatus ports = 4;
|
||||
}
|
||||
|
||||
// LoadBalancerStatus represents the status of a load-balancer.
|
||||
@ -3765,6 +3771,29 @@ message PodTemplateSpec {
|
||||
optional PodSpec spec = 2;
|
||||
}
|
||||
|
||||
message PortStatus {
|
||||
// Port is the port number of the service port of which status is recorded here
|
||||
optional int32 port = 1;
|
||||
|
||||
// Protocol is the protocol of the service port of which status is recorded here
|
||||
// The supported values are: "TCP", "UDP", "SCTP"
|
||||
optional string protocol = 2;
|
||||
|
||||
// Error is to record the problem with the service port
|
||||
// The format of the error shall comply with the following rules:
|
||||
// - built-in error values shall be specified in this file and those shall use
|
||||
// CamelCase names
|
||||
// - cloud provider specific error values must have names that comply with the
|
||||
// format foo.example.com/CamelCase.
|
||||
// ---
|
||||
// The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
|
||||
// +optional
|
||||
// +kubebuilder:validation:Required
|
||||
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
|
||||
// +kubebuilder:validation:MaxLength=316
|
||||
optional string error = 3;
|
||||
}
|
||||
|
||||
// PortworxVolumeSource represents a Portworx volume resource.
|
||||
message PortworxVolumeSource {
|
||||
// VolumeID uniquely identifies a Portworx volume
|
||||
@ -5001,6 +5030,14 @@ message ServiceStatus {
|
||||
// if one is present.
|
||||
// +optional
|
||||
optional LoadBalancerStatus loadBalancer = 1;
|
||||
|
||||
// Current service state
|
||||
// +optional
|
||||
// +patchMergeKey=type
|
||||
// +patchStrategy=merge
|
||||
// +listType=map
|
||||
// +listMapKey=type
|
||||
repeated k8s.io.apimachinery.pkg.apis.meta.v1.Condition conditions = 2;
|
||||
}
|
||||
|
||||
// SessionAffinityConfig represents the configurations of session affinity.
|
||||
|
@ -3939,12 +3939,26 @@ const (
|
||||
ServiceExternalTrafficPolicyTypeCluster ServiceExternalTrafficPolicyType = "Cluster"
|
||||
)
|
||||
|
||||
// These are the valid conditions of a service.
|
||||
const (
|
||||
// LoadBalancerPortsError represents the condition of the requested ports
|
||||
// on the cloud load balancer instance.
|
||||
LoadBalancerPortsError = "LoadBalancerPortsError"
|
||||
)
|
||||
|
||||
// ServiceStatus represents the current status of a service.
|
||||
type ServiceStatus struct {
|
||||
// LoadBalancer contains the current status of the load-balancer,
|
||||
// if one is present.
|
||||
// +optional
|
||||
LoadBalancer LoadBalancerStatus `json:"loadBalancer,omitempty" protobuf:"bytes,1,opt,name=loadBalancer"`
|
||||
// Current service state
|
||||
// +optional
|
||||
// +patchMergeKey=type
|
||||
// +patchStrategy=merge
|
||||
// +listType=map
|
||||
// +listMapKey=type
|
||||
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
|
||||
}
|
||||
|
||||
// LoadBalancerStatus represents the status of a load-balancer.
|
||||
@ -3967,6 +3981,12 @@ type LoadBalancerIngress struct {
|
||||
// (typically AWS load-balancers)
|
||||
// +optional
|
||||
Hostname string `json:"hostname,omitempty" protobuf:"bytes,2,opt,name=hostname"`
|
||||
|
||||
// Ports is a list of records of service ports
|
||||
// If used, every port defined in the service should have an entry in it
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
Ports []PortStatus `json:"ports,omitempty" protobuf:"bytes,4,rep,name=ports"`
|
||||
}
|
||||
|
||||
const (
|
||||
@ -6205,3 +6225,26 @@ const (
|
||||
// and data streams for a single forwarded connection
|
||||
PortForwardRequestIDHeader = "requestID"
|
||||
)
|
||||
|
||||
// PortStatus represents the error condition of a service port
|
||||
|
||||
type PortStatus struct {
|
||||
// Port is the port number of the service port of which status is recorded here
|
||||
Port int32 `json:"port" protobuf:"varint,1,opt,name=port"`
|
||||
// Protocol is the protocol of the service port of which status is recorded here
|
||||
// The supported values are: "TCP", "UDP", "SCTP"
|
||||
Protocol Protocol `json:"protocol" protobuf:"bytes,2,opt,name=protocol,casttype=Protocol"`
|
||||
// Error is to record the problem with the service port
|
||||
// The format of the error shall comply with the following rules:
|
||||
// - built-in error values shall be specified in this file and those shall use
|
||||
// CamelCase names
|
||||
// - cloud provider specific error values must have names that comply with the
|
||||
// format foo.example.com/CamelCase.
|
||||
// ---
|
||||
// The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
|
||||
// +optional
|
||||
// +kubebuilder:validation:Required
|
||||
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
|
||||
// +kubebuilder:validation:MaxLength=316
|
||||
Error *string `json:"error,omitempty" protobuf:"bytes,3,opt,name=error"`
|
||||
}
|
||||
|
@ -953,6 +953,7 @@ var map_LoadBalancerIngress = map[string]string{
|
||||
"": "LoadBalancerIngress represents the status of a load-balancer ingress point: traffic intended for the service should be sent to an ingress point.",
|
||||
"ip": "IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)",
|
||||
"hostname": "Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers)",
|
||||
"ports": "Ports is a list of records of service ports If used, every port defined in the service should have an entry in it",
|
||||
}
|
||||
|
||||
func (LoadBalancerIngress) SwaggerDoc() map[string]string {
|
||||
@ -1723,6 +1724,16 @@ func (PodTemplateSpec) SwaggerDoc() map[string]string {
|
||||
return map_PodTemplateSpec
|
||||
}
|
||||
|
||||
var map_PortStatus = map[string]string{
|
||||
"port": "Port is the port number of the service port of which status is recorded here",
|
||||
"protocol": "Protocol is the protocol of the service port of which status is recorded here The supported values are: \"TCP\", \"UDP\", \"SCTP\"",
|
||||
"error": "Error is to record the problem with the service port The format of the error shall comply with the following rules: - built-in error values shall be specified in this file and those shall use\n CamelCase names\n- cloud provider specific error values must have names that comply with the\n format foo.example.com/CamelCase.",
|
||||
}
|
||||
|
||||
func (PortStatus) SwaggerDoc() map[string]string {
|
||||
return map_PortStatus
|
||||
}
|
||||
|
||||
var map_PortworxVolumeSource = map[string]string{
|
||||
"": "PortworxVolumeSource represents a Portworx volume resource.",
|
||||
"volumeID": "VolumeID uniquely identifies a Portworx volume",
|
||||
@ -2254,6 +2265,7 @@ func (ServiceSpec) SwaggerDoc() map[string]string {
|
||||
var map_ServiceStatus = map[string]string{
|
||||
"": "ServiceStatus represents the current status of a service.",
|
||||
"loadBalancer": "LoadBalancer contains the current status of the load-balancer, if one is present.",
|
||||
"conditions": "Current service state",
|
||||
}
|
||||
|
||||
func (ServiceStatus) SwaggerDoc() map[string]string {
|
||||
|
@ -2144,6 +2144,13 @@ func (in *List) DeepCopyObject() runtime.Object {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LoadBalancerIngress) DeepCopyInto(out *LoadBalancerIngress) {
|
||||
*out = *in
|
||||
if in.Ports != nil {
|
||||
in, out := &in.Ports, &out.Ports
|
||||
*out = make([]PortStatus, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -2163,7 +2170,9 @@ func (in *LoadBalancerStatus) DeepCopyInto(out *LoadBalancerStatus) {
|
||||
if in.Ingress != nil {
|
||||
in, out := &in.Ingress, &out.Ingress
|
||||
*out = make([]LoadBalancerIngress, len(*in))
|
||||
copy(*out, *in)
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -4079,6 +4088,27 @@ func (in *PodTemplateSpec) DeepCopy() *PodTemplateSpec {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PortStatus) DeepCopyInto(out *PortStatus) {
|
||||
*out = *in
|
||||
if in.Error != nil {
|
||||
in, out := &in.Error, &out.Error
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PortStatus.
|
||||
func (in *PortStatus) DeepCopy() *PortStatus {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PortStatus)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PortworxVolumeSource) DeepCopyInto(out *PortworxVolumeSource) {
|
||||
*out = *in
|
||||
@ -5327,6 +5357,13 @@ func (in *ServiceSpec) DeepCopy() *ServiceSpec {
|
||||
func (in *ServiceStatus) DeepCopyInto(out *ServiceStatus) {
|
||||
*out = *in
|
||||
in.LoadBalancer.DeepCopyInto(&out.LoadBalancer)
|
||||
if in.Conditions != nil {
|
||||
in, out := &in.Conditions, &out.Conditions
|
||||
*out = make([]metav1.Condition, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -90,9 +90,26 @@
|
||||
"ingress": [
|
||||
{
|
||||
"ip": "31",
|
||||
"hostname": "32"
|
||||
"hostname": "32",
|
||||
"ports": [
|
||||
{
|
||||
"port": -907310967,
|
||||
"protocol": "喂ƈ斎AO6",
|
||||
"error": "33"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"type": "34",
|
||||
"status": "C",
|
||||
"observedGeneration": -2492120148461555858,
|
||||
"lastTransitionTime": "2392-12-09T15:37:55Z",
|
||||
"reason": "35",
|
||||
"message": "36"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Binary file not shown.
@ -63,7 +63,18 @@ spec:
|
||||
- "30"
|
||||
type: 鮽ort昍řČ扷5ƗǸƢ6/ʕVŚ(Ŀ
|
||||
status:
|
||||
conditions:
|
||||
- lastTransitionTime: "2392-12-09T15:37:55Z"
|
||||
message: "36"
|
||||
observedGeneration: -2492120148461555858
|
||||
reason: "35"
|
||||
status: C
|
||||
type: "34"
|
||||
loadBalancer:
|
||||
ingress:
|
||||
- hostname: "32"
|
||||
ip: "31"
|
||||
ports:
|
||||
- error: "33"
|
||||
port: -907310967
|
||||
protocol: 喂ƈ斎AO6
|
||||
|
@ -87,7 +87,14 @@
|
||||
"ingress": [
|
||||
{
|
||||
"ip": "33",
|
||||
"hostname": "34"
|
||||
"hostname": "34",
|
||||
"ports": [
|
||||
{
|
||||
"port": 2114329341,
|
||||
"protocol": "Ă凗蓏Ŋ蛊ĉy",
|
||||
"error": "35"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Binary file not shown.
@ -60,3 +60,7 @@ status:
|
||||
ingress:
|
||||
- hostname: "34"
|
||||
ip: "33"
|
||||
ports:
|
||||
- error: "35"
|
||||
port: 2114329341
|
||||
protocol: Ă凗蓏Ŋ蛊ĉy
|
||||
|
@ -97,7 +97,14 @@
|
||||
"ingress": [
|
||||
{
|
||||
"ip": "34",
|
||||
"hostname": "35"
|
||||
"hostname": "35",
|
||||
"ports": [
|
||||
{
|
||||
"port": -8441701,
|
||||
"protocol": "",
|
||||
"error": "36"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Binary file not shown.
@ -66,3 +66,7 @@ status:
|
||||
ingress:
|
||||
- hostname: "35"
|
||||
ip: "34"
|
||||
ports:
|
||||
- error: "36"
|
||||
port: -8441701
|
||||
protocol: ""
|
||||
|
@ -87,7 +87,14 @@
|
||||
"ingress": [
|
||||
{
|
||||
"ip": "33",
|
||||
"hostname": "34"
|
||||
"hostname": "34",
|
||||
"ports": [
|
||||
{
|
||||
"port": 2114329341,
|
||||
"protocol": "Ă凗蓏Ŋ蛊ĉy",
|
||||
"error": "35"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Binary file not shown.
@ -60,3 +60,7 @@ status:
|
||||
ingress:
|
||||
- hostname: "34"
|
||||
ip: "33"
|
||||
ports:
|
||||
- error: "35"
|
||||
port: 2114329341
|
||||
protocol: Ă凗蓏Ŋ蛊ĉy
|
||||
|
Loading…
Reference in New Issue
Block a user