Added test where both policies are set

This commit is contained in:
Max Renaud 2022-03-30 03:11:58 +00:00
parent ba4f5c4e7b
commit 198367a486
3 changed files with 46 additions and 2 deletions

View File

@ -6087,6 +6087,16 @@ func TestNoEndpointsMetric(t *testing.T) {
{"10.0.1.3", "host2"}, {"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", name: "internalTrafficPolicy is set and there is zero local endpoint",
internalTrafficPolicy: &internalTrafficPolicyLocal, internalTrafficPolicy: &internalTrafficPolicyLocal,
@ -6107,6 +6117,18 @@ func TestNoEndpointsMetric(t *testing.T) {
}, },
expectedSyncProxyRulesNoLocalEndpointsTotalExternal: 1, 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 { for _, tc := range testCases {

View File

@ -278,14 +278,14 @@ type Proxier struct {
// It is used to publish the sync_proxy_rules_no_endpoints_total // It is used to publish the sync_proxy_rules_no_endpoints_total
// metric with the traffic_policy label set to "internal". // 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 // 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 serviceNoLocalEndpointsInternal sets.String
// serviceNoLocalEndpointsExternal irepresents the set of services that couldn't be applied // 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". // 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 // It is used to publish the sync_proxy_rules_no_endpoints_total
// metric with the traffic_policy label set to "external". // 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 // 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 serviceNoLocalEndpointsExternal sets.String
} }

View File

@ -5838,6 +5838,16 @@ func TestNoEndpointsMetric(t *testing.T) {
{"10.0.1.3", "host2"}, {"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", name: "internalTrafficPolicy is set and there is zero local endpoint",
internalTrafficPolicy: &internalTrafficPolicyLocal, internalTrafficPolicy: &internalTrafficPolicyLocal,
@ -5858,6 +5868,18 @@ func TestNoEndpointsMetric(t *testing.T) {
}, },
expectedSyncProxyRulesNoLocalEndpointsTotalExternal: 1, 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 { for _, tc := range testCases {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ServiceInternalTrafficPolicy, true)() defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ServiceInternalTrafficPolicy, true)()