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

feat(argowf_pipeline): Execute pipeline via ArgoWF #172

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions skit_pipelines/api/argowf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from loguru import logger
from constants import SKIT_PIPELINES_ARGO_MANIFEST


def generate_args_list(pipeline_name: str, payload: dict):
cli_args_list = []
logger.debug(f"Incoming Payload - {payload}")
pipeline_name_cli_arg = f"--pipeline_name={pipeline_name}"
cli_args_list.append(pipeline_name_cli_arg)
for key, value in payload.items():
cli_arg_string = f"--{key}={value}"
cli_args_list.append(cli_arg_string)
logger.debug(f"Final args list - {cli_args_list}")
return cli_args_list


def prepare_argo_payload(final_args_list):
logger.debug(f"SKIT PIPELINES MANIFEST - {SKIT_PIPELINES_ARGO_MANIFEST}")
workflow_spec = SKIT_PIPELINES_ARGO_MANIFEST.get("workflow", {}).get("spec", {})
skit_pipeline_template = workflow_spec.get("templates", [{}])[0]
args_list = skit_pipeline_template.get("container", {}).get("args", [])
args_list.extend(final_args_list)
logger.debug(f"Final modified SKIT_PIPELINES_ARGO_MANIFEST - {SKIT_PIPELINES_ARGO_MANIFEST}")
return SKIT_PIPELINES_ARGO_MANIFEST


def initiate_workflow_via_argo(pipeline_name, payload):
cli_args_list = generate_args_list(pipeline_name, payload)
final_argo_manifest = prepare_argo_payload(cli_args_list)
return final_argo_manifest
18 changes: 18 additions & 0 deletions skit_pipelines/api/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import json
from loguru import logger

TRIGGER_WORKFLOW_VIA_ARGO = os.environ.get("TRIGGER_WORKFLOW_VIA_ARGO", "false").lower()
if TRIGGER_WORKFLOW_VIA_ARGO == "true":
TRIGGER_WORKFLOW_VIA_ARGO = True
else:
TRIGGER_WORKFLOW_VIA_ARGO = False


try:
with open("./resources/skit_pipelines_argo_manifest.json", "r+") as f:
Copy link
Collaborator

@d-shree d-shree Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the resources directory here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Got removed due to gitignore.

SKIT_PIPELINES_ARGO_MANIFEST = json.load(f)
except Exception as e:
logger.error(f"Some exception occurred when attempting to open Argo Manifest - {e}")
SKIT_PIPELINES_ARGO_MANIFEST = {}

13 changes: 10 additions & 3 deletions skit_pipelines/api/slack_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import requests
from jsoncomment import JsonComment
from loguru import logger
from constants import TRIGGER_WORKFLOW_VIA_ARGO
from argowf import initiate_workflow_via_argo

import skit_pipelines.constants as const
from skit_pipelines.api.validate_input import ValidateInput
Expand Down Expand Up @@ -103,9 +105,14 @@ def run_pipeline(
payload["notify"] = (
user if "notify" not in payload else f"{payload['notify']} ,{user}"
)
url_path = f"http://localhost:{server_port}/skit/pipelines/run/{pipeline_name}/"
access_token = read_access_token()
res = make_run_requests(url_path, payload, access_token)

if TRIGGER_WORKFLOW_VIA_ARGO:
response = initiate_workflow_via_argo(pipeline_name, payload)
return response
else:
url_path = f"http://localhost:{server_port}/skit/pipelines/run/{pipeline_name}/"
access_token = read_access_token()
res = make_run_requests(url_path, payload, access_token)

if res.status_code == 401:
new_access_token = read_access_token(token_fetch=True)
Expand Down