Skip to content

Commit

Permalink
feat(sdk): Upload namespaced pipeline definitions. Part of kubeflow#4197
Browse files Browse the repository at this point in the history


Add a namespace field in the relevant Python wrappers for uploading
namespaced pipeline definitions.
  • Loading branch information
elikatsis committed Nov 30, 2022
1 parent f7161d7 commit 1673b07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 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 @@ -1352,19 +1352,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 @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion sdk/python/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1673b07

Please sign in to comment.