Service instantiation #31

Merged
rixx merged 37 commits from 24-service-instantiation into main 2025-04-04 10:57:29 +00:00
Showing only changes of commit 94713a3100 - Show all commits

View file

@ -131,6 +131,7 @@ class ControlPlane(ServalaModelMixin, models.Model):
"clusters": [ "clusters": [
{ {
"cluster": { "cluster": {
"insecure-skip-tls-verify": True,
"certificate-authority-data": self.api_credentials[ "certificate-authority-data": self.api_credentials[
"certificate-authority-data" "certificate-authority-data"
], ],
@ -460,6 +461,26 @@ class ServiceInstance(ServalaModelMixin, models.Model):
@classmethod @classmethod
def create_instance(cls, organization, context, created_by, spec_data): def create_instance(cls, organization, context, created_by, spec_data):
name = spec_data.get("spec.name") name = spec_data.get("spec.name")
# Ensure the namespace exists
namespace_name = organization.namespace
api_instance = kubernetes.client.CoreV1Api(
context.control_plane.get_kubernetes_client()
)
try:
api_instance.read_namespace(name=namespace_name)
except kubernetes.client.ApiException as e:
if e.status == 404:
# Namespace does not exist, create it
body = kubernetes.client.V1Namespace(
metadata=kubernetes.client.V1ObjectMeta(name=namespace_name)
)
api_instance.create_namespace(body=body)
else:
# If there's another error, raise it
raise
return cls.objects.create( return cls.objects.create(
name=name, name=name,
organization=organization, organization=organization,