1313# limitations under the License.
1414import re
1515import time
16+ from typing import Any
1617
1718import munch
1819from rapyuta_io_sdk_v2 import Client
@@ -34,10 +35,11 @@ def fetch_deployments(
3435 client : Client ,
3536 deployment_name_or_regex : str ,
3637 include_all : bool ,
37- ) -> list :
38+ ) -> list [ Any ] :
3839 deployments = client .list_deployments (phases = DEFAULT_PHASES )
3940 result = []
40- for deployment in deployments .items :
41+ items = deployments .items if deployments .items is not None else []
42+ for deployment in items :
4143 if (
4244 include_all
4345 or deployment_name_or_regex == deployment .metadata .name
@@ -75,7 +77,7 @@ def poll_deployment(
7577 name : str ,
7678 retry_count : int = 50 ,
7779 sleep_interval : int = 6 ,
78- ready_phases : list [str ] = None ,
80+ ready_phases : list [str ] | None = None ,
7981):
8082 if ready_phases is None :
8183 ready_phases = []
@@ -84,18 +86,27 @@ def poll_deployment(
8486 status = deployment .status
8587
8688 for _ in range (retry_count ):
87- if status .phase in ready_phases :
89+ if status is not None and status .phase in ready_phases :
8890 return deployment
8991
90- if status .phase == DeploymentPhaseConstants .DeploymentPhaseProvisioning .value :
92+ if (
93+ status is not None
94+ and status .phase == DeploymentPhaseConstants .DeploymentPhaseProvisioning .value
95+ ):
9196 errors = status .get ("error_codes" , [])
9297 if "DEP_E153" in errors :
9398 raise ImagePullError (
9499 f"Deployment not running. Phase: Provisioning Status: { status .phase } "
95100 )
96- elif status .phase == DeploymentPhaseConstants .DeploymentPhaseSucceeded .value :
101+ elif (
102+ status is not None
103+ and status .phase == DeploymentPhaseConstants .DeploymentPhaseSucceeded .value
104+ ):
97105 return deployment
98- elif status .phase == DeploymentPhaseConstants .DeploymentPhaseStopped .value :
106+ elif (
107+ status is not None
108+ and status .phase == DeploymentPhaseConstants .DeploymentPhaseStopped .value
109+ ):
99110 raise DeploymentNotRunning (
100111 f"Deployment not running. Phase: Stopped Status: { status .phase } "
101112 )
@@ -104,9 +115,12 @@ def poll_deployment(
104115 deployment = client .get_deployment (name = name )
105116 status = deployment .status
106117
118+ error_codes = []
119+ if status is not None and hasattr (status , "error_codes" ):
120+ error_codes = status .error_codes or []
107121 msg = (
108122 f"Retries exhausted: Tried { retry_count } times with { sleep_interval } s interval. "
109123 f"Deployment: phase={ status .phase } status={ status .status } \n "
110- f"{ process_errors (status . get ( ' error_codes' , [])) } "
124+ f"{ process_errors (error_codes ) if callable ( process_errors ) else process_errors } "
111125 )
112126 raise RetriesExhausted (msg )
0 commit comments