Add required_label field to ControlPlane

This commit is contained in:
Tobias Kunze 2025-04-03 17:39:49 +02:00
parent 08fada04e0
commit bc8c7a80b2
4 changed files with 45 additions and 1 deletions

View file

@ -131,7 +131,7 @@ class ControlPlaneAdmin(admin.ModelAdmin):
fieldsets = ( fieldsets = (
( (
None, None,
{"fields": ("name", "description", "cloud_provider")}, {"fields": ("name", "description", "cloud_provider", "required_label")},
), ),
( (
_("API Credentials"), _("API Credentials"),

View file

@ -0,0 +1,31 @@
# 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",
),
),
]

View file

@ -1,5 +1,6 @@
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
@ -106,6 +107,15 @@ 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",
@ -495,6 +505,8 @@ class ServiceInstance(ServalaModelMixin, models.Model):
}, },
"spec": spec_data or {}, "spec": spec_data or {},
} }
if label := context.control_plane.required_label:
create_data["metadata"]["labels"] = [{settings.DEFAULT_LABEL_KEY: label}]
api_instance = client.CustomObjectsApi( api_instance = client.CustomObjectsApi(
context.control_plane.get_kubernetes_client() context.control_plane.get_kubernetes_client()
) )

View file

@ -210,6 +210,7 @@ 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