Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: adding availability to specify CPU and Memory of K8s deployment #13

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ outputs:
modelInstanceId:
description: "ModelInstance id registered by the API"
inputs:
resourceMemory:
description: "Specify resources memory of the application to deploy"
required: false
default: "-1"
resourceCPU:
description: "Specify resources CPU of the application to deploy"
required: false
default: "-1"
lokiSkip:
description: "Skips Loki ArgoWorkflow."
required: true
Expand Down
23 changes: 18 additions & 5 deletions bookish.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ def waitForHealthy(self):

print(f"Waiting for {tts}s")
time.sleep(tts)

if status != "Healthy":
raise RuntimeError(f"Health status error: {status} after all retries")
raise RuntimeError(
f"Health status error: {status} after all retries")

def checkApplicationExists(self) -> bool:
import requests # pylint: disable=import-error
Expand All @@ -221,8 +222,7 @@ def generateArgoApplicationSpec(self) -> dict:
chart_version = self.env_vars.get("MODEL_HELM_CHART_VERSION")
server_dest = "https://34.91.136.161"
metadata = {"name": self.application_name, "namespace": "default"}

helm = {"parameters": [
parameters = [
{"name": "app.env", "value": self._workerEnv},
{"name": "image.imageName", "value": self.applied_repo},
{"name": "image.version", "value": self.model_version[1:]},
Expand All @@ -240,7 +240,19 @@ def generateArgoApplicationSpec(self) -> dict:
"NUTSHELL_WORKER_MODEL_PREDICT_TIMEOUT_S")},
{"name": "model.path", "value": self.env_vars.get(
"NUTSHELL_MODEL_PATH")}
]}
]

resource_cpu = int(os.environ.get("INPUT_RESOURCEMEMORY", "-1"))
if resource_cpu > -1:
self._send_slack_message(f"Set CPU resource amount to {resource_cpu}", self._thread_ts)
parameters.append({"name": "resources.cpu", "value": resource_cpu})
resource_memory = int(os.environ.get("INPUT_RESOURCECPU", "-1"))
if resource_memory > -1:
self._send_slack_message(f"Set memory resource amount to {resource_memory}", self._thread_ts)
parameters.append(
{"name": "resources.memory", "value": resource_memory})

helm = {"parameters": parameters}

if not self._hasSHA:
helm["parameters"] = helm.get("parameters", []) + [{
Expand Down Expand Up @@ -384,5 +396,6 @@ def end(self):
print(
f"ModelInstanceId({self._model_instance_id}) file is saved at = {url}")


if __name__ == '__main__':
ModelDeployment(use_cli=True)