Compare commits
No commits in common. "a2ac202f265e8af45c5c7b6303ee652b7836ec7f" and "da69666389062198df2e13d16fc2bc832c40871f" have entirely different histories.
a2ac202f26
...
da69666389
6 changed files with 6 additions and 80 deletions
|
@ -131,7 +131,7 @@ class ControlPlaneAdmin(admin.ModelAdmin):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(
|
(
|
||||||
None,
|
None,
|
||||||
{"fields": ("name", "description", "cloud_provider", "required_label")},
|
{"fields": ("name", "description", "cloud_provider")},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
_("API Credentials"),
|
_("API Credentials"),
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
# Generated by Django 5.2b1 on 2025-04-03 15:24
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("core", "0001_initial"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterModelOptions(
|
|
||||||
name="controlplanecrd",
|
|
||||||
options={
|
|
||||||
"verbose_name": "ControlPlane CRD",
|
|
||||||
"verbose_name_plural": "ControlPlane CRDs",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="controlplane",
|
|
||||||
name="required_label",
|
|
||||||
field=models.CharField(
|
|
||||||
blank=True,
|
|
||||||
help_text="Label value for the 'appcat.vshn.io/provider-config' added to every instance on this plane.",
|
|
||||||
max_length=100,
|
|
||||||
null=True,
|
|
||||||
verbose_name="Required Label",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,13 +1,12 @@
|
||||||
import kubernetes
|
import kubernetes
|
||||||
import urlman
|
import urlman
|
||||||
from django.conf import settings
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
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 client, config
|
from kubernetes import 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
|
||||||
|
@ -107,15 +106,6 @@ class ControlPlane(ServalaModelMixin, models.Model):
|
||||||
help_text="Required fields: certificate-authority-data, server (URL), token",
|
help_text="Required fields: certificate-authority-data, server (URL), token",
|
||||||
validators=[validate_api_credentials],
|
validators=[validate_api_credentials],
|
||||||
)
|
)
|
||||||
required_label = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
verbose_name=_("Required Label"),
|
|
||||||
help_text=_(
|
|
||||||
"Label value for the 'appcat.vshn.io/provider-config' added to every instance on this plane."
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
cloud_provider = models.ForeignKey(
|
cloud_provider = models.ForeignKey(
|
||||||
to="CloudProvider",
|
to="CloudProvider",
|
||||||
|
@ -147,6 +137,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"
|
||||||
],
|
],
|
||||||
|
@ -493,35 +484,6 @@ 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 {},
|
|
||||||
}
|
|
||||||
if label := context.control_plane.required_label:
|
|
||||||
create_data["metadata"]["labels"] = {settings.DEFAULT_LABEL_KEY: label}
|
|
||||||
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().get("spec"),
|
spec_data=form.get_nested_data(),
|
||||||
)
|
)
|
||||||
return redirect(service_instance.urls.base)
|
return redirect(service_instance.urls.base)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -210,7 +210,6 @@ LANGUAGE_COOKIE_NAME = "servala_lang"
|
||||||
SESSION_COOKIE_NAME = "servala_sess"
|
SESSION_COOKIE_NAME = "servala_sess"
|
||||||
SESSION_COOKIE_SECURE = not DEBUG
|
SESSION_COOKIE_SECURE = not DEBUG
|
||||||
|
|
||||||
DEFAULT_LABEL_KEY = "appcat.vshn.io/provider-config"
|
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
|
@ -15,16 +15,12 @@ def origin():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def organization(origin):
|
def organization(origin):
|
||||||
return Organization.objects.create(
|
return Organization.objects.create(name="Test Org", origin=origin)
|
||||||
name="Test Org", namespace="test-org", origin=origin
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def other_organization(origin):
|
def other_organization(origin):
|
||||||
return Organization.objects.create(
|
return Organization.objects.create(name="Test Org Alternate", origin=origin)
|
||||||
name="Test Org Alternate", namespace="test-org-alternate", origin=origin
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue