13
13
# limitations under the License.
14
14
import re
15
15
import time
16
+ from typing import Any
16
17
17
18
import munch
18
19
from rapyuta_io_sdk_v2 import Client
@@ -34,10 +35,11 @@ def fetch_deployments(
34
35
client : Client ,
35
36
deployment_name_or_regex : str ,
36
37
include_all : bool ,
37
- ) -> list :
38
+ ) -> list [ Any ] :
38
39
deployments = client .list_deployments (phases = DEFAULT_PHASES )
39
40
result = []
40
- for deployment in deployments .items :
41
+ items = deployments .items if deployments .items is not None else []
42
+ for deployment in items :
41
43
if (
42
44
include_all
43
45
or deployment_name_or_regex == deployment .metadata .name
@@ -75,7 +77,7 @@ def poll_deployment(
75
77
name : str ,
76
78
retry_count : int = 50 ,
77
79
sleep_interval : int = 6 ,
78
- ready_phases : list [str ] = None ,
80
+ ready_phases : list [str ] | None = None ,
79
81
):
80
82
if ready_phases is None :
81
83
ready_phases = []
@@ -84,18 +86,27 @@ def poll_deployment(
84
86
status = deployment .status
85
87
86
88
for _ in range (retry_count ):
87
- if status .phase in ready_phases :
89
+ if status is not None and status .phase in ready_phases :
88
90
return deployment
89
91
90
- if status .phase == DeploymentPhaseConstants .DeploymentPhaseProvisioning .value :
92
+ if (
93
+ status is not None
94
+ and status .phase == DeploymentPhaseConstants .DeploymentPhaseProvisioning .value
95
+ ):
91
96
errors = status .get ("error_codes" , [])
92
97
if "DEP_E153" in errors :
93
98
raise ImagePullError (
94
99
f"Deployment not running. Phase: Provisioning Status: { status .phase } "
95
100
)
96
- elif status .phase == DeploymentPhaseConstants .DeploymentPhaseSucceeded .value :
101
+ elif (
102
+ status is not None
103
+ and status .phase == DeploymentPhaseConstants .DeploymentPhaseSucceeded .value
104
+ ):
97
105
return deployment
98
- elif status .phase == DeploymentPhaseConstants .DeploymentPhaseStopped .value :
106
+ elif (
107
+ status is not None
108
+ and status .phase == DeploymentPhaseConstants .DeploymentPhaseStopped .value
109
+ ):
99
110
raise DeploymentNotRunning (
100
111
f"Deployment not running. Phase: Stopped Status: { status .phase } "
101
112
)
@@ -104,9 +115,12 @@ def poll_deployment(
104
115
deployment = client .get_deployment (name = name )
105
116
status = deployment .status
106
117
118
+ error_codes = []
119
+ if status is not None and hasattr (status , "error_codes" ):
120
+ error_codes = status .error_codes or []
107
121
msg = (
108
122
f"Retries exhausted: Tried { retry_count } times with { sleep_interval } s interval. "
109
123
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 } "
111
125
)
112
126
raise RetriesExhausted (msg )
0 commit comments