From 7d8d4b1eb31b3747f625634985f197bc92accac2 Mon Sep 17 00:00:00 2001 From: Hongliang Liu <75655411+hongliangl@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:20:28 +0800 Subject: [PATCH] Fix hint annotation implementation in AntreaProxy (#6607) This commit is to be consistent with kube-proxy's behavior for Topology Aware Routing feature. For `service.kubernetes.io/topology-mode` hint annotation, any non-empty and non-disabled values for the annotation are acceptable to enable Topology Aware Routing for a Service. Signed-off-by: Hongliang Liu --- pkg/agent/proxy/topology.go | 6 ++---- pkg/agent/proxy/topology_test.go | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/agent/proxy/topology.go b/pkg/agent/proxy/topology.go index 7460082c201..63f1d1a5e0a 100644 --- a/pkg/agent/proxy/topology.go +++ b/pkg/agent/proxy/topology.go @@ -124,11 +124,9 @@ func (p *proxier) canUseTopology(endpoints map[string]k8sproxy.Endpoint, svcInfo if !p.topologyAwareHintsEnabled { return false } + // Any non-empty and non-disabled values for the hints annotation are acceptable. hintsAnnotation := svcInfo.HintsAnnotation() - if hintsAnnotation != "Auto" && hintsAnnotation != "auto" { - if hintsAnnotation != "" && hintsAnnotation != "Disabled" && hintsAnnotation != "disabled" { - klog.InfoS("Skipping topology aware Endpoint filtering since Service has unexpected value", "annotationTopologyAwareHints", v1.DeprecatedAnnotationTopologyAwareHints, "hints", hintsAnnotation) - } + if hintsAnnotation == "" || hintsAnnotation == "disabled" || hintsAnnotation == "Disabled" { return false } diff --git a/pkg/agent/proxy/topology_test.go b/pkg/agent/proxy/topology_test.go index f17fc40699b..ebbadf35dfa 100644 --- a/pkg/agent/proxy/topology_test.go +++ b/pkg/agent/proxy/topology_test.go @@ -97,7 +97,7 @@ func TestCategorizeEndpoints(t *testing.T) { localEndpoints: nil, }, { - name: "hints enabled, hints annotation == aUto (wrong capitalization), hints ignored", + name: "hints enabled, hints annotation == aUto (wrong capitalization), hints no longer ignored", hintsEnabled: true, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, serviceInfo: k8sproxy.NewBaseServiceInfo(net.ParseIP("10.96.0.1"), 80, v1.ProtocolTCP, 0, nil, "", 0, nil, nil, 0, false, false, nil, "aUto"), @@ -107,7 +107,7 @@ func TestCategorizeEndpoints(t *testing.T) { "10.1.2.5:80": &k8sproxy.BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true}, "10.1.2.6:80": &k8sproxy.BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true}, }, - clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), + clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"), localEndpoints: nil, }, {