Skip to content

Commit

Permalink
feat(sdk): Add support for uploading namespaced pipelines
Browse files Browse the repository at this point in the history
Add a namespace field in the relevant Python wrappers for uploading
pipeline definitions.
  • Loading branch information
Panagiotis Giannoulis committed Aug 29, 2022
1 parent 39a1951 commit 89e5090
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions sdk/python/kfp/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,19 +1348,21 @@ 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:
pipeline_package_path: Local path to the pipeline package.
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.
Expand All @@ -1370,21 +1372,26 @@ 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)
if self._is_ipython():
import IPython
html = f'<a href={self._get_url_prefix()}/#/pipelines/details/{response.id}>Pipeline details</a>.'
IPython.display.display(IPython.display.HTML(html))
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.
Expand All @@ -1395,6 +1402,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.
Expand All @@ -1414,6 +1424,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)

Expand Down

0 comments on commit 89e5090

Please sign in to comment.