Skip to content

Commit

Permalink
Address Sergii's comments: Refactor enable_dualstack flag to xds_k8s_…
Browse files Browse the repository at this point in the history
…testcase, add enable_dualstack to client and server deployment
  • Loading branch information
purnesh42H committed Jul 20, 2024
1 parent 661c57a commit 44dd2a4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion framework/infrastructure/gcp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def compute(self, version: str):
return self._build_from_discovery_v1(api_name, version)
elif version == "v1alpha":
return self._build_from_discovery_v1(api_name, "alpha")
elif version in ["v1beta", "v1beta1"]:
elif version == "v1beta":
return self._build_from_discovery_v1(api_name, "beta")

raise NotImplementedError(f"Compute {version} not supported")
Expand Down
23 changes: 17 additions & 6 deletions framework/infrastructure/traffic_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(
resource_suffix: str,
network: str = "default",
compute_api_version: str = "v1",
enable_dualstack: bool = False,
):
# API
self.compute = _ComputeV1(
Expand All @@ -123,6 +124,7 @@ def __init__(
self.network: str = network
self.resource_prefix: str = resource_prefix
self.resource_suffix: str = resource_suffix
self.enable_dualstack: bool = enable_dualstack

# Managed resources
self.health_check: Optional[GcpResource] = None
Expand All @@ -138,7 +140,6 @@ def __init__(
self.forwarding_rule: Optional[GcpResource] = None
self.forwarding_rule_ipv6: Optional[GcpResource] = None
self.alternative_forwarding_rule: Optional[GcpResource] = None
self.enable_dualstack = xds_flags.ENABLE_DUALSTACK.value

# Backends.
self.backends = set()
Expand Down Expand Up @@ -189,6 +190,7 @@ def cleanup(self, *, force=False):
self.delete_target_grpc_proxy(force=force)
if self.enable_dualstack:
self.delete_target_proxy_ipv6(force=force)
self.delete_forwarding_rule_ipv6(force=force)
self.delete_alternative_target_grpc_proxy(force=force)
self.delete_url_map(force=force)
self.delete_alternative_url_map(force=force)
Expand Down Expand Up @@ -740,7 +742,6 @@ def create_forwarding_rule(self, src_port: int):

def create_forwarding_rule_ipv6(self, src_port: int):
name = self.make_resource_name(self.FORWARDING_RULE_NAME_IPV6)
src_port = int(src_port)
logging.info(
'Creating forwarding rule "%s" in network "%s": [::]:%s -> %s',
name,
Expand All @@ -762,17 +763,23 @@ def create_forwarding_rule_ipv6(self, src_port: int):
def delete_forwarding_rule(self, force=False):
if force:
name = self.make_resource_name(self.FORWARDING_RULE_NAME)
name_ipv6 = self.make_resource_name(self.FORWARDING_RULE_NAME_IPV6)
elif self.forwarding_rule:
name = self.forwarding_rule.name
name_ipv6 = self.forwarding_rule_ipv6.name
else:
return
logger.info('Deleting Forwarding rule "%s"', name)
self.compute.delete_forwarding_rule(name)
self.forwarding_rule = None
logger.info('Deleting Forwarding rule "%s"', name_ipv6)
self.compute.delete_forwarding_rule(name_ipv6)

def delete_forwarding_rule_ipv6(self, force=False):
if force:
name = self.make_resource_name(self.FORWARDING_RULE_NAME_IPV6)
elif self.forwarding_rule_ipv6:
name = self.forwarding_rule_ipv6.name
else:
return
logger.info('Deleting Forwarding rule "%s"', name)
self.compute.delete_forwarding_rule(name)
self.forwarding_rule_ipv6 = None

def create_alternative_forwarding_rule(
Expand Down Expand Up @@ -914,6 +921,7 @@ def __init__(
resource_suffix: Optional[str] = None,
network: str = "default",
compute_api_version: str = "v1",
enable_dualstack: bool = False,
):
super().__init__(
gcp_api_manager,
Expand All @@ -922,6 +930,7 @@ def __init__(
resource_suffix=resource_suffix,
network=network,
compute_api_version=compute_api_version,
enable_dualstack=enable_dualstack,
)

# API
Expand Down Expand Up @@ -1038,6 +1047,7 @@ def __init__(
resource_suffix: Optional[str] = None,
network: str = "default",
compute_api_version: str = "v1",
enable_dualstack: bool = False,
):
super().__init__(
gcp_api_manager,
Expand All @@ -1046,6 +1056,7 @@ def __init__(
resource_suffix=resource_suffix,
network=network,
compute_api_version=compute_api_version,
enable_dualstack=enable_dualstack,
)

# API
Expand Down
1 change: 1 addition & 0 deletions framework/test_app/runners/k8s/k8s_xds_client_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ClientDeploymentArgs:
enable_csm_observability: bool = False
csm_workload_name: str = ""
csm_canonical_service_name: str = ""
enable_dualstack: bool = False

def as_dict(self):
return dataclasses.asdict(self)
Expand Down
3 changes: 3 additions & 0 deletions framework/test_app/runners/k8s/k8s_xds_server_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__( # pylint: disable=too-many-locals
debug_use_port_forwarding: bool = False,
enable_workload_identity: bool = True,
deployment_args: Optional[ServerDeploymentArgs] = None,
enable_dualstack: bool = False,
):
super().__init__(
k8s_namespace,
Expand Down Expand Up @@ -142,6 +143,7 @@ def __init__( # pylint: disable=too-many-locals
self.td_bootstrap_image = td_bootstrap_image
self.network = network
self.xds_server_uri = xds_server_uri
self.enable_dualstack = enable_dualstack

# Workload identity settings:
if self.enable_workload_identity:
Expand Down Expand Up @@ -223,6 +225,7 @@ def run( # pylint: disable=arguments-differ,too-many-branches
deployment_name=self.deployment_name,
neg_name=self.gcp_neg_name,
test_port=test_port,
enable_dualstack=self.enable_dualstack,
)
self._wait_service_neg_status_annotation(self.service_name, test_port)

Expand Down
2 changes: 1 addition & 1 deletion framework/xds_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
ENABLE_DUALSTACK = flags.DEFINE_bool(
"enable_dualstack",
default=False,
help=("Enable support for Dual Stack resources to the framework."),
help="Enable support for Dual Stack resources to the framework.",
)


Expand Down
14 changes: 13 additions & 1 deletion framework/xds_k8s_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
TrafficDirectorSecureManager = traffic_director.TrafficDirectorSecureManager
XdsTestServer = server_app.XdsTestServer
XdsTestClient = client_app.XdsTestClient
ClientDeploymentArgs = k8s_xds_client_runner.ClientDeploymentArgs
KubernetesServerRunner = k8s_xds_server_runner.KubernetesServerRunner
KubernetesClientRunner = k8s_xds_client_runner.KubernetesClientRunner
_LoadBalancerStatsResponse = grpc_testing.LoadBalancerStatsResponse
Expand Down Expand Up @@ -146,6 +147,7 @@ class XdsKubernetesBaseTestCase(base_testcase.BaseTestCase):
_prev_sigint_handler: Optional[_SignalHandler] = None
_handling_sigint: bool = False
yaml_highlighter: framework.helpers.highlighter.HighlighterYaml = None
enable_dualstack: bool = False

@staticmethod
def is_supported(config: skips.TestConfig) -> bool:
Expand Down Expand Up @@ -179,6 +181,7 @@ def setUpClass(cls):
cls.td_bootstrap_image = xds_k8s_flags.TD_BOOTSTRAP_IMAGE.value
cls.xds_server_uri = xds_flags.XDS_SERVER_URI.value
cls.compute_api_version = xds_flags.COMPUTE_API_VERSION.value
cls.enable_dualstack = xds_flags.ENABLE_DUALSTACK.value

# Firewall
cls.ensure_firewall = xds_flags.ENSURE_FIREWALL.value
Expand Down Expand Up @@ -796,7 +799,11 @@ def setUp(self):
self.client_namespace = KubernetesClientRunner.make_namespace_name(
self.resource_prefix, self.resource_suffix
)
self.client_runner = self.initKubernetesClientRunner()
self.client_runner = self.initKubernetesClientRunner(
deployment_args=ClientDeploymentArgs(
enable_dualstack=self.enable_dualstack
)
)

# Create healthcheck firewall rules if necessary.
if self.ensure_firewall:
Expand Down Expand Up @@ -940,6 +947,7 @@ def initTrafficDirectorManager(self) -> TrafficDirectorManager:
resource_suffix=self.resource_suffix,
network=self.network,
compute_api_version=self.compute_api_version,
enable_dualstack=self.enable_dualstack,
)

def initKubernetesServerRunner(self, **kwargs) -> KubernetesServerRunner:
Expand All @@ -957,6 +965,7 @@ def initKubernetesServerRunner(self, **kwargs) -> KubernetesServerRunner:
network=self.network,
debug_use_port_forwarding=self.debug_use_port_forwarding,
enable_workload_identity=self.enable_workload_identity,
enable_dualstack=self.enable_dualstack,
**kwargs,
)

Expand Down Expand Up @@ -1014,6 +1023,7 @@ def initTrafficDirectorManager(self) -> TrafficDirectorAppNetManager:
resource_suffix=self.resource_suffix,
network=self.network,
compute_api_version=self.compute_api_version,
enable_dualstack=self.enable_dualstack,
)


Expand Down Expand Up @@ -1051,6 +1061,7 @@ def initTrafficDirectorManager(self) -> TrafficDirectorSecureManager:
resource_suffix=self.resource_suffix,
network=self.network,
compute_api_version=self.compute_api_version,
enable_dualstack=self.enable_dualstack,
)

def initKubernetesServerRunner(self, **kwargs) -> KubernetesServerRunner:
Expand All @@ -1068,6 +1079,7 @@ def initKubernetesServerRunner(self, **kwargs) -> KubernetesServerRunner:
xds_server_uri=self.xds_server_uri,
deployment_template="server-secure.deployment.yaml",
debug_use_port_forwarding=self.debug_use_port_forwarding,
enable_dualstack=self.enable_dualstack,
**kwargs,
)

Expand Down

0 comments on commit 44dd2a4

Please sign in to comment.