Merge pull request #134457 from danwinship/prefersamenode

KEP-3015: update PreferSameTrafficDistribution to GA
This commit is contained in:
Kubernetes Prow Robot 2025-10-23 14:41:33 -07:00 committed by GitHub
commit 6652c9fadf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 93 additions and 217 deletions

View file

@ -12639,7 +12639,7 @@
"description": "EndpointHints provides hints describing how an endpoint should be consumed.",
"properties": {
"forNodes": {
"description": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries. This is an Alpha feature and is only used when the PreferSameTrafficDistribution feature gate is enabled.",
"description": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
"items": {
"$ref": "#/definitions/io.k8s.api.discovery.v1.ForNode"
},

View file

@ -121,7 +121,7 @@
"description": "EndpointHints provides hints describing how an endpoint should be consumed.",
"properties": {
"forNodes": {
"description": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries. This is an Alpha feature and is only used when the PreferSameTrafficDistribution feature gate is enabled.",
"description": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
"items": {
"allOf": [
{

View file

@ -72,6 +72,10 @@ func GetWarningsForService(service, oldService *api.Service) []string {
warnings = append(warnings, fmt.Sprintf("spec.externalName is ignored when spec.type is not %q", api.ServiceTypeExternalName))
}
if service.Spec.TrafficDistribution != nil && *service.Spec.TrafficDistribution == api.ServiceTrafficDistributionPreferClose {
warnings = append(warnings, fmt.Sprintf("spec.trafficDistribution: %q is deprecated; use %q", api.ServiceTrafficDistributionPreferClose, api.ServiceTrafficDistributionPreferSameZone))
}
return warnings
}

View file

@ -23,6 +23,7 @@ import (
"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/utils/ptr"
)
func TestGetWarningsForService(t *testing.T) {
@ -90,18 +91,31 @@ func TestGetWarningsForService(t *testing.T) {
s.Spec.SessionAffinity = api.ServiceAffinityNone
},
numWarnings: 0,
},
{
name: "ExternalIPs, LoadBalancerIP and SessionAffinity set when headless service",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.ClusterIP = api.ClusterIPNone
s.Spec.ExternalIPs = []string{"1.2.3.4"}
s.Spec.LoadBalancerIP = "1.2.3.4"
s.Spec.SessionAffinity = api.ServiceAffinityClientIP
},
numWarnings: 3,
}}
}, {
name: "ExternalIPs, LoadBalancerIP and SessionAffinity set when headless service",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.ClusterIP = api.ClusterIPNone
s.Spec.ExternalIPs = []string{"1.2.3.4"}
s.Spec.LoadBalancerIP = "1.2.3.4"
s.Spec.SessionAffinity = api.ServiceAffinityClientIP
},
numWarnings: 3,
}, {
name: "trafficDistribution: PreferSameZone",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.TrafficDistribution = ptr.To(api.ServiceTrafficDistributionPreferSameZone)
},
numWarnings: 0,
}, {
name: "trafficDistribution: PreferClose",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.TrafficDistribution = ptr.To(api.ServiceTrafficDistributionPreferClose)
},
numWarnings: 1,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

View file

@ -4839,27 +4839,25 @@ const (
// These are valid values for the TrafficDistribution field of a Service.
const (
// Indicates a preference for routing traffic to endpoints that are in the same
// zone as the client. Users should not set this value unless they have ensured
// that clients and endpoints are distributed in such a way that the "same zone"
// preference will not result in endpoints getting overloaded.
ServiceTrafficDistributionPreferClose = "PreferClose"
// Indicates a preference for routing traffic to endpoints that are in the same
// zone as the client. Users should not set this value unless they have ensured
// that clients and endpoints are distributed in such a way that the "same zone"
// preference will not result in endpoints getting overloaded.
// This is an alias for "PreferClose", but it is an Alpha feature and is only
// recognized if the PreferSameTrafficDistribution feature gate is enabled.
// ServiceTrafficDistributionPreferSameZone indicates a preference for routing
// traffic to endpoints that are in the same zone as the client. Users should only
// set this value if they have ensured that clients and endpoints are distributed
// in such a way that the "same zone" preference will not result in endpoints
// getting overloaded.
ServiceTrafficDistributionPreferSameZone = "PreferSameZone"
// Indicates a preference for routing traffic to endpoints that are on the same
// node as the client. Users should not set this value unless they have ensured
// that clients and endpoints are distributed in such a way that the "same node"
// preference will not result in endpoints getting overloaded.
// This is an Alpha feature and is only recognized if the
// PreferSameTrafficDistribution feature gate is enabled.
// ServiceTrafficDistributionPreferSameNode indicates a preference for routing
// traffic to endpoints that are on the same node as the client. Users should only
// set this value if they have ensured that clients and endpoints are distributed
// in such a way that the "same node" preference will not result in endpoints
// getting overloaded.
ServiceTrafficDistributionPreferSameNode = "PreferSameNode"
// ServiceTrafficDistributionPreferClose is the original name of "PreferSameZone".
// Despite the generic-sounding name, it has exactly the same meaning as
// "PreferSameZone".
// Deprecated: use "PreferSameZone" instead.
ServiceTrafficDistributionPreferClose = "PreferClose"
)
// These are the valid conditions of a service.

View file

@ -17569,6 +17569,9 @@ func TestValidateServiceCreate(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if !tc.newTrafficDist {
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.34"))
}
featuregatetesting.SetFeatureGatesDuringTest(t, utilfeature.DefaultFeatureGate, featuregatetesting.FeatureOverrides{
features.PreferSameTrafficDistribution: tc.newTrafficDist,
features.RelaxedServiceNameValidation: tc.relaxedServiceNames,

View file

@ -138,10 +138,7 @@ type EndpointHints struct {
ForZones []ForZone
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled. May contain a maximum of 8 entries.
// +featureGate=PreferSameTrafficDistribution
// using topology aware routing. May contain a maximum of 8 entries.
ForNodes []ForNode
}

View file

@ -1541,6 +1541,7 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
PreferSameTrafficDistribution: {
{Version: version.MustParse("1.33"), Default: false, PreRelease: featuregate.Alpha},
{Version: version.MustParse("1.34"), Default: true, PreRelease: featuregate.Beta},
{Version: version.MustParse("1.35"), Default: true, PreRelease: featuregate.GA, LockToDefault: true},
},
PreventStaticPodAPIReferences: {

View file

@ -34820,7 +34820,7 @@ func schema_k8sio_api_discovery_v1_EndpointHints(ref common.ReferenceCallback) c
},
},
SchemaProps: spec.SchemaProps{
Description: "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries. This is an Alpha feature and is only used when the PreferSameTrafficDistribution feature gate is enabled.",
Description: "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
@ -35218,7 +35218,7 @@ func schema_k8sio_api_discovery_v1beta1_EndpointHints(ref common.ReferenceCallba
},
},
SchemaProps: spec.SchemaProps{
Description: "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries. This is an Alpha feature and is only used when the PreferSameTrafficDistribution feature gate is enabled.",
Description: "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{

View file

@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/version"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/features"
@ -401,6 +402,9 @@ func TestCategorizeEndpoints(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if !tc.preferSameEnabled {
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.34"))
}
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PreferSameTrafficDistribution, tc.preferSameEnabled)
clusterEndpoints, localEndpoints, allEndpoints, hasAnyEndpoints := CategorizeEndpoints(tc.endpoints, tc.serviceInfo, tc.nodeName, tc.nodeLabels)

View file

@ -115,7 +115,10 @@ func Test_dropDisabledFieldsOnCreate(t *testing.T) {
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PreferSameTrafficDistribution, testcase.preferSameEnabled)
if !testcase.preferSameEnabled {
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.34"))
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PreferSameTrafficDistribution, false)
}
dropDisabledFieldsOnCreate(testcase.eps)
if !apiequality.Semantic.DeepEqual(testcase.eps, testcase.expectedEPS) {
@ -413,9 +416,9 @@ func Test_dropDisabledFieldsOnUpdate(t *testing.T) {
t.Run(testcase.name, func(t *testing.T) {
if !testcase.hintsGateEnabled {
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.32"))
}
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.TopologyAwareHints, testcase.hintsGateEnabled)
if testcase.hintsGateEnabled {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.TopologyAwareHints, testcase.hintsGateEnabled)
} else if !testcase.preferSameEnabled {
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.34"))
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PreferSameTrafficDistribution, testcase.preferSameEnabled)
}

View file

@ -5707,27 +5707,25 @@ const (
// These are valid values for the TrafficDistribution field of a Service.
const (
// Indicates a preference for routing traffic to endpoints that are in the same
// zone as the client. Users should not set this value unless they have ensured
// that clients and endpoints are distributed in such a way that the "same zone"
// preference will not result in endpoints getting overloaded.
ServiceTrafficDistributionPreferClose = "PreferClose"
// Indicates a preference for routing traffic to endpoints that are in the same
// zone as the client. Users should not set this value unless they have ensured
// that clients and endpoints are distributed in such a way that the "same zone"
// preference will not result in endpoints getting overloaded.
// This is an alias for "PreferClose", but it is an Alpha feature and is only
// recognized if the PreferSameTrafficDistribution feature gate is enabled.
// ServiceTrafficDistributionPreferSameZone indicates a preference for routing
// traffic to endpoints that are in the same zone as the client. Users should only
// set this value if they have ensured that clients and endpoints are distributed
// in such a way that the "same zone" preference will not result in endpoints
// getting overloaded.
ServiceTrafficDistributionPreferSameZone = "PreferSameZone"
// Indicates a preference for routing traffic to endpoints that are on the same
// node as the client. Users should not set this value unless they have ensured
// that clients and endpoints are distributed in such a way that the "same node"
// preference will not result in endpoints getting overloaded.
// This is an Alpha feature and is only recognized if the
// PreferSameTrafficDistribution feature gate is enabled.
// ServiceTrafficDistributionPreferSameNode indicates a preference for routing
// traffic to endpoints that are on the same node as the client. Users should only
// set this value if they have ensured that clients and endpoints are distributed
// in such a way that the "same node" preference will not result in endpoints
// getting overloaded.
ServiceTrafficDistributionPreferSameNode = "PreferSameNode"
// ServiceTrafficDistributionPreferClose is the original name of "PreferSameZone".
// Despite the generic-sounding name, it has exactly the same meaning as
// "PreferSameZone".
// Deprecated: use "PreferSameZone" instead.
ServiceTrafficDistributionPreferClose = "PreferClose"
)
// These are the valid conditions of a service.

View file

@ -114,8 +114,6 @@ message EndpointHints {
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing. May contain a maximum of 8 entries.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled.
// +listType=atomic
repeated ForNode forNodes = 2;
}

View file

@ -166,8 +166,6 @@ type EndpointHints struct {
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing. May contain a maximum of 8 entries.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled.
// +listType=atomic
ForNodes []ForNode `json:"forNodes,omitempty" protobuf:"bytes,2,name=forNodes"`
}

View file

@ -57,7 +57,7 @@ func (EndpointConditions) SwaggerDoc() map[string]string {
var map_EndpointHints = map[string]string{
"": "EndpointHints provides hints describing how an endpoint should be consumed.",
"forZones": "forZones indicates the zone(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
"forNodes": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries. This is an Alpha feature and is only used when the PreferSameTrafficDistribution feature gate is enabled.",
"forNodes": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
}
func (EndpointHints) SwaggerDoc() map[string]string {

View file

@ -117,8 +117,6 @@ message EndpointHints {
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing. May contain a maximum of 8 entries.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled.
// +listType=atomic
repeated ForNode forNodes = 2;
}

View file

@ -164,8 +164,6 @@ type EndpointHints struct {
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing. May contain a maximum of 8 entries.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled.
// +listType=atomic
ForNodes []ForNode `json:"forNodes,omitempty" protobuf:"bytes,2,name=forNodes"`
}

View file

@ -56,7 +56,7 @@ func (EndpointConditions) SwaggerDoc() map[string]string {
var map_EndpointHints = map[string]string{
"": "EndpointHints provides hints describing how an endpoint should be consumed.",
"forZones": "forZones indicates the zone(s) this endpoint should be consumed by to enable topology aware routing. May contain a maximum of 8 entries.",
"forNodes": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries. This is an Alpha feature and is only used when the PreferSameTrafficDistribution feature gate is enabled.",
"forNodes": "forNodes indicates the node(s) this endpoint should be consumed by when using topology aware routing. May contain a maximum of 8 entries.",
}
func (EndpointHints) SwaggerDoc() map[string]string {

View file

@ -28,8 +28,6 @@ type EndpointHintsApplyConfiguration struct {
ForZones []ForZoneApplyConfiguration `json:"forZones,omitempty"`
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing. May contain a maximum of 8 entries.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled.
ForNodes []ForNodeApplyConfiguration `json:"forNodes,omitempty"`
}

View file

@ -28,8 +28,6 @@ type EndpointHintsApplyConfiguration struct {
ForZones []ForZoneApplyConfiguration `json:"forZones,omitempty"`
// forNodes indicates the node(s) this endpoint should be consumed by when
// using topology aware routing. May contain a maximum of 8 entries.
// This is an Alpha feature and is only used when the PreferSameTrafficDistribution
// feature gate is enabled.
ForNodes []ForNodeApplyConfiguration `json:"forNodes,omitempty"`
}

View file

@ -1253,6 +1253,10 @@
lockToDefault: false
preRelease: Beta
version: "1.34"
- default: true
lockToDefault: true
preRelease: GA
version: "1.35"
- name: PreventStaticPodAPIReferences
versionedSpecs:
- default: true

View file

@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/test/e2e/framework"
e2eendpointslice "k8s.io/kubernetes/test/e2e/framework/endpointslice"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
@ -362,21 +361,21 @@ var _ = common.SIGDescribe("Traffic Distribution", func() {
checkTrafficDistribution(ctx, clientPods)
})
framework.It("should route traffic to an endpoint in the same zone when using PreferSameZone", framework.WithFeatureGate(features.PreferSameTrafficDistribution), func(ctx context.Context) {
framework.It("should route traffic to an endpoint in the same zone when using PreferSameZone", func(ctx context.Context) {
clientPods, serverPods := allocateClientsAndServers(ctx)
svc := createService(ctx, v1.ServiceTrafficDistributionPreferSameZone)
createPods(ctx, svc, clientPods, serverPods)
checkTrafficDistribution(ctx, clientPods)
})
framework.It("should route traffic correctly between pods on multiple nodes when using PreferSameZone", framework.WithFeatureGate(features.PreferSameTrafficDistribution), func(ctx context.Context) {
framework.It("should route traffic correctly between pods on multiple nodes when using PreferSameZone", func(ctx context.Context) {
clientPods, serverPods := allocateMultiNodeClientsAndServers(ctx)
svc := createService(ctx, v1.ServiceTrafficDistributionPreferSameZone)
createPods(ctx, svc, clientPods, serverPods)
checkTrafficDistribution(ctx, clientPods)
})
framework.It("should route traffic to an endpoint on the same node or fall back to same zone when using PreferSameNode", framework.WithFeatureGate(features.PreferSameTrafficDistribution), func(ctx context.Context) {
framework.It("should route traffic to an endpoint on the same node or fall back to same zone when using PreferSameNode", func(ctx context.Context) {
ginkgo.By("finding a set of nodes for the test")
zone1Nodes, zone2Nodes, zone3Nodes := getNodesForMultiNode(ctx)
@ -428,7 +427,7 @@ var _ = common.SIGDescribe("Traffic Distribution", func() {
checkTrafficDistribution(ctx, clientPods)
})
framework.It("should route traffic to an endpoint on the same node when using PreferSameNode and fall back when the endpoint becomes unavailable", framework.WithFeatureGate(features.PreferSameTrafficDistribution), func(ctx context.Context) {
framework.It("should route traffic to an endpoint on the same node when using PreferSameNode and fall back when the endpoint becomes unavailable", func(ctx context.Context) {
ginkgo.By("finding a set of nodes for the test")
nodeList, err := e2enode.GetReadySchedulableNodes(ctx, c)
framework.ExpectNoError(err)

View file

@ -549,143 +549,6 @@ func Test_TransitionsForTrafficDistribution(t *testing.T) {
}
assertEndpointSliceHints(t, ctx, client, ns.GetName(), svc.GetName(), false, false)
}
// Test transitions involving the `trafficDistribution` field with
// PreferSameTrafficDistribution enabled.
func Test_TransitionsForPreferSameTrafficDistribution(t *testing.T) {
////////////////////////////////////////////////////////////////////////////
// Setup components, like kube-apiserver and EndpointSlice controller.
////////////////////////////////////////////////////////////////////////////
featuregatetesting.SetFeatureGatesDuringTest(t, utilfeature.DefaultFeatureGate, featuregatetesting.FeatureOverrides{
features.ServiceTrafficDistribution: true,
features.PreferSameTrafficDistribution: true,
})
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
server := kubeapiservertesting.StartTestServerOrDie(t, nil, framework.DefaultTestServerFlags(), framework.SharedEtcd())
defer server.TearDownFn()
client, err := clientset.NewForConfig(server.ClientConfig)
if err != nil {
t.Fatalf("Error creating clientset: %v", err)
}
resyncPeriod := 12 * time.Hour
informers := informers.NewSharedInformerFactory(client, resyncPeriod)
ctx := ktesting.Init(t)
defer ctx.Cancel("test has completed")
epsController := endpointslice.NewController(
ctx,
informers.Core().V1().Pods(),
informers.Core().V1().Services(),
informers.Core().V1().Nodes(),
informers.Discovery().V1().EndpointSlices(),
int32(100),
client,
1*time.Second,
)
informers.Start(ctx.Done())
go epsController.Run(ctx, 1)
////////////////////////////////////////////////////////////////////////////
// Create a namespace, node, pod in the node, and a service exposing the pod.
////////////////////////////////////////////////////////////////////////////
ns := framework.CreateNamespaceOrDie(client, "test-service-traffic-distribution", t)
defer framework.DeleteNamespaceOrDie(client, ns, t)
node := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-node",
Labels: map[string]string{
corev1.LabelTopologyZone: "fake-zone-1",
},
},
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Namespace: ns.GetName(),
Labels: map[string]string{
"foo": "bar",
},
},
Spec: corev1.PodSpec{
NodeName: node.GetName(),
Containers: []corev1.Container{
{
Name: "fake-name",
Image: "fake-image",
Ports: []corev1.ContainerPort{
{
Name: "port-443",
ContainerPort: 443,
},
},
},
},
},
Status: corev1.PodStatus{
Phase: corev1.PodRunning,
Conditions: []corev1.PodCondition{
{
Type: corev1.PodReady,
Status: corev1.ConditionTrue,
},
},
PodIP: "10.0.0.1",
PodIPs: []corev1.PodIP{
{
IP: "10.0.0.1",
},
},
},
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "test-service",
Namespace: ns.GetName(),
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{
"foo": "bar",
},
Ports: []corev1.ServicePort{
{Name: "port-443", Port: 443, Protocol: "TCP", TargetPort: intstr.FromInt32(443)},
},
},
}
_, err = client.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create test node: %v", err)
}
_, err = client.CoreV1().Pods(ns.Name).Create(ctx, pod, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create test ready pod: %v", err)
}
_, err = client.CoreV1().Pods(ns.Name).UpdateStatus(ctx, pod, metav1.UpdateOptions{})
if err != nil {
t.Fatalf("Failed to update status for test pod to Ready: %v", err)
}
_, err = client.CoreV1().Services(ns.Name).Create(ctx, svc, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create test service: %v", err)
}
////////////////////////////////////////////////////////////////////////////
// Assert that without the presence of `trafficDistribution` field there are
// no zone hints in EndpointSlice.
////////////////////////////////////////////////////////////////////////////
assertEndpointSliceHints(t, ctx, client, ns.GetName(), svc.GetName(), false, false)
////////////////////////////////////////////////////////////////////////////
// Update the service by setting `trafficDistribution: PreferSameZone`
@ -693,7 +556,7 @@ func Test_TransitionsForPreferSameTrafficDistribution(t *testing.T) {
// Assert that the respective EndpointSlices get the same-zone hints.
////////////////////////////////////////////////////////////////////////////
trafficDist := corev1.ServiceTrafficDistributionPreferSameZone
trafficDist = corev1.ServiceTrafficDistributionPreferSameZone
svc.Spec.TrafficDistribution = &trafficDist
_, err = client.CoreV1().Services(ns.Name).Update(ctx, svc, metav1.UpdateOptions{})
if err != nil {