Skip to content

Commit

Permalink
adds logic to account if kind has special characters such as "-"
Browse files Browse the repository at this point in the history
  • Loading branch information
Skybound1 committed Nov 21, 2024
1 parent 0eb2738 commit 6f570ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion icekube/models/api_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from pydantic import BaseModel
from pydantic import BaseModel, field_validator


class APIResource(BaseModel):
Expand All @@ -10,3 +10,9 @@ class APIResource(BaseModel):
kind: str
verbs: List[str]
preferred: bool = False

@field_validator("kind")
@classmethod
def kind_can_only_have_underscore(cls, v: str) -> str:
s = "".join([x if x.isalnum() else "_" for x in v])
return s
8 changes: 7 additions & 1 deletion icekube/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from icekube.relationships import Relationship
from icekube.utils import to_camel_case
from kubernetes import client
from pydantic import BaseModel, Field, computed_field, model_validator
from pydantic import BaseModel, Field, computed_field, model_validator, field_validator

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -52,6 +52,12 @@ def __eq__(self, other) -> bool:

return all(getattr(self, x) == getattr(other, x) for x in comparison_points)

@field_validator("kind")
@classmethod
def kind_can_only_have_underscore(cls, v: str) -> str:
s = "".join([x if x.isalnum() else "_" for x in v])
return s

@cached_property
def data(self) -> Dict[str, Any]:
return cast(Dict[str, Any], json.loads(self.raw or "{}"))
Expand Down

0 comments on commit 6f570ff

Please sign in to comment.