@@ -46,6 +46,11 @@ class InvalidConfigError(Exception):
4646 pass
4747
4848
49+ class ServiceUnavailableError (Exception ):
50+ '''Error that will be raised when a service is not available'''
51+ pass
52+
53+
4954#
5055# Private functions
5156#
@@ -127,20 +132,26 @@ def _retrieve_jupyter_lab_url(workspaceName: str, namespace: str = "default", pr
127132 _print_invalid_config_error ()
128133 raise InvalidConfigError ()
129134
130- # Retrieve access port
131135 try :
132136 api = client .CoreV1Api ()
133137 serviceStatus = api .read_namespaced_service (namespace = namespace ,
134138 name = _get_jupyter_lab_service (workspaceName = workspaceName ))
135- port = serviceStatus .spec .ports [0 ].node_port
136- loadBalancerIP = serviceStatus .status .load_balancer .ingress [0 ].ip
137139
138140 # Check if service type is LoadBalancer
139141 if serviceStatus .spec .type == "LoadBalancer" :
140142 # Construct and return url
143+ try :
144+ loadBalancerIP = serviceStatus .status .load_balancer .ingress [0 ].ip
145+ except :
146+ if printOutput :
147+ print ("Error: Kubernetes Service for workspace is not available." )
148+ raise ServiceUnavailableError ()
141149 return "http://" + loadBalancerIP
142150 else :
143- # Retrieve node IP (random node)
151+ # Retrieve access port
152+ port = serviceStatus .spec .ports [0 ].node_port
153+
154+ # Retrieve node IP (random node)
144155 try :
145156 api = client .CoreV1Api ()
146157 nodes = api .list_node ()
@@ -608,7 +619,7 @@ def create_jupyter_lab(workspace_name: str, workspace_size: str, storage_class:
608619 # Step 4 - Retrieve access URL
609620 try :
610621 url = _retrieve_jupyter_lab_url (workspaceName = workspace_name , namespace = namespace , printOutput = print_output )
611- except APIConnectionError as err :
622+ except ( APIConnectionError , ServiceUnavailableError ) as err :
612623 if print_output :
613624 print ("Aborting workspace creation..." )
614625 raise
@@ -951,8 +962,14 @@ def list_jupyter_labs(namespace: str = "default", print_output: bool = False) ->
951962 workspaceDict ["StorageClass" ] = ""
952963
953964 # Retrieve access URL
954- workspaceDict ["Access URL" ] = _retrieve_jupyter_lab_url (workspaceName = workspaceName , namespace = namespace ,
955- printOutput = print_output )
965+ try :
966+ workspaceDict ["Access URL" ] = _retrieve_jupyter_lab_url (workspaceName = workspaceName , namespace = namespace , printOutput = False )
967+ except ServiceUnavailableError :
968+ workspaceDict ["Access URL" ] = "unavailable"
969+ except APIConnectionError as err :
970+ if print_output :
971+ print ("Error: Kubernetes API Error: " , err )
972+ raise APIConnectionError (err )
956973
957974 # Retrieve clone details
958975 try :
0 commit comments