From 198367a4865161424f99d89c07dfaca6df9784f3 Mon Sep 17 00:00:00 2001 From: Max Renaud Date: Wed, 30 Mar 2022 03:11:58 +0000 Subject: [PATCH] Added test where both policies are set --- pkg/proxy/iptables/proxier_test.go | 22 ++++++++++++++++++++++ pkg/proxy/ipvs/proxier.go | 4 ++-- pkg/proxy/ipvs/proxier_test.go | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/pkg/proxy/iptables/proxier_test.go b/pkg/proxy/iptables/proxier_test.go index c38ffdd71d9..c2c94981d08 100644 --- a/pkg/proxy/iptables/proxier_test.go +++ b/pkg/proxy/iptables/proxier_test.go @@ -6087,6 +6087,16 @@ func TestNoEndpointsMetric(t *testing.T) { {"10.0.1.3", "host2"}, }, }, + { + name: "both policies are set and there is non-zero local endpoints", + internalTrafficPolicy: &internalTrafficPolicyLocal, + externalTrafficPolicy: externalTrafficPolicyLocal, + endpoints: []endpoint{ + {"10.0.1.1", testHostname}, + {"10.0.1.2", "host1"}, + {"10.0.1.3", "host2"}, + }, + }, { name: "internalTrafficPolicy is set and there is zero local endpoint", internalTrafficPolicy: &internalTrafficPolicyLocal, @@ -6107,6 +6117,18 @@ func TestNoEndpointsMetric(t *testing.T) { }, expectedSyncProxyRulesNoLocalEndpointsTotalExternal: 1, }, + { + name: "both policies are set and there is zero local endpoint", + internalTrafficPolicy: &internalTrafficPolicyLocal, + externalTrafficPolicy: externalTrafficPolicyLocal, + endpoints: []endpoint{ + {"10.0.1.1", "host0"}, + {"10.0.1.2", "host1"}, + {"10.0.1.3", "host2"}, + }, + expectedSyncProxyRulesNoLocalEndpointsTotalInternal: 1, + expectedSyncProxyRulesNoLocalEndpointsTotalExternal: 1, + }, } for _, tc := range testCases { diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index 4abdcc283c8..0631be80ab8 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -278,14 +278,14 @@ type Proxier struct { // It is used to publish the sync_proxy_rules_no_endpoints_total // metric with the traffic_policy label set to "internal". // sets.String is used here since we end up calculating endpoint topology multiple times for the same Service - // if it has mulitple ports but each Service should only be counted once. + // if it has multiple ports but each Service should only be counted once. serviceNoLocalEndpointsInternal sets.String // serviceNoLocalEndpointsExternal irepresents the set of services that couldn't be applied // due to the absence of any endpoints when the external traffic policy is "Local". // It is used to publish the sync_proxy_rules_no_endpoints_total // metric with the traffic_policy label set to "external". // sets.String is used here since we end up calculating endpoint topology multiple times for the same Service - // if it has mulitple ports but each Service should only be counted once. + // if it has multiple ports but each Service should only be counted once. serviceNoLocalEndpointsExternal sets.String } diff --git a/pkg/proxy/ipvs/proxier_test.go b/pkg/proxy/ipvs/proxier_test.go index 20dbc70650b..2f6cbb2f05d 100644 --- a/pkg/proxy/ipvs/proxier_test.go +++ b/pkg/proxy/ipvs/proxier_test.go @@ -5838,6 +5838,16 @@ func TestNoEndpointsMetric(t *testing.T) { {"10.0.1.3", "host2"}, }, }, + { + name: "both policies are set and there is non-zero local endpoints", + internalTrafficPolicy: &internalTrafficPolicyLocal, + externalTrafficPolicy: externalTrafficPolicyLocal, + endpoints: []endpoint{ + {"10.0.1.1", testHostname}, + {"10.0.1.2", "host1"}, + {"10.0.1.3", "host2"}, + }, + }, { name: "internalTrafficPolicy is set and there is zero local endpoint", internalTrafficPolicy: &internalTrafficPolicyLocal, @@ -5858,6 +5868,18 @@ func TestNoEndpointsMetric(t *testing.T) { }, expectedSyncProxyRulesNoLocalEndpointsTotalExternal: 1, }, + { + name: "Both policies are set and there is zero local endpoint", + internalTrafficPolicy: &internalTrafficPolicyLocal, + externalTrafficPolicy: externalTrafficPolicyLocal, + endpoints: []endpoint{ + {"10.0.1.1", "host0"}, + {"10.0.1.2", "host1"}, + {"10.0.1.3", "host2"}, + }, + expectedSyncProxyRulesNoLocalEndpointsTotalInternal: 1, + expectedSyncProxyRulesNoLocalEndpointsTotalExternal: 1, + }, } for _, tc := range testCases { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ServiceInternalTrafficPolicy, true)()