File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
src/hyperpod_cli/commands Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -1142,4 +1142,11 @@ def get_user_name():
11421142 user_name = 'Unknown'
11431143
11441144 # label value does not allow slash
1145- return user_name .replace ('/' , '-' )
1145+ user_name = user_name .replace ('/' , '-' )
1146+ # 63 is the max length for a Kubernetes label
1147+ if len (user_name ) > 63 :
1148+ # Add dots in the end to indicate the username is trimmed
1149+ trimmed_user_name = user_name [:55 ] + '-trimmed'
1150+ logger .warning (f"The username is longer than the maximum length (63) of Kubernetes label, trimming to { trimmed_user_name } " )
1151+ return trimmed_user_name
1152+ return user_name
Original file line number Diff line number Diff line change 2727from hyperpod_cli .commands .job import (
2828 cancel_job ,
2929 get_job ,
30+ get_user_name ,
3031 list_jobs ,
3132 list_pods ,
3233 patch_job ,
@@ -2138,3 +2139,16 @@ def test_start_job_with_recipe_missing_required_args(self):
21382139 ],
21392140 )
21402141 self .assertNotEqual (result .exit_code , 0 )
2142+
2143+ @mock .patch ("boto3.client" )
2144+ def test_get_user_name_long_arn (self , mock_boto3_client ):
2145+ mock_client = MagicMock ()
2146+ mock_boto3_client .return_value = mock_client
2147+
2148+ mock_identity = MagicMock ()
2149+ mock_client .get_caller_identity .return_value = mock_identity
2150+
2151+ long_user_name = "ReadOnly/AmazonSageMaker-a-long-long-long-long-long-long-long-arn-for-testing-get-user-name"
2152+ long_arn = "arn:aws:iam::0123456789012:assumed-role/" + long_user_name
2153+ mock_identity .get .return_value = long_arn
2154+ self .assertEqual (get_user_name (), "AssumedRole-" + long_user_name .replace ("/" , "-" )[:43 ] + "-trimmed" )
You can’t perform that action at this time.
0 commit comments