Skip to content

Commit c405753

Browse files
committed
[HWORKS-2476] Add support for configuring environment variables in Deployments
1 parent fd0da54 commit c405753

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

python/hsml/deployment.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,18 @@ def environment(self):
539539
def environment(self, environment: str):
540540
self._predictor.environment = environment
541541

542+
@property
543+
def env_vars(self):
544+
"""Environment variables of the deployment"""
545+
return self._predictor.env_vars
546+
547+
@env_vars.setter
548+
def env_vars(self, env_vars: str):
549+
self._predictor.env_vars = env_vars
550+
542551
@property
543552
def project_namespace(self):
544-
"""Name of inference environment"""
553+
"""Name of kubernetes namespace the project is in"""
545554
return self._predictor.project_namespace
546555

547556
@project_namespace.setter

python/hsml/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def deploy(
208208
transformer: Optional[Union[Transformer, dict]] = None,
209209
api_protocol: Optional[str] = IE.API_PROTOCOL_REST,
210210
environment: Optional[str] = None,
211+
env_vars: Optional[dict] = None,
211212
) -> deployment.Deployment:
212213
"""Deploy the model.
213214
@@ -266,6 +267,7 @@ def deploy(
266267
transformer=transformer,
267268
api_protocol=api_protocol,
268269
environment=environment,
270+
env_vars=env_vars,
269271
)
270272

271273
return predictor.deploy()

python/hsml/model_serving.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def create_predictor(
171171
transformer: Optional[Union[Transformer, dict]] = None,
172172
api_protocol: Optional[str] = IE.API_PROTOCOL_REST,
173173
environment: Optional[str] = None,
174+
env_vars: Optional[dict] = None,
174175
) -> Predictor:
175176
"""Create a Predictor metadata object.
176177
@@ -212,6 +213,7 @@ def create_predictor(
212213
transformer: Transformer to be deployed together with the predictor.
213214
api_protocol: API protocol to be enabled in the deployment (i.e., 'REST' or 'GRPC'). Defaults to 'REST'.
214215
environment: The project Python environment to use
216+
env_vars: Additional environment variables to use
215217
216218
# Returns
217219
`Predictor`. The predictor metadata object.
@@ -232,6 +234,7 @@ def create_predictor(
232234
transformer=transformer,
233235
api_protocol=api_protocol,
234236
environment=environment,
237+
env_vars=env_vars,
235238
)
236239

237240
@usage.method_logger
@@ -313,6 +316,7 @@ def create_endpoint(
313316
inference_batcher: Optional[Union[InferenceBatcher, dict]] = None,
314317
api_protocol: Optional[str] = IE.API_PROTOCOL_REST,
315318
environment: Optional[str] = None,
319+
env_vars: Optional[dict] = None,
316320
) -> Predictor:
317321
"""Create an Entrypoint metadata object.
318322
@@ -341,6 +345,7 @@ def create_endpoint(
341345
inference_batcher: Inference batcher configuration.
342346
api_protocol: API protocol to be enabled in the deployment (i.e., 'REST' or 'GRPC'). Defaults to 'REST'.
343347
environment: The project Python environment to use
348+
env_vars: Additional environment variables to use
344349
345350
# Returns
346351
`Predictor`. The predictor metadata object.
@@ -355,6 +360,7 @@ def create_endpoint(
355360
inference_batcher=inference_batcher,
356361
api_protocol=api_protocol,
357362
environment=environment,
363+
env_vars=env_vars,
358364
)
359365

360366
@usage.method_logger

python/hsml/predictor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
api_protocol: Optional[str] = INFERENCE_ENDPOINTS.API_PROTOCOL_REST,
6666
environment: Optional[str] = None,
6767
project_namespace: str = None,
68+
env_vars: Optional[dict] = None,
6869
**kwargs,
6970
):
7071
serving_tool = (
@@ -104,6 +105,7 @@ def __init__(
104105
self._environment = environment
105106
self._project_namespace = project_namespace
106107
self._project_name = None
108+
self._env_vars = env_vars
107109

108110
def deploy(self):
109111
"""Create a deployment for this predictor and persists it in the Model Serving.
@@ -302,6 +304,8 @@ def extract_fields_from_json(cls, json_decamelized):
302304
if "environment_dto" in json_decamelized:
303305
environment = json_decamelized.pop("environment_dto")
304306
kwargs["environment"] = environment["name"]
307+
if "env_vars" in json_decamelized:
308+
kwargs["env_vars"] = json_decamelized.pop("env_vars")
305309
kwargs["project_namespace"] = json_decamelized.pop("project_namespace")
306310
return kwargs
307311

@@ -337,6 +341,8 @@ def to_dict(self):
337341
json = {**json, **{"modelVersion": self._model_version}}
338342
if self.model_framework is not None:
339343
json = {**json, **{"modelFramework": self._model_framework}}
344+
if self.env_vars is not None:
345+
json = {**json, **{"envVars": self._env_vars}}
340346
if self.environment is not None:
341347
json = {**json, **{"environmentDTO": {"name": self._environment}}}
342348
if self._resources is not None:
@@ -533,6 +539,15 @@ def api_protocol(self):
533539
def api_protocol(self, api_protocol):
534540
self._api_protocol = api_protocol
535541

542+
@property
543+
def env_vars(self):
544+
"""Environment variables of the inference environment"""
545+
return self._env_vars
546+
547+
@env_vars.setter
548+
def env_vars(self, env_vars):
549+
self._env_vars = env_vars
550+
536551
@property
537552
def environment(self):
538553
"""Name of the inference environment"""

0 commit comments

Comments
 (0)