Skip to content

Commit

Permalink
Resolving comments by sergii
Browse files Browse the repository at this point in the history
  • Loading branch information
purnesh42H committed Jul 10, 2024
1 parent 97f7761 commit cd91460
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 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 == "v1beta" or version == "v1beta1":
elif version in ["v1beta", "v1beta1"]:
return self._build_from_discovery_v1(api_name, "beta")

raise NotImplementedError(f"Compute {version} not supported")
Expand Down
2 changes: 1 addition & 1 deletion framework/infrastructure/gcp/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
api_manager: gcp.api.GcpApiManager,
project: str,
gfe_debug_header: Optional[str] = None,
add_dualstack_support: Optional[bool] = False,
add_dualstack_support: bool = False,
version: str = "v1",
):
super().__init__(api_manager.compute(version), project)
Expand Down
42 changes: 23 additions & 19 deletions framework/infrastructure/traffic_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ class TrafficDirectorManager: # pylint: disable=too-many-public-methods
URL_MAP_PATH_MATCHER_NAME: Final[str] = "path-matcher"

TARGET_PROXY_NAME: Final[str] = "target-proxy"
TARGET_PROXY_NAME_IPV6: Final[str] = "target-proxy-ipv6"
ALTERNATIVE_TARGET_PROXY_NAME: Final[str] = "target-proxy-alt"

FORWARDING_RULE_NAME: Final[str] = "forwarding-rule"
FORWARDING_RULE_NAME_IPV6: Final[str] = "forwarding-rule_ipv6"
ALTERNATIVE_FORWARDING_RULE_NAME: Final[str] = "forwarding-rule-alt"

HEALTH_CHECK_NAME: Final[str] = "health-check"
Expand Down Expand Up @@ -114,7 +116,7 @@ def __init__(
project,
version=compute_api_version,
gfe_debug_header=xds_flags.GFE_DEBUG_HEADER.value,
add_dualstack_support=xds_flags.ADD_DUALSTACK_SUPPORT.value
add_dualstack_support=xds_flags.ADD_DUALSTACK_SUPPORT.value,
)

# Settings
Expand Down Expand Up @@ -604,12 +606,12 @@ def delete_alternative_url_map(self, force=False):
self.compute.delete_url_map(name)
self.url_map = None

def create_target_proxy(self, ipv6=False):
def create_target_proxy(self, ipv6=False):
if ipv6:
name = self.make_resource_name(self.TARGET_PROXY_NAME + "-v6")
name = self.make_resource_name(self.TARGET_PROXY_NAME_IPV6)
else:
name = self.make_resource_name(self.TARGET_PROXY_NAME)

if self.backend_service_protocol is BackendServiceProtocol.GRPC:
target_proxy_type = "GRPC"
create_proxy_fn = self.compute.create_target_grpc_proxy
Expand All @@ -627,7 +629,7 @@ def create_target_proxy(self, ipv6=False):
target_proxy_type,
self.url_map.name,
)

if ipv6:
self.target_proxy_v6 = create_proxy_fn(name, self.url_map)
else:
Expand All @@ -638,43 +640,43 @@ def delete_target_grpc_proxy(self, force=False):
if ipv6:
name = self.make_resource_name(self.TARGET_PROXY_NAME)
else:
name = self.make_resource_name(self.TARGET_PROXY_NAME + "-v6")
name = self.make_resource_name(self.TARGET_PROXY_NAME_IPV6)
elif self.target_proxy:
name = self.target_proxy.name
elif self.target_proxy_v6:
name = self.target_proxy_v6.name
name = self.target_proxy_v6.name
else:
return

logger.info('Deleting Target GRPC proxy "%s"', name)
self.compute.delete_target_grpc_proxy(name)
if ipv6:
self.target_proxy_v6 = None
else:
self.target_proxy = None

self.target_proxy_is_http = False

def delete_target_http_proxy(self, force=False, ipv6=False):
if force:
if ipv6:
name = self.make_resource_name(self.TARGET_PROXY_NAME)
else:
name = self.make_resource_name(self.TARGET_PROXY_NAME + "-v6")
name = self.make_resource_name(self.TARGET_PROXY_NAME_IPV6)
elif self.target_proxy and self.target_proxy_is_http:
name = self.target_proxy.name
elif self.target_proxy_v6 and self.target_proxy_is_http:
name = self.target_proxy_v6.name
else:
return

logger.info('Deleting HTTP Target proxy "%s"', name)
self.compute.delete_target_http_proxy(name)
if ipv6:
self.target_proxy_v6 = None
else:
self.target_proxy = None

self.target_proxy_is_http = False

def create_alternative_target_proxy(self):
Expand Down Expand Up @@ -719,11 +721,11 @@ def find_unused_forwarding_rule_port(
raise RuntimeError("Couldn't find unused forwarding rule port")

def create_forwarding_rule(self, src_port: int, ipv6=False):
if ipPv6:
name = self.make_resource_name(self.FORWARDING_RULE_NAME + "-v6")
if ipv6:
name = self.make_resource_name(self.FORWARDING_RULE_NAME_IPV6)
else:
name = self.make_resource_name(self.FORWARDING_RULE_NAME)

src_port = int(src_port)
logging.info(
'Creating forwarding rule "%s" in network "%s": 0.0.0.0:%s -> %s',
Expand All @@ -735,27 +737,29 @@ def create_forwarding_rule(self, src_port: int, ipv6=False):
resource = self.compute.create_forwarding_rule(
name, src_port, self.target_proxy, self.network_url
)

if ipv6:
self.forwarding_rule_v6 = resource
else:
self.forwarding_rule = resource

return resource

def delete_forwarding_rule(self, force=False, ipv6=False):
if force:
if ipv6:
name = self.make_resource_name(self.FORWARDING_RULE_NAME)
else:
name = self.make_resource_name(self.FORWARDING_RULE_NAME + "-v6")
name = self.make_resource_name(
self.FORWARDING_RULE_NAME + "-v6"
)
elif self.forwarding_rule:
name = self.forwarding_rule.name
elif self.forwarding_rule_v6:
name = self.forwarding_rule_v6.name
else:
return

logger.info('Deleting Forwarding rule "%s"', name)
self.compute.delete_forwarding_rule(name)
if ipv6:
Expand Down
2 changes: 1 addition & 1 deletion framework/xds_k8s_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is disgtributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Expand Down

0 comments on commit cd91460

Please sign in to comment.