diff --git a/icekube/models/api_resource.py b/icekube/models/api_resource.py index f262ed9..453aec8 100644 --- a/icekube/models/api_resource.py +++ b/icekube/models/api_resource.py @@ -1,6 +1,6 @@ from typing import List -from pydantic import BaseModel +from pydantic import BaseModel, field_validator class APIResource(BaseModel): @@ -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 diff --git a/icekube/models/base.py b/icekube/models/base.py index dd52b41..5270bc9 100644 --- a/icekube/models/base.py +++ b/icekube/models/base.py @@ -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__) @@ -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 "{}"))