@@ -1322,6 +1322,7 @@ def prepare_gpus(system: SystemCharacteristics):
13221322 if err_code > 0 :
13231323 xpk_exit (err_code )
13241324
1325+
13251326def install_cert_manager (version : str = 'v1.13.0' ):
13261327 """
13271328 Apply the cert-manager manifest.
@@ -1331,7 +1332,8 @@ def install_cert_manager(version: str = 'v1.13.0'):
13311332 """
13321333
13331334 command = (
1334- f'kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/'
1335+ 'kubectl apply -f'
1336+ ' https://github.com/cert-manager/cert-manager/releases/download/'
13351337 f'{ version } /cert-manager.yaml'
13361338 )
13371339
@@ -1344,38 +1346,45 @@ def install_cert_manager(version: str = 'v1.13.0'):
13441346
13451347 return return_code
13461348
1349+
13471350def download_mldiagnostics_yaml (package_name : str , version : str ):
13481351 """
13491352 Downloads the mldiagnostics injection webhook YAML from Artifact Registry.
1350-
1353+
13511354 Returns:
13521355 0 if successful and 1 otherwise.
13531356 """
13541357
13551358 command = (
1356- f'gcloud artifacts generic download --repository=mldiagnostics-webhook-and-operator-yaml --location=us '
1357- f'--package={ package_name } --version={ version } --destination=./ '
1358- f'--project=ai-on-gke'
1359+ 'gcloud artifacts generic download'
1360+ ' --repository=mldiagnostics-webhook-and-operator-yaml --location=us'
1361+ f' --package={ package_name } --version={ version } --destination=./'
1362+ ' --project=ai-on-gke'
13591363 )
13601364
13611365 return_code , return_output = run_command_for_value (
1362- command , f'Starting gcloud artifacts download for { package_name } { version } ...'
1366+ command ,
1367+ f'Starting gcloud artifacts download for { package_name } { version } ...' ,
13631368 )
13641369
13651370 if return_code != 0 :
13661371 if 'already exists' in return_output :
1367- xpk_print (f'Artifact file for { package_name } { version } already exists locally. Skipping download.' )
1372+ xpk_print (
1373+ f'Artifact file for { package_name } { version } already exists locally.'
1374+ ' Skipping download.'
1375+ )
13681376 return 0
13691377 xpk_print (f'gcloud download returned with ERROR { return_code } .\n ' )
13701378 xpk_exit (return_code )
13711379
13721380 xpk_print ('Artifact download completed successfully.' )
13731381 return return_code
13741382
1383+
13751384def create_mldiagnostics_namespace ():
13761385 """
13771386 Creates the 'gke-diagon' namespace.
1378-
1387+
13791388 Returns:
13801389 0 if successful and 1 otherwise.
13811390 """
@@ -1396,6 +1405,7 @@ def create_mldiagnostics_namespace():
13961405 xpk_print ('gke-diagon Namespace created or already exists.' )
13971406 return return_code
13981407
1408+
13991409def install_mldiagnostics_yaml (artifact_filename : str ):
14001410 """
14011411 Applies the mldiagnostics injection webhook YAML manifest.
@@ -1422,25 +1432,32 @@ def install_mldiagnostics_yaml(artifact_filename: str):
14221432 xpk_print (f'Successfully deleted local file: { artifact_filename } ' )
14231433
14241434 except PermissionError :
1425- xpk_print (f'Failed to delete file { artifact_filename } due to Permission Error.' )
1435+ xpk_print (
1436+ f'Failed to delete file { artifact_filename } due to Permission Error.'
1437+ )
14261438
14271439 else :
1428- xpk_print (f'File { artifact_filename } does not exist locally. Skipping deletion (Cleanup assumed).' )
1440+ xpk_print (
1441+ f'File { artifact_filename } does not exist locally. Skipping deletion'
1442+ ' (Cleanup assumed).'
1443+ )
14291444
14301445 return return_code
14311446
1447+
14321448def label_default_namespace_mldiagnostics ():
14331449 """
14341450 Labels the 'default' namespace with 'diagon-enabled=true'.
1435-
1451+
14361452 Returns:
14371453 0 if successful and 1 otherwise.
14381454 """
14391455
14401456 command = 'kubectl label namespace default diagon-enabled=true'
14411457
14421458 return_code = run_command_with_updates (
1443- command , 'Starting kubectl label namespace default with diagon-enabled=true...'
1459+ command ,
1460+ 'Starting kubectl label namespace default with diagon-enabled=true...' ,
14441461 )
14451462
14461463 if return_code != 0 :
@@ -1450,6 +1467,7 @@ def label_default_namespace_mldiagnostics():
14501467 xpk_print ('default Namespace successfully labeled.' )
14511468 return return_code
14521469
1470+
14531471def install_diagon_prerequisites ():
14541472 """
14551473 Diagon installation requirements.
@@ -1468,22 +1486,28 @@ def install_diagon_prerequisites():
14681486 if return_code != 0 :
14691487 return return_code
14701488
1471- cert_webhook_ready = wait_for_deployment_ready (cert_webhook_deployment_name , cert_webhook_namespace_name )
1489+ cert_webhook_ready = wait_for_deployment_ready (
1490+ cert_webhook_deployment_name , cert_webhook_namespace_name
1491+ )
14721492 if cert_webhook_ready :
14731493
14741494 webhook_package = 'mldiagnostics-injection-webhook'
14751495 webhook_version = 'v0.3.0'
14761496 webhook_filename = f'{ webhook_package } -{ webhook_version } .yaml'
14771497
1478- return_code = download_mldiagnostics_yaml (package_name = webhook_package , version = webhook_version )
1498+ return_code = download_mldiagnostics_yaml (
1499+ package_name = webhook_package , version = webhook_version
1500+ )
14791501 if return_code != 0 :
14801502 return return_code
14811503
14821504 return_code = create_mldiagnostics_namespace ()
14831505 if return_code != 0 :
14841506 return return_code
14851507
1486- return_code = install_mldiagnostics_yaml (artifact_filename = webhook_filename )
1508+ return_code = install_mldiagnostics_yaml (
1509+ artifact_filename = webhook_filename
1510+ )
14871511 if return_code != 0 :
14881512 return return_code
14891513
@@ -1496,26 +1520,39 @@ def install_diagon_prerequisites():
14961520 operator_version = 'v0.3.0'
14971521 operator_filename = f'{ operator_package } -{ operator_version } .yaml'
14981522
1499- return_code = download_mldiagnostics_yaml (package_name = operator_package , version = operator_version )
1523+ return_code = download_mldiagnostics_yaml (
1524+ package_name = operator_package , version = operator_version
1525+ )
15001526 if return_code != 0 :
15011527 return return_code
15021528
1503- return_code = install_mldiagnostics_yaml (artifact_filename = operator_filename )
1529+ return_code = install_mldiagnostics_yaml (
1530+ artifact_filename = operator_filename
1531+ )
15041532 if return_code != 0 :
15051533 return return_code
15061534
1507- xpk_print ('All diagon installation and setup steps have been successfully completed!' )
1535+ xpk_print (
1536+ 'All diagon installation and setup steps have been successfully'
1537+ ' completed!'
1538+ )
15081539 return return_code
15091540 else :
15101541 xpk_print ('The cert-manager-webhook installation failed.' )
15111542 xpk_exit (1 )
15121543 else :
1513- xpk_print (f'Application { deployment_name } failed to become ready within the timeout.' )
1544+ xpk_print (
1545+ f'Application { deployment_name } failed to become ready within the'
1546+ ' timeout.'
1547+ )
15141548 xpk_exit (1 )
15151549
1516- def wait_for_deployment_ready (deployment_name : str , namespace : str , timeout_seconds : int = 300 ) -> bool :
1550+
1551+ def wait_for_deployment_ready (
1552+ deployment_name : str , namespace : str , timeout_seconds : int = 300
1553+ ) -> bool :
15171554 """
1518- Polls the Kubernetes Deployment status using kubectl rollout status
1555+ Polls the Kubernetes Deployment status using kubectl rollout status
15191556 until it successfully rolls out (all replicas are ready) or times out.
15201557
15211558 Args:
@@ -1532,7 +1569,10 @@ def wait_for_deployment_ready(deployment_name: str, namespace: str, timeout_seco
15321569 f' --timeout={ timeout_seconds } s'
15331570 )
15341571
1535- print (f'Waiting for deployment { deployment_name } in namespace { namespace } to successfully roll out...' )
1572+ print (
1573+ f'Waiting for deployment { deployment_name } in namespace { namespace } to'
1574+ ' successfully roll out...'
1575+ )
15361576
15371577 return_code , return_output = run_command_for_value (
15381578 command , f'Checking status of deployment { deployment_name } ...'
0 commit comments