1717
1818from absl import flags
1919from absl .testing import absltest
20+ from typing_extensions import override
2021
2122from framework import xds_k8s_flags
2223from framework import xds_k8s_testcase
2324from framework .helpers import skips
2425from framework .rpc import grpc_channelz
2526from framework .rpc import grpc_testing
27+ from framework .test_app .runners .k8s import k8s_xds_client_runner
2628
2729logger = logging .getLogger (__name__ )
2830flags .adopt_module_key_flags (xds_k8s_testcase )
3133_XdsTestServer = xds_k8s_testcase .XdsTestServer
3234_XdsTestClient = xds_k8s_testcase .XdsTestClient
3335_ChannelzChannelState = grpc_channelz .ChannelState
36+ KubernetesClientRunner = k8s_xds_client_runner .KubernetesClientRunner
3437_Lang = skips .Lang
3538
3639# Testing consts
@@ -61,6 +64,10 @@ def is_supported(config: skips.TestConfig) -> bool:
6164 return config .version_gte ("v1.10.x" )
6265 return True
6366
67+ @override
68+ def initKubernetesClientRunner (self , ** kwargs ) -> KubernetesClientRunner :
69+ return super ().initKubernetesClientRunner (reuse_namespace = True )
70+
6471 def test_affinity (self ) -> None : # pylint: disable=too-many-statements
6572 with self .subTest ("00_create_health_check" ):
6673 self .td .create_health_check ()
@@ -86,6 +93,14 @@ def test_affinity(self) -> None: # pylint: disable=too-many-statements
8693 with self .subTest ("06_add_server_backends_to_backend_services" ):
8794 self .setupServerBackends ()
8895
96+ with self .subTest ("06a_wait_for_endpoints_propagation" ):
97+ # Start a temporary client to verify all endpoints are reported by TD.
98+ # This is to address flakiness where the main client starts with
99+ # a partial list of endpoints.
100+ temp_client = self .startTestClient (test_servers [0 ])
101+ self .assertHealthyEndpointsCount (temp_client , _REPLICA_COUNT )
102+ self .client_runner .cleanup (force_namespace = False )
103+
89104 test_client : _XdsTestClient
90105 with self .subTest ("07_start_test_client" ):
91106 test_client = self .startTestClient (
@@ -174,7 +189,7 @@ def test_affinity(self) -> None: # pylint: disable=too-many-statements
174189 finally :
175190 logging .info ("Client received CSDS response: %s" , parsed )
176191
177- with self .subTest ("12_next_100_affinity_rpcs_pick_different_backend " ):
192+ with self .subTest ("13_next_100_affinity_rpcs_pick_different_backend " ):
178193 rpc_stats = self .getClientRpcStats (test_client , _RPC_COUNT )
179194 rpc_distribution = grpc_testing .RpcDistributionStats .from_message (
180195 rpc_stats
0 commit comments