diff --git a/CHANGELOG.md b/CHANGELOG.md index d69c9684c..733a099d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/service/argo/instance_deploy.py b/service/argo/instance_deploy.py index f9eb151cc..55e8174d7 100644 --- a/service/argo/instance_deploy.py +++ b/service/argo/instance_deploy.py @@ -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 @@ -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( @@ -62,11 +63,15 @@ 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 @@ -74,7 +79,12 @@ def _get_workflow_data(provider_uuid, server_ip, username, timezone): 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", diff --git a/service/argo/wf.py b/service/argo/wf.py index 212d0c2ed..d089319d5 100644 --- a/service/argo/wf.py +++ b/service/argo/wf.py @@ -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 @@ -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"]: