Skip to content

Commit 46508b2

Browse files
committed
added and fixed docstrings
1 parent d11c95c commit 46508b2

File tree

1 file changed

+97
-3
lines changed

1 file changed

+97
-3
lines changed

datacrunch/containers/containers.py

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class ContainerDeploymentStatus(str, Enum):
4545
@dataclass_json
4646
@dataclass
4747
class HealthcheckSettings:
48+
"""Settings for container health checking.
49+
50+
:param enabled: Whether health checking is enabled
51+
:param port: Port number to perform health check on
52+
:param path: HTTP path to perform health check on
53+
"""
4854
enabled: bool
4955
port: Optional[int] = None
5056
path: Optional[str] = None
@@ -53,6 +59,12 @@ class HealthcheckSettings:
5359
@dataclass_json
5460
@dataclass
5561
class EntrypointOverridesSettings:
62+
"""Settings for overriding container entrypoint and command.
63+
64+
:param enabled: Whether entrypoint overrides are enabled
65+
:param entrypoint: List of strings forming the entrypoint command
66+
:param cmd: List of strings forming the command arguments
67+
"""
5668
enabled: bool
5769
entrypoint: Optional[List[str]] = None
5870
cmd: Optional[List[str]] = None
@@ -61,6 +73,12 @@ class EntrypointOverridesSettings:
6173
@dataclass_json
6274
@dataclass
6375
class EnvVar:
76+
"""Environment variable configuration for containers.
77+
78+
:param name: Name of the environment variable
79+
:param value_or_reference_to_secret: Direct value or reference to a secret
80+
:param type: Type of the environment variable
81+
"""
6482
name: str
6583
value_or_reference_to_secret: str
6684
type: EnvVarType
@@ -69,13 +87,28 @@ class EnvVar:
6987
@dataclass_json
7088
@dataclass
7189
class VolumeMount:
90+
"""Volume mount configuration for containers.
91+
92+
:param type: Type of volume mount
93+
:param mount_path: Path where the volume should be mounted in the container
94+
"""
7295
type: VolumeMountType
7396
mount_path: str
7497

7598

7699
@dataclass_json
77100
@dataclass
78101
class Container:
102+
"""Container configuration for deployments.
103+
104+
:param name: Name of the container
105+
:param image: Container image to use
106+
:param exposed_port: Port to expose from the container
107+
:param healthcheck: Optional health check configuration
108+
:param entrypoint_overrides: Optional entrypoint override settings
109+
:param env: Optional list of environment variables
110+
:param volume_mounts: Optional list of volume mounts
111+
"""
79112
name: str
80113
image: str
81114
exposed_port: int
@@ -88,19 +121,34 @@ class Container:
88121
@dataclass_json
89122
@dataclass
90123
class ContainerRegistryCredentials:
124+
"""Credentials for accessing a container registry.
125+
126+
:param name: Name of the credentials
127+
"""
91128
name: str
92129

93130

94131
@dataclass_json
95132
@dataclass
96133
class ContainerRegistrySettings:
134+
"""Settings for container registry access.
135+
136+
:param is_private: Whether the registry is private
137+
:param credentials: Optional credentials for accessing private registry
138+
"""
97139
is_private: bool
98140
credentials: Optional[ContainerRegistryCredentials] = None
99141

100142

101143
@dataclass_json
102144
@dataclass
103145
class ComputeResource:
146+
"""Compute resource configuration.
147+
148+
:param name: Name of the compute resource
149+
:param size: Size of the compute resource
150+
:param is_available: Whether the compute resource is currently available
151+
"""
104152
name: str
105153
size: int
106154
# Made optional since it's only used in API responses
@@ -110,25 +158,44 @@ class ComputeResource:
110158
@dataclass_json
111159
@dataclass
112160
class ScalingPolicy:
161+
"""Policy for controlling scaling behavior.
162+
163+
:param delay_seconds: Number of seconds to wait before applying scaling action
164+
"""
113165
delay_seconds: int
114166

115167

