From 6b315d4693955485c9183f326d258b6a1221d681 Mon Sep 17 00:00:00 2001 From: qimingj Date: Wed, 12 Dec 2018 23:36:18 -0800 Subject: [PATCH] Change "namespace" param to "host" in kfp client so we can use Jupyter outside cluster. (#529) * Change "namespace" param to "host" in kfp client so we can use Jupyter outside cluster. * Fix tests. --- sdk/python/kfp/_client.py | 12 ++++++++---- test/sample-test/run_basic_test.py | 3 ++- test/sample-test/run_kubeflow_test.py | 3 ++- test/sample-test/run_tfx_test.py | 3 ++- test/sample-test/run_xgboost_test.py | 5 +++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sdk/python/kfp/_client.py b/sdk/python/kfp/_client.py index a25c1309063..1fcd0a62768 100644 --- a/sdk/python/kfp/_client.py +++ b/sdk/python/kfp/_client.py @@ -23,16 +23,21 @@ from .compiler import compiler + class Client(object): """ API Client for KubeFlow Pipeline. """ - def __init__(self, namespace='kubeflow'): + def __init__(self, host='ml-pipeline.kubeflow.svc.cluster.local:8888'): """Create a new instance of kfp client. Args: - namespace: the namespace where pipelines are deployed. Default is kubeflow - TODO: check if it works outside of the cluster. + host: the host name to use to talk to Kubeflow Pipelines. Default value + "ml-pipeline.kubeflow.svc.cluster.local:8888" is the in-cluster DNS name + of the pipeline service. It only works if the current environment is a pod + in the same cluster (such as a Jupyter instance spawned by Kubeflow's + JupyterHub). If you have a different connection to cluster, such as a kubectl + proxy connection, then set it to something like "127.0.0.1:8080/pipeline". """ try: @@ -45,7 +50,6 @@ def __init__(self, namespace='kubeflow'): except ImportError: raise Exception('This module requires installation of kfp_run') - host='ml-pipeline.' + namespace + '.svc.cluster.local:8888' config = kfp_run.configuration.Configuration() config.host = host api_client = kfp_run.api_client.ApiClient(config) diff --git a/test/sample-test/run_basic_test.py b/test/sample-test/run_basic_test.py index 7abb7a48189..38d822bc012 100644 --- a/test/sample-test/run_basic_test.py +++ b/test/sample-test/run_basic_test.py @@ -58,7 +58,8 @@ def main(): test_name = args.testname + ' Sample Test' ###### Initialization ###### - client = Client(namespace=args.namespace) + host = 'ml-pipeline.%s.svc.cluster.local:8888' % args.namespace + client = Client(host=host) ###### Check Input File ###### utils.add_junit_test(test_cases, 'input generated yaml file', os.path.exists(args.input), 'yaml file is not generated') diff --git a/test/sample-test/run_kubeflow_test.py b/test/sample-test/run_kubeflow_test.py index 6a504bc69f1..15ef3faddea 100644 --- a/test/sample-test/run_kubeflow_test.py +++ b/test/sample-test/run_kubeflow_test.py @@ -55,7 +55,8 @@ def main(): test_name = 'Kubeflow Sample Test' ###### Initialization ###### - client = Client(namespace=args.namespace) + host = 'ml-pipeline.%s.svc.cluster.local:8888' % args.namespace + client = Client(host=host) ###### Check Input File ###### utils.add_junit_test(test_cases, 'input generated yaml file', os.path.exists(args.input), 'yaml file is not generated') diff --git a/test/sample-test/run_tfx_test.py b/test/sample-test/run_tfx_test.py index 75264a69aba..1146b470769 100644 --- a/test/sample-test/run_tfx_test.py +++ b/test/sample-test/run_tfx_test.py @@ -54,7 +54,8 @@ def main(): test_name = 'TFX Sample Test' ###### Initialization ###### - client = Client(namespace=args.namespace) + host = 'ml-pipeline.%s.svc.cluster.local:8888' % args.namespace + client = Client(host=host) ###### Check Input File ###### utils.add_junit_test(test_cases, 'input generated yaml file', os.path.exists(args.input), 'yaml file is not generated') diff --git a/test/sample-test/run_xgboost_test.py b/test/sample-test/run_xgboost_test.py index 9459355d438..243b8ac002b 100644 --- a/test/sample-test/run_xgboost_test.py +++ b/test/sample-test/run_xgboost_test.py @@ -55,7 +55,8 @@ def main(): test_name = 'XGBoost Sample Test' ###### Initialization ###### - client = Client(namespace=args.namespace) + host = 'ml-pipeline.%s.svc.cluster.local:8888' % args.namespace + client = Client(host=host) ###### Check Input File ###### utils.add_junit_test(test_cases, 'input generated yaml file', os.path.exists(args.input), 'yaml file is not generated') @@ -123,4 +124,4 @@ def main(): utils.write_junit_xml(test_name, args.result, test_cases) if __name__ == "__main__": - main() \ No newline at end of file + main()