From 475e426373fdd6e3a9b11fadb9414e842cae0a46 Mon Sep 17 00:00:00 2001 From: Jose Aguirre Date: Tue, 13 Feb 2018 21:20:57 -0800 Subject: [PATCH] Add argo UI urls to gubernator metadata (#29) Would like to provide a link to workflow URLs in gubernator. Changes made: Pass ui_urls into create_finished to use in the metadata. --- py/kubeflow/testing/prow_artifacts.py | 6 ++++-- py/kubeflow/testing/prow_artifacts_test.py | 8 +++++--- py/kubeflow/testing/run_e2e_workflow.py | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/py/kubeflow/testing/prow_artifacts.py b/py/kubeflow/testing/prow_artifacts.py index b53c2862e18..60cfb2e6743 100644 --- a/py/kubeflow/testing/prow_artifacts.py +++ b/py/kubeflow/testing/prow_artifacts.py @@ -46,7 +46,7 @@ def create_started(): # TODO(jlewi): Replace create_finished in tensorflow/k8s/py/prow.py with this # version. We should do that when we switch tensorflow/k8s to use Argo instead # of Airflow. -def create_finished(success): +def create_finished(success, ui_urls): """Create a string containing the contents for finished.json. Args: @@ -62,7 +62,9 @@ def create_finished(success): # Dictionary of extra key value pairs to display to the user. # TODO(jlewi): Perhaps we should add the GCR path of the Docker image # we are running in. We'd have to plumb this in from bootstrap. - "metadata": {}, + "metadata": { + "ui-urls": ui_urls + }, } return json.dumps(finished) diff --git a/py/kubeflow/testing/prow_artifacts_test.py b/py/kubeflow/testing/prow_artifacts_test.py index 1b4552498a6..e1ae3508718 100644 --- a/py/kubeflow/testing/prow_artifacts_test.py +++ b/py/kubeflow/testing/prow_artifacts_test.py @@ -31,14 +31,16 @@ def testCreateStartedPresubmit(self, mock_time): # pylint: disable=no-self-use def testCreateFinished(self, mock_time): # pylint: disable=no-self-use """Test create finished job.""" mock_time.return_value = 1000 - + test_urls = "https://example.com" expected = { "timestamp": 1000, "result": "FAILED", - "metadata": {}, + "metadata": { + "ui-urls": "https://example.com" + }, } - actual = prow_artifacts.create_finished(False) + actual = prow_artifacts.create_finished(False, test_urls) self.assertEquals(expected, json.loads(actual)) diff --git a/py/kubeflow/testing/run_e2e_workflow.py b/py/kubeflow/testing/run_e2e_workflow.py index c3706110e64..72e7be5a67d 100644 --- a/py/kubeflow/testing/run_e2e_workflow.py +++ b/py/kubeflow/testing/run_e2e_workflow.py @@ -82,9 +82,9 @@ def create_started_file(bucket): target = os.path.join(prow_artifacts.get_gcs_dir(bucket), "started.json") upload_to_gcs(contents, target) -def create_finished_file(bucket, success): +def create_finished_file(bucket, success, ui_urls): """Create the started file in gcs for gubernator.""" - contents = prow_artifacts.create_finished(success) + contents = prow_artifacts.create_finished(success, ui_urls) target = os.path.join(prow_artifacts.get_gcs_dir(bucket), "finished.json") upload_to_gcs(contents, target) @@ -115,6 +115,7 @@ def run(args, file_handler): api_client = k8s_client.ApiClient() workflow_names = [] + ui_urls = [] for w in workflows: app_dir = w.app_dir # Create the name for the workflow @@ -173,6 +174,7 @@ def run(args, file_handler): ui_url = ("http://testing-argo.kubeflow.io/timeline/kubeflow-test-infra/{0}" ";tab=workflow".format(workflow_name)) + ui_urls.append(ui_url) logging.info("URL for workflow: %s", ui_url) success = True @@ -190,7 +192,7 @@ def run(args, file_handler): success = False logging.error("Time out waiting for Workflows %s to finish", ",".join(workflow_names)) finally: - create_finished_file(args.bucket, success) + create_finished_file(args.bucket, success, ",".join(ui_urls)) # Upload logs to GCS. No logs after this point will appear in the # file in gcs