Skip to content

Commit

Permalink
Add TrustyAIService resource (#1884)
Browse files Browse the repository at this point in the history
* Add TrustyAIService resource

* Add None return type hint to __init__

* Add return type hint to to_dict

* Raise if there are missing required arguments

* Fix docstrings
  • Loading branch information
adolfo-ab committed Jun 26, 2024
1 parent c065809 commit 0f3c491
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class ApiGroup:
TEKTON_DEV = "tekton.dev"
TEMPLATE_KUBEVIRT_IO = "template.kubevirt.io"
TEMPLATE_OPENSHIFT_IO = "template.openshift.io"
TRUSTYAI_OPENDATAHUB_IO = "trustyai.opendatahub.io"
UPLOAD_CDI_KUBEVIRT_IO = "upload.cdi.kubevirt.io"
USER_OPENSHIFT_IO = "user.openshift.io"
V2V_KUBEVIRT_IO = "v2v.kubevirt.io"
Expand Down
62 changes: 62 additions & 0 deletions ocp_resources/trustyai_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError
from typing import Optional, Any, Dict


class TrustyAIService(NamespacedResource):
"""
https://github.com/trustyai-explainability/trustyai-service-operator/blob/main/api/v1alpha1/trustyaiservice_types.go
"""

api_group: str = NamespacedResource.ApiGroup.TRUSTYAI_OPENDATAHUB_IO

def __init__(
self,
storage: Optional[Dict[str, Any]] = None,
data: Optional[Dict[str, Any]] = None,
metrics: Optional[Dict[str, Any]] = None,
replicas: Optional[int] = None,
image: Optional[str] = None,
tag: Optional[str] = None,
**kwargs,
) -> None:
"""
TrustyAIService object
Args:
storage (Optional[Dic[str, Any]], mandatory if not passing yaml_file): TrustyAIService storage config (format, folder and size).
data (Optional[Dict[str, Any]], mandatory if not passing yaml_file): TrustyAIService data config (filename and format).
metrics (Optional[Dict[str, Any]], mandatory if not passing yaml_file): TrustyAIService metrics config.
replicas (Optional[int]): Number of replicas for the TrustyAIService.
image (Optional[str]): Pull url of the TrustyAIService.
tag (Optional[str]): Tag of the image.
"""
super().__init__(**kwargs)
self.storage = storage
self.data = data
self.metrics = metrics
self.replicas = replicas
self.image = image
self.tag = tag

def to_dict(self) -> None:
super().to_dict()

if not self.yaml_file:
if not (self.storage or self.data or self.metrics):
raise MissingRequiredArgumentError(argument="'storage' or 'data' or 'metrics'")

self.res["spec"] = {}
_spec = self.res["spec"]

_spec["storage"] = self.storage
_spec["data"] = self.data
_spec["metrics"] = self.metrics

if self.replicas:
_spec["replicas"] = self.replicas

if self.image:
_spec["image"] = self.image

if self.tag:
_spec["tag"] = self.tag

0 comments on commit 0f3c491

Please sign in to comment.