diff --git a/src/servala/core/migrations/0009_organization_namespace.py b/src/servala/core/migrations/0009_organization_namespace.py new file mode 100644 index 0000000..393db68 --- /dev/null +++ b/src/servala/core/migrations/0009_organization_namespace.py @@ -0,0 +1,34 @@ +# Generated by Django 5.2b1 on 2025-03-28 09:39 + +import django.core.validators +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0008_created_and_updated"), + ] + + operations = [ + migrations.AddField( + model_name="organization", + name="namespace", + field=models.CharField( + default="namespace", + help_text="This namespace will be used for all Kubernetes resources. Cannot be changed after creation.", + max_length=63, + unique=True, + validators=[ + django.core.validators.RegexValidator( + code="invalid_namespace", + message='Namespace must consist of lowercase alphanumeric characters or "-", must start and end with an alphanumeric character.', + regex="^[a-z0-9]([-a-z0-9]*[a-z0-9])?$", + ) + ], + verbose_name="Kubernetes Namespace", + ), + preserve_default=False, + ), + ] diff --git a/src/servala/core/models/organization.py b/src/servala/core/models/organization.py index e842c36..cc5eae7 100644 --- a/src/servala/core/models/organization.py +++ b/src/servala/core/models/organization.py @@ -1,6 +1,7 @@ import rules import urlman from django.conf import settings +from django.core.validators import RegexValidator from django.db import models from django.utils.functional import cached_property from django.utils.text import slugify @@ -13,6 +14,24 @@ from servala.core.models.mixins import ServalaModelMixin class Organization(ServalaModelMixin, models.Model): name = models.CharField(max_length=100, verbose_name=_("Name")) + namespace = models.CharField( + max_length=63, + verbose_name=_("Kubernetes Namespace"), + unique=True, + help_text=_( + "This namespace will be used for all Kubernetes resources. Cannot be changed after creation." + ), + validators=[ + RegexValidator( + regex=r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?$", + message=_( + 'Namespace must consist of lowercase alphanumeric characters or "-", ' + "must start and end with an alphanumeric character." + ), + code="invalid_namespace", + ) + ], + ) billing_entity = models.ForeignKey( to="BillingEntity",