-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api-server: Support task labels in main (#950)
Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com>
- Loading branch information
Showing
17 changed files
with
12,155 additions
and
9,939 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
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,25 @@ | ||
from typing import Sequence | ||
|
||
from pydantic import RootModel | ||
|
||
|
||
class Labels(RootModel): | ||
""" | ||
Labels for a resource. | ||
""" | ||
|
||
root: dict[str, str] | ||
|
||
@staticmethod | ||
def _parse_label(s: str) -> tuple[str, str]: | ||
sep = s.find("=") | ||
if sep == -1: | ||
return s, "" | ||
return s[:sep], s[sep + 1 :] | ||
|
||
@staticmethod | ||
def from_strings(labels: Sequence[str]) -> "Labels": | ||
return Labels(dict(Labels._parse_label(s) for s in labels)) | ||
|
||
def to_strings(self) -> list[str]: | ||
return [f"{k}={v}" for k, v in self.root.items()] |
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
TaskEventLogPhasesLog, | ||
TaskFavorite, | ||
TaskFavoritePydantic, | ||
TaskLabel, | ||
TaskRequest, | ||
TaskState, | ||
) | ||
|
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
Oops, something went wrong.