-
Notifications
You must be signed in to change notification settings - Fork 41
feat: Add ContainerBackend with Docker and Podman #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fiona-Waters
wants to merge
6
commits into
kubeflow:main
Choose a base branch
from
Fiona-Waters:podman-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1188510
Add docker backend
briangallagher 60fd258
Add podman backend
Fiona-Waters d1288b2
Implementing ContainerBackend
Fiona-Waters 0680c3e
Use ip address for Podman
Fiona-Waters 24f0bbd
Updating to rely on container runtime rather than storing job info in…
Fiona-Waters a9218c5
Addressing feedback
Fiona-Waters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| # Copyright 2025 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 kubeflow.trainer.backends.container.backend import ContainerBackend | ||
| from kubeflow.trainer.backends.container.types import ContainerBackendConfig | ||
|
|
||
| __all__ = ["ContainerBackend", "ContainerBackendConfig"] |
This file contains hidden or 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,31 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| """ | ||
| Container runtime adapters. | ||
|
|
||
| This package provides adapter implementations for different container runtimes | ||
| (Docker and Podman), allowing the Container backend to work with either runtime | ||
| through a unified interface. | ||
| """ | ||
|
|
||
| from kubeflow.trainer.backends.container.adapters.base import BaseContainerClientAdapter | ||
| from kubeflow.trainer.backends.container.adapters.docker import DockerClientAdapter | ||
| from kubeflow.trainer.backends.container.adapters.podman import PodmanClientAdapter | ||
|
|
||
| __all__ = [ | ||
| "BaseContainerClientAdapter", | ||
| "DockerClientAdapter", | ||
| "PodmanClientAdapter", | ||
| ] |
This file contains hidden or 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,196 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| """ | ||
| Container client adapters for Docker and Podman. | ||
|
|
||
| This module implements the adapter pattern to abstract away differences between | ||
| Docker and Podman APIs, allowing the backend to work with either runtime through | ||
| a common interface. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import abc | ||
| from collections.abc import Iterator | ||
|
|
||
|
|
||
| class BaseContainerClientAdapter(abc.ABC): | ||
| """ | ||
| Abstract adapter interface for container clients. | ||
|
|
||
| This adapter abstracts the container runtime API, allowing the backend | ||
| to work with Docker and Podman through a unified interface. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def ping(self): | ||
| """Test the connection to the container runtime.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def create_network( | ||
| self, | ||
| name: str, | ||
| labels: dict[str, str], | ||
| ) -> str: | ||
| """ | ||
| Create a container network. | ||
|
|
||
| Args: | ||
| name: Network name | ||
| labels: Labels to attach to the network | ||
|
|
||
| Returns: | ||
| Network ID or name | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def delete_network(self, network_id: str): | ||
| """Delete a network.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def create_and_start_container( | ||
| self, | ||
| image: str, | ||
| command: list[str], | ||
| name: str, | ||
| network_id: str, | ||
| environment: dict[str, str], | ||
| labels: dict[str, str], | ||
| volumes: dict[str, dict[str, str]], | ||
| working_dir: str, | ||
| gpus: int | bool | None = None, | ||
| ) -> str: | ||
| """ | ||
| Create and start a container. | ||
|
|
||
| Args: | ||
| image: Container image | ||
| command: Command to run | ||
| name: Container name | ||
| network_id: Network to attach to | ||
| environment: Environment variables | ||
| labels: Container labels | ||
| volumes: Volume mounts | ||
| working_dir: Working directory | ||
| gpus: GPU configuration (None=no GPU, True=all GPUs, int=number of GPUs) | ||
|
|
||
| Returns: | ||
| Container ID | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def get_container(self, container_id: str): | ||
| """Get container object by ID.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def container_logs(self, container_id: str, follow: bool) -> Iterator[str]: | ||
| """Stream logs from a container.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def stop_container(self, container_id: str, timeout: int = 10): | ||
| """Stop a container.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def remove_container(self, container_id: str, force: bool = True): | ||
| """Remove a container.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def pull_image(self, image: str): | ||
| """Pull an image.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def image_exists(self, image: str) -> bool: | ||
| """Check if an image exists locally.""" | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def run_oneoff_container(self, image: str, command: list[str]) -> str: | ||
| """ | ||
| Run a short-lived container and return its output. | ||
|
|
||
| Args: | ||
| image: Container image | ||
| command: Command to run | ||
|
|
||
| Returns: | ||
| Container output as string | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def container_status(self, container_id: str) -> tuple[str, int | None]: | ||
| """ | ||
| Get container status. | ||
|
|
||
| Returns: | ||
| Tuple of (status_string, exit_code) | ||
| Status strings: "running", "created", "exited", etc. | ||
| Exit code is None if container hasn't exited | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def get_container_ip(self, container_id: str, network_id: str) -> str | None: | ||
| """ | ||
| Get container's IP address on a specific network. | ||
|
|
||
| Args: | ||
| container_id: Container ID | ||
| network_id: Network name or ID | ||
|
|
||
| Returns: | ||
| IP address string or None if not found | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def list_containers(self, filters: dict[str, str] | None = None) -> list[dict]: | ||
| """ | ||
| List containers, optionally filtered by labels. | ||
|
|
||
| Args: | ||
| filters: Dictionary of filters (e.g., {"label": ["key=value"]}) | ||
|
|
||
| Returns: | ||
| List of container info dictionaries with keys: | ||
| - id: Container ID | ||
| - name: Container name | ||
| - labels: Dictionary of labels | ||
| - status: Container status | ||
| - created: Creation timestamp | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abc.abstractmethod | ||
| def get_network(self, network_id: str) -> dict | None: | ||
| """ | ||
| Get network information by ID or name. | ||
|
|
||
| Args: | ||
| network_id: Network ID or name | ||
|
|
||
| Returns: | ||
| Dictionary with network info including labels, or None if not found | ||
| """ | ||
| raise NotImplementedError() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also include docs about Trainer local execution to the user guides ?
https://www.kubeflow.org/docs/components/trainer/user-guides/
you can also add info from the @szaher PR: #95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP PR for this kubeflow/website#4221