116168
@dataclass_json
117169
@dataclass
118170
class QueueLoadScalingTrigger:
171+
"""Trigger for scaling based on queue load.
172+
173+
:param threshold: Queue load threshold that triggers scaling
174+
"""
119175
threshold: float
120176

121177

122178
@dataclass_json
123179
@dataclass
124180
class UtilizationScalingTrigger:
181+
"""Trigger for scaling based on resource utilization.
182+
183+
:param enabled: Whether this trigger is enabled
184+
:param threshold: Utilization threshold that triggers scaling
185+
"""
125186
enabled: bool
126187
threshold: Optional[float] = None
127188

128189

129190
@dataclass_json
130191
@dataclass
131192
class ScalingTriggers:
193+
"""Collection of triggers that can cause scaling actions.
194+
195+
:param queue_load: Optional trigger based on queue load
196+
:param cpu_utilization: Optional trigger based on CPU utilization
197+
:param gpu_utilization: Optional trigger based on GPU utilization
198+
"""
132199
queue_load: Optional[QueueLoadScalingTrigger] = None
133200
cpu_utilization: Optional[UtilizationScalingTrigger] = None
134201
gpu_utilization: Optional[UtilizationScalingTrigger] = None
@@ -137,6 +204,16 @@ class ScalingTriggers:
137204
@dataclass_json
138205
@dataclass
139206
class ScalingOptions:
207+
"""Configuration for automatic scaling behavior.
208+
209+
:param min_replica_count: Minimum number of replicas to maintain
210+
:param max_replica_count: Maximum number of replicas allowed
211+
:param scale_down_policy: Policy for scaling down replicas
212+
:param scale_up_policy: Policy for scaling up replicas
213+
:param queue_message_ttl_seconds: Time-to-live for queue messages in seconds
214+
:param concurrent_requests_per_replica: Number of concurrent requests each replica can handle
215+
:param scaling_triggers: Configuration for various scaling triggers
216+
"""
140217
min_replica_count: int
141218
max_replica_count: int
142219
scale_down_policy: ScalingPolicy
@@ -149,6 +226,17 @@ class ScalingOptions:
149226
@dataclass_json(undefined=Undefined.EXCLUDE)
150227
@dataclass
151228
class Deployment:
229+
"""Configuration for a container deployment.
230+
231+
:param name: Name of the deployment
232+
:param container_registry_settings: Settings for accessing container registry
233+
:param containers: List of containers in the deployment
234+
:param compute: Compute resource configuration
235+
:param is_spot: Whether is spot deployment
236+
:param endpoint_base_url: Optional base URL for the deployment endpoint
237+
:param scaling: Optional scaling configuration
238+
:param created_at: Timestamp when the deployment was created
239+
"""
152240
name: str
153241
container_registry_settings: ContainerRegistrySettings
154242
containers: List[Container]
@@ -170,6 +258,12 @@ class Deployment:
170258
@dataclass_json
171259
@dataclass
172260
class ReplicaInfo:
261+
"""Information about a deployment replica.
262+
263+
:param id: Unique identifier of the replica
264+
:param status: Current status of the replica
265+
:param started_at: Timestamp when the replica was started
266+
"""
173267
id: str
174268
status: str
175269
started_at: datetime = field(
@@ -332,13 +426,13 @@ def update_deployment_scaling_options(self, deployment_name: str, scaling_option
332426
)
333427
return ScalingOptions.from_dict(response.json())
334428

335-
def get_deployment_replicas(self, deployment_name: str) -> ReplicaInfo:
429+
def get_deployment_replicas(self, deployment_name: str) -> List[ReplicaInfo]:
336430
"""Get deployment replicas
337431
338432
:param deployment_name: name of the deployment
339433
:type deployment_name: str
340-
:return: replicas information
341-
:rtype: ReplicaInfo
434+
:return: list of replicas information
435+
:rtype: List[ReplicaInfo]
342436
"""
343437
response = self.client.get(
344438
f"{CONTAINER_DEPLOYMENTS_ENDPOINT}/{deployment_name}/replicas")

0 commit comments

Comments
 (0)