Skip to content

Commit 457b88c

Browse files
Tag all SkyPilot AWS nodes with "skypilot-user: $USER". (skypilot-org#1515)
* Tag all SkyPilot AWS nodes with "skypilot-user: $USER". * Use getpass.getuser(). * Don't catch getuser()
1 parent d97ffed commit 457b88c

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

sky/backends/backend_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ def write_cluster_config(
768768

769769
yaml_path = _get_yaml_path_from_cluster_name(cluster_name)
770770

771-
# Use a tmp file path to avoid incomplete YAML file being re-used in the future.
771+
# Use a tmp file path to avoid incomplete YAML file being re-used in the
772+
# future.
772773
tmp_yaml_path = yaml_path + '.tmp'
773774
tmp_yaml_path = fill_template(
774775
cluster_config_template,
@@ -778,6 +779,12 @@ def write_cluster_config(
778779
'cluster_name': cluster_name,
779780
'num_nodes': num_nodes,
780781
'disk_size': to_provision.disk_size,
782+
# If the current code is run by controller, propagate the real
783+
# calling user which should've been passed in as the
784+
# SKYPILOT_USER env var (see spot-controller.yaml.j2).
785+
'user': os.environ.get('SKYPILOT_USER', getpass.getuser()),
786+
787+
# AWS only:
781788
# Temporary measure, as deleting per-cluster SGs is too slow.
782789
# See https://github.com/skypilot-org/skypilot/pull/742.
783790
# Generate the name of the security group we're looking for.

sky/execution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ def spot_launch(
527527
'disable_logging': env_options.Options.DISABLE_LOGGING.get(),
528528
'logging_user_hash': common_utils.get_user_hash(),
529529
'retry_until_up': retry_until_up,
530+
'user': os.environ.get('USER', None),
530531
},
531532
output_prefix=spot.SPOT_CONTROLLER_YAML_PREFIX)
532533
controller_task = task_lib.Task.from_yaml(yaml_path)

sky/templates/aws-ray.yml.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ available_node_types:
4343
# SpotOptions:
4444
# MaxPrice: MAX_HOURLY_PRICE
4545
{% endif %}
46+
TagSpecifications:
47+
- ResourceType: instance
48+
Tags:
49+
- Key: skypilot-user
50+
Value: {{ user }}
4651
{% if num_nodes > 1 %}
4752
ray.worker.default:
4853
min_workers: {{num_nodes - 1}}
@@ -65,6 +70,11 @@ available_node_types:
6570
# SpotOptions:
6671
# MaxPrice: MAX_HOURLY_PRICE
6772
{% endif %}
73+
TagSpecifications:
74+
- ResourceType: instance
75+
Tags:
76+
- Key: skypilot-user
77+
Value: {{ user }}
6878
{%- endif %}
6979

7080
head_node_type: ray.head.default

sky/templates/spot-controller.yaml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ run: |
3939

4040
envs:
4141
SKYPILOT_USAGE_USER_ID: {{logging_user_hash}}
42+
SKYPILOT_USER: {{user}}
4243
{% if is_dev %}
4344
SKYPILOT_DEV: 1
4445
{% endif %}

0 commit comments

Comments
 (0)