From 1673b075597d16ac1fe88584308577cd8cf07875 Mon Sep 17 00:00:00 2001 From: Ilias Katsakioris Date: Wed, 24 Aug 2022 11:45:57 +0300 Subject: [PATCH] feat(sdk): Upload namespaced pipeline definitions. Part of #4197 Add a namespace field in the relevant Python wrappers for uploading namespaced pipeline definitions. --- sdk/python/kfp/client/client.py | 39 ++++++++++++++++++++++----------- sdk/python/requirements.in | 2 +- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/sdk/python/kfp/client/client.py b/sdk/python/kfp/client/client.py index 1a6846d41607..a3e7f9aa7c14 100644 --- a/sdk/python/kfp/client/client.py +++ b/sdk/python/kfp/client/client.py @@ -1352,12 +1352,11 @@ def _get_workflow_json(self, run_id: str) -> dict: workflow_json = json.loads(workflow) return workflow_json - def upload_pipeline( - self, - pipeline_package_path: str = None, - pipeline_name: str = None, - description: str = None, - ) -> kfp_server_api.ApiPipeline: + def upload_pipeline(self, + pipeline_package_path: str = None, + pipeline_name: str = None, + description: str = None, + namespace: str = None) -> kfp_server_api.ApiPipeline: """Uploads a pipeline. Args: @@ -1365,6 +1364,9 @@ def upload_pipeline( pipeline_name: Name of the pipeline to be shown in the UI. description: Description of the pipeline to be shown in the UI. + namespace: Optional. Kubernetes namespace where the pipeline should be uploaded. + For single user deployment, leave it as None; + For multi user, input a namespace where the user is authorized. Returns: ``ApiPipeline`` object. @@ -1374,8 +1376,12 @@ def upload_pipeline( os.path.basename('something/file.txt'))[0] validate_pipeline_resource_name(pipeline_name) + namespace = namespace or self.get_user_namespace() response = self._upload_api.upload_pipeline( - pipeline_package_path, name=pipeline_name, description=description) + pipeline_package_path, + name=pipeline_name, + description=description, + namespace=namespace) link = f'{self._get_url_prefix()}/#/pipelines/details/{response.id}' if self._is_ipython(): import IPython @@ -1387,12 +1393,13 @@ def upload_pipeline( return response def upload_pipeline_version( - self, - pipeline_package_path: str, - pipeline_version_name: str, - pipeline_id: Optional[str] = None, - pipeline_name: Optional[str] = None, - description: Optional[str] = None, + self, + pipeline_package_path: str, + pipeline_version_name: str, + pipeline_id: Optional[str] = None, + pipeline_name: Optional[str] = None, + description: Optional[str] = None, + namespace: Optional[str] = None ) -> kfp_server_api.ApiPipelineVersion: """Uploads a new version of the pipeline. @@ -1403,6 +1410,9 @@ def upload_pipeline_version( pipeline_id: ID of the pipeline. pipeline_name: Name of the pipeline. description: Description of the pipeline version to show in the UI. + namespace: Optional. Kubernetes namespace where the pipeline should be uploaded. + For single user deployment, leave it as None; + For multi user, input a namespace where the user is authorized. Returns: ``ApiPipelineVersion`` object. @@ -1422,6 +1432,9 @@ def upload_pipeline_version( if description: kwargs['description'] = description + if namespace: + kwargs['namespace'] = namespace or self.get_user_namespace() + response = self._upload_api.upload_pipeline_version( pipeline_package_path, **kwargs) diff --git a/sdk/python/requirements.in b/sdk/python/requirements.in index 77b764f4dc4d..fdb46c1c59ca 100644 --- a/sdk/python/requirements.in +++ b/sdk/python/requirements.in @@ -22,7 +22,7 @@ kfp-pipeline-spec>=0.1.16,<0.2.0 # Update the lower version when kfp sdk depends on new apis/fields in # kfp-server-api. # Note, please also update ./requirements.in -kfp-server-api>=2.0.0a0,<3.0.0 +kfp-server-api>=2.0.0a7,<3.0.0 kubernetes>=8.0.0,<24 protobuf>=3.13.0,<4 PyYAML>=5.3,<6