Add organization namespaces
This commit is contained in:
parent
9a403d74f2
commit
a72358a854
2 changed files with 53 additions and 0 deletions
34
src/servala/core/migrations/0009_organization_namespace.py
Normal file
34
src/servala/core/migrations/0009_organization_namespace.py
Normal file
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue