Implement k8s instance retrieval

This commit is contained in:
Tobias Kunze 2025-04-11 09:53:47 +02:00
parent 0eb07feeef
commit c4522e31e8

View file

@ -564,3 +564,23 @@ class ServiceInstance(ServalaModelMixin, models.Model):
raise ValidationError(_("Kubernetes API error: {}").format(str(e)))
raise ValidationError(_("Error creating instance: {}").format(str(e)))
return instance
@cached_property
def kubernetes_object(self):
"""Fetch the Kubernetes custom resource object"""
try:
api_instance = client.CustomObjectsApi(
self.context.control_plane.get_kubernetes_client()
)
return api_instance.get_namespaced_custom_object(
group=self.context.group,
version=self.context.version,
namespace=self.organization.namespace,
plural=self.context.kind_plural,
name=self.name,
)
except ApiException as e:
if e.status == 404:
return None
raise