1- import os , json , logging , yaml , time , uuid
1+ import os , logging , yaml , time , uuid
22from dataiku .cluster import Cluster
33
44from azure .mgmt .containerservice import ContainerServiceClient
77from azure .mgmt .authorization import AuthorizationManagementClient
88from azure .core .pipeline .policies import UserAgentPolicy
99from azure .core .exceptions import ResourceNotFoundError , HttpResponseError
10- from msrestazure .azure_exceptions import CloudError
1110
12- from dku_utils .access import _is_none_or_blank , _has_not_blank_property
13- from dku_utils .cluster import make_overrides , get_cluster_from_connection_info
11+ from dku_utils .access import _is_none_or_blank
12+ from dku_utils .cluster import make_overrides
1413from dku_kube .nvidia_utils import add_gpu_driver_if_needed
1514from dku_azure .auth import get_credentials_from_connection_info , get_credentials_from_connection_infoV2
1615from dku_azure .clusters import ClusterBuilder
17- from dku_azure .utils import run_and_process_cloud_error , get_subnet_id , get_instance_metadata , get_subscription_id
18- from dku_azure .auth import AzureIdentityCredentialAdapter
16+ from dku_azure .utils import run_and_process_cloud_error , get_instance_metadata , get_subscription_id
1917
2018class MyCluster (Cluster ):
2119 def __init__ (self , cluster_id , cluster_name , config , plugin_config ):
@@ -84,9 +82,7 @@ def start(self):
8482 existing = clusters_client .managed_clusters .get (resource_group , self .cluster_name )
8583 if existing is not None :
8684 raise Exception ("A cluster with name %s in resource group %s already exists" % (self .cluster_name , resource_group ))
87- except CloudError as e :
88- logging .info ("Cluster doesn't seem to exist yet" )
89- except ResourceNotFoundError as e :
85+ except ResourceNotFoundError :
9086 logging .info ("Cluster doesn't seem to exist yet" )
9187
9288 cluster_builder = ClusterBuilder (clusters_client )
@@ -153,7 +149,7 @@ def start(self):
153149 if not cluster_identity .get ("useAKSManagedKubeletIdentity" ,True ):
154150 kubelet_mi = cluster_identity ["kubeletUserAssignedIdentity" ]
155151 _ ,_ ,mi_subscription_id ,_ ,mi_resource_group ,_ ,_ ,_ ,mi_name = kubelet_mi .split ("/" )
156- msiclient = ManagedServiceIdentityClient (AzureIdentityCredentialAdapter ( credentials ) , mi_subscription_id )
152+ msiclient = ManagedServiceIdentityClient (credentials , mi_subscription_id )
157153 mi = msiclient .user_assigned_identities .get (mi_resource_group , mi_name )
158154 cluster_builder .with_kubelet_identity (kubelet_mi , mi .client_id , mi .principal_id )
159155 logging .info ("Configure kubelet identity with user assigned identity resourceId=\" {}\" , clientId=\" {}\" , objectId=\" {}\" " .format (kubelet_mi , mi .client_id , mi .principal_id ))
@@ -184,7 +180,7 @@ def start(self):
184180 acr_scope = "/subscriptions/{acr_subscription_id}/resourceGroups/{acr_resource_group}/providers/Microsoft.ContainerRegistry/registries/{acr_name}" .format (** locals ())
185181 try :
186182 acr_roles = list (authorization_client .role_definitions .list (acr_scope ,"roleName eq 'AcrPull'" ))
187- except ResourceNotFoundError as e :
183+ except ResourceNotFoundError :
188184 raise Exception ("ACR {} not found. Check it exists and you are Owner of it." .format (acr_scope ))
189185 if 0 == len (acr_roles ):
190186 raise Exception ("Could not find the AcrPull role on the ACR {}. Check you are Owner of it." .format (acr_scope ))
@@ -245,9 +241,9 @@ def start(self):
245241 authorization_client = AuthorizationManagementClient (credentials , subscription_id )
246242 try :
247243 vnet_roles = list (authorization_client .role_definitions .list (vnet_id ,"roleName eq 'Contributor'" ))
248- except ResourceNotFoundError as e :
244+ except ResourceNotFoundError :
249245 raise Exception ("Vnet {} not found. Check it exists and you are Owner of it." .format (vnet_id ))
250- if 0 == len (acr_roles ):
246+ if 0 == len (vnet_roles ):
251247 raise Exception ("Could not find the Contributor role on the vnet {}. Check you are Owner of it." .format (vnet_id ))
252248 else :
253249 vnet_role_id = vnet_roles [0 ].id
@@ -424,7 +420,7 @@ def stop(self, data):
424420 authorization_client = AuthorizationManagementClient (credentials , acr_attachment ["subscription_id" ])
425421 try :
426422 authorization_client .role_assignments .delete_by_id (acr_attachment ["role_assignment" ]["id" ])
427- except ResourceNotFoundError as e :
423+ except ResourceNotFoundError :
428424 logging .warn ("It looks that the ACR role assignment doesnt exist. Ignore this step" )
429425
430426 # Detach Vnet like ACR
@@ -436,13 +432,13 @@ def stop(self, data):
436432 authorization_client = AuthorizationManagementClient (credentials , vnet_attachment ["subscription_id" ])
437433 try :
438434 authorization_client .role_assignments .delete_by_id (vnet_attachment ["role_assignment" ]["id" ])
439- except ResourceNotFoundError as e :
435+ except ResourceNotFoundError :
440436 logging .warn ("It looks that the Vnet role assignment doesnt exist. Ignore this step" )
441437
442438 def do_delete ():
443439 future = clusters_client .managed_clusters .begin_delete (resource_group , cluster_name )
444440 return future .result ()
445- delete_result = run_and_process_cloud_error (do_delete )
441+ run_and_process_cloud_error (do_delete )
446442
447443 # delete returns void, so we poll until the cluster is really gone
448444 gone = False
@@ -453,6 +449,6 @@ def do_delete():
453449 if cluster .provisioning_state .lower () != 'deleting' :
454450 logging .info ("Cluster is not deleting anymore, must be deleted now (state = %s)" % cluster .provisioning_state )
455451 # other exceptions should not be ignored
456- except ResourceNotFoundError as e :
452+ except ResourceNotFoundError :
457453 logging .info ("Cluster doesn't seem to exist anymore, considering it deleted" )
458454 gone = True
0 commit comments