Successfully create an instance
This commit is contained in:
parent
a2c3695611
commit
08fada04e0
2 changed files with 29 additions and 3 deletions
|
@ -6,7 +6,7 @@ from django.db import models
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from encrypted_fields.fields import EncryptedJSONField
|
from encrypted_fields.fields import EncryptedJSONField
|
||||||
from kubernetes import config
|
from kubernetes import client, config
|
||||||
from kubernetes.client.rest import ApiException
|
from kubernetes.client.rest import ApiException
|
||||||
|
|
||||||
from servala.core.models.mixins import ServalaModelMixin
|
from servala.core.models.mixins import ServalaModelMixin
|
||||||
|
@ -137,7 +137,6 @@ 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"
|
||||||
],
|
],
|
||||||
|
@ -484,6 +483,33 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
# Ensure the namespace exists
|
# Ensure the namespace exists
|
||||||
context.control_plane.get_or_create_namespace(organization.namespace)
|
context.control_plane.get_or_create_namespace(organization.namespace)
|
||||||
|
|
||||||
|
group = context.service_definition.api_definition["group"]
|
||||||
|
version = context.service_definition.api_definition["version"]
|
||||||
|
kind = context.service_definition.api_definition["kind"]
|
||||||
|
create_data = {
|
||||||
|
"apiVersion": f"{group}/{version}",
|
||||||
|
"kind": kind,
|
||||||
|
"metadata": {
|
||||||
|
"name": name,
|
||||||
|
"namespace": organization.namespace,
|
||||||
|
},
|
||||||
|
"spec": spec_data or {},
|
||||||
|
}
|
||||||
|
api_instance = client.CustomObjectsApi(
|
||||||
|
context.control_plane.get_kubernetes_client()
|
||||||
|
)
|
||||||
|
plural = kind.lower()
|
||||||
|
if not plural.endswith("s"):
|
||||||
|
plural = f"{plural}s"
|
||||||
|
|
||||||
|
api_instance.create_namespaced_custom_object(
|
||||||
|
group=group,
|
||||||
|
version=version,
|
||||||
|
namespace=organization.namespace,
|
||||||
|
plural=plural,
|
||||||
|
body=create_data,
|
||||||
|
)
|
||||||
|
|
||||||
return cls.objects.create(
|
return cls.objects.create(
|
||||||
name=name,
|
name=name,
|
||||||
organization=organization,
|
organization=organization,
|
||||||
|
|
|
@ -131,7 +131,7 @@ class ServiceOfferingDetailView(OrganizationViewMixin, HtmxViewMixin, DetailView
|
||||||
name=form.cleaned_data["name"],
|
name=form.cleaned_data["name"],
|
||||||
context=self.context_object,
|
context=self.context_object,
|
||||||
created_by=request.user,
|
created_by=request.user,
|
||||||
spec_data=form.get_nested_data(),
|
spec_data=form.get_nested_data().get("spec"),
|
||||||
)
|
)
|
||||||
return redirect(service_instance.urls.base)
|
return redirect(service_instance.urls.base)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue