@@ -1127,7 +1127,29 @@ def check_local_gpus() -> bool:
1127
1127
def generate_cluster_name ():
1128
1128
# TODO: change this ID formatting to something more pleasant.
1129
1129
# User name is helpful in non-isolated accounts, e.g., GCP, Azure.
1130
- return f'sky-{ uuid .uuid4 ().hex [:4 ]} -{ getpass .getuser ()} '
1130
+ return f'sky-{ uuid .uuid4 ().hex [:4 ]} -{ get_cleaned_username ()} '
1131
+
1132
+
1133
+ def get_cleaned_username () -> str :
1134
+ """Cleans the current username to be used as part of a cluster name.
1135
+
1136
+ Clean up includes:
1137
+ 1. Making all characters lowercase
1138
+ 2. Removing any non-alphanumeric characters (excluding hyphens)
1139
+ 3. Removing any numbers and/or hyphens at the start of the username.
1140
+ 4. Removing any hyphens at the end of the username
1141
+
1142
+ e.g. 1SkY-PiLot2- becomes sky-pilot2.
1143
+
1144
+ Returns:
1145
+ A cleaned username that will pass the regex in check_cluster_name_is_valid().
1146
+ """
1147
+ username = getpass .getuser ()
1148
+ username = username .lower ()
1149
+ username = re .sub (r'[^a-z0-9-]' , '' , username )
1150
+ username = re .sub (r'^[0-9-]+' , '' , username )
1151
+ username = re .sub (r'-$' , '' , username )
1152
+ return username
1131
1153
1132
1154
1133
1155
def query_head_ip_with_retries (cluster_yaml : str , max_attempts : int = 1 ) -> str :
0 commit comments