From cdaeabfb46e987d3fa27522ef36f977cbbafcd31 Mon Sep 17 00:00:00 2001 From: m1093782566 Date: Fri, 14 Dec 2018 15:52:02 +0800 Subject: [PATCH] Add API for feature gate ServiceTopology --- api/api-rules/violation_exceptions.list | 1 + pkg/apis/core/types.go | 15 +++++++++++++++ pkg/features/kube_features.go | 7 +++++++ staging/src/k8s.io/api/core/v1/types.go | 16 ++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/api/api-rules/violation_exceptions.list b/api/api-rules/violation_exceptions.list index 10211214c1c..ff562d01652 100644 --- a/api/api-rules/violation_exceptions.list +++ b/api/api-rules/violation_exceptions.list @@ -214,6 +214,7 @@ API rule violation: list_type_missing,k8s.io/api/core/v1,ServiceAccountList,Item API rule violation: list_type_missing,k8s.io/api/core/v1,ServiceList,Items API rule violation: list_type_missing,k8s.io/api/core/v1,ServiceSpec,ExternalIPs API rule violation: list_type_missing,k8s.io/api/core/v1,ServiceSpec,LoadBalancerSourceRanges +API rule violation: list_type_missing,k8s.io/api/core/v1,ServiceSpec,TopologyKeys API rule violation: list_type_missing,k8s.io/api/core/v1,TopologySelectorLabelRequirement,Values API rule violation: list_type_missing,k8s.io/api/core/v1,TopologySelectorTerm,MatchLabelExpressions API rule violation: list_type_missing,k8s.io/api/events/v1beta1,EventList,Items diff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go index effdecc49f8..a453f0cabf8 100644 --- a/pkg/apis/core/types.go +++ b/pkg/apis/core/types.go @@ -3503,6 +3503,21 @@ type ServiceSpec struct { // cluster (e.g. IPv6 in IPv4 only cluster) is an error condition and will fail during clusterIP assignment. // +optional IPFamily *IPFamily + + // topologyKeys is a preference-order list of topology keys which + // implementations of services should use to preferentially sort endpoints + // when accessing this Service. Topology keys must be valid label keys and + // at most 16 keys may be specified. + // If any ready backends exist for index [0], they should always be chosen; + // only if no backends exist for index [0] should backends for index [1] be considered. + // If this field is specified and all entries have no backends that match + // the topology of the client, the service has no backends for that client + // and connections should fail. + // The special value "" may be used to mean "any node". This catch-all + // value, if used, only makes sense as the last value in the list. + // If this is not specified or empty, no topology constraints will be applied. + // +optional + TopologyKeys []string } // ServicePort represents the port on which the service is exposed diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 42dc87927a7..741c491e17c 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -538,6 +538,12 @@ const ( // // Enable all logic related to the PodDisruptionBudget API object in policy PodDisruptionBudget featuregate.Feature = "PodDisruptionBudget" + + // owner: @m1093782566 + // alpha: v1.17 + // + // Enables topology aware service routing + ServiceTopology featuregate.Feature = "ServiceTopology" ) func init() { @@ -623,6 +629,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS StartupProbe: {Default: false, PreRelease: featuregate.Alpha}, AllowInsecureBackendProxy: {Default: true, PreRelease: featuregate.Beta}, PodDisruptionBudget: {Default: true, PreRelease: featuregate.Beta}, + ServiceTopology: {Default: false, PreRelease: featuregate.Alpha}, // inherited features from generic apiserver, relisted here to get a conflict if it is changed // unintentionally on either side: diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 893dfb34cf4..ee12e3aa231 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -3940,6 +3940,7 @@ type ServiceSpec struct { // of peer discovery. // +optional PublishNotReadyAddresses bool `json:"publishNotReadyAddresses,omitempty" protobuf:"varint,13,opt,name=publishNotReadyAddresses"` + // sessionAffinityConfig contains the configurations of session affinity. // +optional SessionAffinityConfig *SessionAffinityConfig `json:"sessionAffinityConfig,omitempty" protobuf:"bytes,14,opt,name=sessionAffinityConfig"` @@ -3953,6 +3954,21 @@ type ServiceSpec struct { // cluster (e.g. IPv6 in IPv4 only cluster) is an error condition and will fail during clusterIP assignment. // +optional IPFamily *IPFamily `json:"ipFamily,omitempty" protobuf:"bytes,15,opt,name=ipFamily,Configcasttype=IPFamily"` + + // topologyKeys is a preference-order list of topology keys which + // implementations of services should use to preferentially sort endpoints + // when accessing this Service. Topology keys must be valid label keys and + // at most 16 keys may be specified. + // If any ready backends exist for index [0], they should always be chosen; + // only if no backends exist for index [0] should backends for index [1] be considered. + // If this field is specified and all entries have no backends that match + // the topology of the client, the service has no backends for that client + // and connections should fail. + // The special value "" may be used to mean "any node". This catch-all + // value, if used, only makes sense as the last value in the list. + // If this is not specified or empty, no topology constraints will be applied. + // +optional + TopologyKeys []string `json:"topologyKeys,omitempty" protobuf:"bytes,15,opt,name=topologyKeys"` } // ServicePort contains information on service's port.