-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Backend + SDK): Update kfp backend and kubernetes sdk to support…
… EmptyDir (#10913) Update kfp backend and kubernetes sdk to support mounting EmptyDir volumes to task pods. Inspired by #10427 Fixes: #10656 Signed-off-by: Greg Sheremeta <[email protected]>
- Loading branch information
1 parent
ae8315c
commit 7506a8e
Showing
11 changed files
with
485 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 The Kubeflow Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Optional | ||
|
||
from google.protobuf import json_format | ||
from kfp.dsl import PipelineTask | ||
from kfp.kubernetes import common | ||
from kfp.kubernetes import kubernetes_executor_config_pb2 as pb | ||
|
||
|
||
def empty_dir_mount( | ||
task: PipelineTask, | ||
volume_name: str, | ||
mount_path: str, | ||
medium: Optional[str] = None, | ||
size_limit: Optional[str] = None, | ||
) -> PipelineTask: | ||
"""Mount an EmptyDir volume to the task's container. | ||
Args: | ||
task: Pipeline task. | ||
volume_name: Name of the EmptyDir volume. | ||
mount_path: Path within the container at which the EmptyDir should be mounted. | ||
medium: Storage medium to back the EmptyDir. Must be one of `Memory` or `HugePages`. Defaults to `None`. | ||
size_limit: Maximum size of the EmptyDir. For example, `5Gi`. Defaults to `None`. | ||
Returns: | ||
Task object with updated EmptyDir mount configuration. | ||
""" | ||
|
||
msg = common.get_existing_kubernetes_config_as_message(task) | ||
|
||
empty_dir_mount = pb.EmptyDirMount( | ||
volume_name=volume_name, | ||
mount_path=mount_path, | ||
medium=medium, | ||
size_limit=size_limit, | ||
) | ||
|
||
msg.empty_dir_mounts.append(empty_dir_mount) | ||
|
||
task.platform_config['kubernetes'] = json_format.MessageToDict(msg) | ||
|
||
return task |
36 changes: 36 additions & 0 deletions
36
kubernetes_platform/python/test/snapshot/data/empty_dir_mounts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2024 The Kubeflow Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from kfp import dsl | ||
from kfp import kubernetes | ||
|
||
|
||
@dsl.component | ||
def comp(): | ||
pass | ||
|
||
@dsl.pipeline | ||
def my_pipeline(): | ||
task = comp() | ||
kubernetes.empty_dir_mount( | ||
task, | ||
volume_name='emptydir-vol-1', | ||
mount_path='/mnt/my_vol_1', | ||
medium='Memory', | ||
size_limit='1Gi' | ||
) | ||
|
||
if __name__ == '__main__': | ||
from kfp import compiler | ||
compiler.Compiler().compile(my_pipeline, __file__.replace('.py', '.yaml')) |
Oops, something went wrong.