Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #752 from zhxu73/wf-naming
Browse files Browse the repository at this point in the history
add username & instance_uuid label to workflow
  • Loading branch information
zhxu73 authored Nov 25, 2020
2 parents e01fe7c + 2325228 commit bf345eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
-->
## [Unreleased](https://github.com/cyverse/atmosphere/compare/v37-2...HEAD) - YYYY-MM-DD
### Changed
- add `username` and `instance_uuid` label to the argo workflows launched
- bump ansible to 2.8
- calls `ansible-playbook` executable directly to execute ansible playbooks

Expand Down
16 changes: 13 additions & 3 deletions service/argo/instance_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def argo_deploy_instance(
Args:
provider_uuid (str): provider uuid
instance_uuid (str): instance uuid
server_ip (str): ip of the server instance
username (str): username
timezone (str): timezone of the provider, e.g. America/Arizona
Expand All @@ -34,7 +35,7 @@ def argo_deploy_instance(
"""
try:
wf_data = _get_workflow_data(
provider_uuid, server_ip, username, timezone
provider_uuid, instance_uuid, server_ip, username, timezone
)

wf, status = argo_workflow_exec(
Expand Down Expand Up @@ -62,19 +63,28 @@ def argo_deploy_instance(
raise exc


def _get_workflow_data(provider_uuid, server_ip, username, timezone):
def _get_workflow_data(
provider_uuid, instance_uuid, server_ip, username, timezone
):
"""
Generate the data structure to be passed to the workflow
Args:
provider_uuid (str): provider uuid
instance_uuid (str): instance uuid
server_ip (str): ip of the server instance
username (str): username of the owner of the instance
timezone (str): timezone of the provider
Returns:
dict: {"arguments": {"parameters": [{"name": "", "value": ""}]}}
"""
wf_data = {"arguments": {"parameters": []}}
wf_data = {"metadata": {"labels": {}}, "arguments": {"parameters": []}}

# labels
wf_data["metadata"]["labels"]["instance_uuid"] = instance_uuid
wf_data["metadata"]["labels"]["username"] = username

wf_data["arguments"]["parameters"].append(
{
"name": "server-ip",
Expand Down
4 changes: 4 additions & 0 deletions service/argo/wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def create(context, wf_def, wf_data={}, lint=False):

json_resp = context.client().run_workflow(wf_def)
wf_name = json_resp["metadata"]["name"]
logger.debug("ARGO, workflow {} created".format(wf_name))
return ArgoWorkflow(wf_name)

@staticmethod
Expand Down Expand Up @@ -307,6 +308,9 @@ def _populate_wf_data(wf_def, wf_data):
Returns:
dict: workflow definition with the workflow data populated
"""
if "metadata" in wf_data and "labels" in wf_data["metadata"]:
wf_def["metadata"]["labels"] = wf_data["metadata"]["labels"]

if not wf_data["arguments"]:
return wf_def
if not wf_def["spec"]["arguments"]:
Expand Down

0 comments on commit bf345eb

Please sign in to comment.