-
Notifications
You must be signed in to change notification settings - Fork 40
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 generic labels (#949)
* save generic labels Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * document problems with tortoise-orm Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * cleanup Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * cleanup Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * port generic label filtering from main Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * successfully ported generic label sorting Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * fix test leaking to other tests Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * add TODO Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * update client api Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * uncomment out test Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> * fix api call Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com> --------- Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com>
- Loading branch information
Showing
17 changed files
with
371 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Sequence | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Labels(BaseModel): | ||
""" | ||
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(__root__=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
Oops, something went wrong.