Skip to content

Commit

Permalink
add backward compatibility for gcp ports
Browse files Browse the repository at this point in the history
  • Loading branch information
cblmemo committed Sep 16, 2023
1 parent 938e398 commit c546115
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions sky/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
# - UserData: The UserData field of the old yaml may be outdated, and we want to
# use the new yaml's UserData field, which contains the authorized key setup as
# well as the disabling of the auto-update with apt-get.
# - firewall_rule: This is a newly added section for gcp in provider section.
# - security_group: In #2485 we introduces the changed of security group, so we
# should take the latest security group name.
_RAY_YAML_KEYS_TO_RESTORE_EXCEPTIONS = [
('provider', 'availability_zone'),
('provider', 'firewall_rule'),
Expand Down
3 changes: 1 addition & 2 deletions sky/provision/aws/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def _get_sg_from_name(


def _maybe_move_to_new_sg(
ec2: Any,
instance: Any,
expected_sg: Any,
) -> None:
Expand Down Expand Up @@ -258,7 +257,7 @@ def open_ports(
return
# For multinode cases, we need to open ports for all instances.
for instance in instance_list:
_maybe_move_to_new_sg(ec2, instance, sg)
_maybe_move_to_new_sg(instance, sg)

existing_ports: Set[int] = set()
for existing_rule in sg.ip_permissions:
Expand Down
16 changes: 10 additions & 6 deletions sky/provision/gcp/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ def cleanup_ports(
) -> None:
"""See sky/provision/__init__.py"""
assert provider_config is not None, cluster_name_on_cloud
if 'firewall_rule' not in provider_config:
# No new ports were opened, so there is nothing to clean up.
return
project_id = provider_config['project_id']
firewall_rule_name = provider_config['firewall_rule']
instance_utils.GCPComputeInstance.delete_firewall_rule(
project_id, firewall_rule_name)
if 'ports' in provider_config:
# Backward compatibility for old provider config.
for port in provider_config['ports']:
rule_name = f'user-ports-{cluster_name_on_cloud}-{port}'
instance_utils.GCPComputeInstance.delete_firewall_rule(
project_id, rule_name)
if 'firewall_rule' in provider_config:
firewall_rule_name = provider_config['firewall_rule']
instance_utils.GCPComputeInstance.delete_firewall_rule(
project_id, firewall_rule_name)

0 comments on commit c546115

Please sign in to comment.