wip
This commit is contained in:
parent
2f769e0e2e
commit
94713a3100
1 changed files with 21 additions and 0 deletions
|
@ -131,6 +131,7 @@ class ControlPlane(ServalaModelMixin, models.Model):
|
|||
"clusters": [
|
||||
{
|
||||
"cluster": {
|
||||
"insecure-skip-tls-verify": True,
|
||||
"certificate-authority-data": self.api_credentials[
|
||||
"certificate-authority-data"
|
||||
],
|
||||
|
@ -460,6 +461,26 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
|||
@classmethod
|
||||
def create_instance(cls, organization, context, created_by, spec_data):
|
||||
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(
|
||||
name=name,
|
||||
organization=organization,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue