Skip to content

Commit 8149122

Browse files
committed
chore(controller): unified naming convention for ptype
1 parent 5d67d65 commit 8149122

37 files changed

Lines changed: 488 additions & 457 deletions

rootfs/api/admissions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ def detect(self, request: Request) -> bool:
2828
def handle(self, request: Request) -> bool:
2929
app_id = request["object"]["metadata"]["namespace"]
3030
app = models.app.App.objects.filter(id=app_id).first()
31-
container_type = request["object"]["metadata"].get("labels", {}).get("type", "")
32-
if app and container_type:
31+
ptype = request["object"]["metadata"].get("labels", {}).get("type", "")
32+
if app and ptype:
3333
status = request["object"]["status"]
3434
replicas = request["object"]["spec"].get("replicas", 0)
3535
if "active" in status:
3636
replicas += 1
3737
elif "succeeded" in status or "failed" in status:
3838
replicas -= 1
3939
replicas = 0 if replicas < 0 else replicas
40-
if app.structure.get(container_type, 0) != replicas:
40+
if app.structure.get(ptype, 0) != replicas:
4141
models.app.App.objects.filter(id=app.id).update(
4242
structure=Func(
4343
F("structure"),
44-
Value([container_type]),
44+
Value([ptype]),
4545
Value(replicas, JSONField()),
4646
function="jsonb_set",
4747
)
@@ -64,18 +64,18 @@ def detect(self, request: Request) -> bool:
6464
def handle(self, request: Request) -> bool:
6565
app_id = request["object"]["metadata"]["namespace"]
6666
app = models.app.App.objects.filter(id=app_id).first()
67-
container_type = None
67+
ptype = None
6868
for item in request["object"]["status"]["selector"].split(","):
6969
key, value = item.split("=")
7070
if key == "type":
71-
container_type = value
72-
if app and container_type:
71+
ptype = value
72+
if app and ptype:
7373
replicas = request["object"]["spec"].get("replicas", 0)
74-
if app.structure.get(container_type, 0) != replicas:
74+
if app.structure.get(ptype, 0) != replicas:
7575
models.app.App.objects.filter(id=app.id).update(
7676
structure=Func(
7777
F("structure"),
78-
Value([container_type]),
78+
Value([ptype]),
7979
Value(replicas, JSONField()),
8080
function="jsonb_set",
8181
)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Generated by Django 4.2.15 on 2024-09-03 03:48
2+
3+
import api.utils
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0011_appsettings_autodeploy'),
12+
]
13+
14+
operations = [
15+
migrations.AlterModelOptions(
16+
name='app',
17+
options={'ordering': ['id'], 'verbose_name': 'Application'},
18+
),
19+
migrations.RenameField(
20+
model_name='domain',
21+
old_name='procfile_type',
22+
new_name='ptype',
23+
),
24+
migrations.RenameField(
25+
model_name='route',
26+
old_name='procfile_type',
27+
new_name='ptype',
28+
),
29+
migrations.RenameField(
30+
model_name='service',
31+
old_name='procfile_type',
32+
new_name='ptype',
33+
),
34+
migrations.AddField(
35+
model_name='certificate',
36+
name='app',
37+
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='api.app'),
38+
preserve_default=False,
39+
),
40+
migrations.AddField(
41+
model_name='release',
42+
name='conditions',
43+
field=models.JSONField(default=list),
44+
),
45+
migrations.AlterField(
46+
model_name='certificate',
47+
name='name',
48+
field=models.CharField(max_length=253, validators=[api.utils.validate_label]),
49+
),
50+
migrations.AlterUniqueTogether(
51+
name='certificate',
52+
unique_together={('app', 'name')},
53+
),
54+
migrations.AlterUniqueTogether(
55+
name='service',
56+
unique_together={('app', 'ptype')},
57+
),
58+
]

rootfs/api/migrations/0012_alter_app_options_certificate_app_release_conditions_and_more.py renamed to rootfs/api/migrations/0013_migration_permissions_and_certificates.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# Generated by Django 4.2.15 on 2024-08-30 00:53
1+
# Generated by Django 4.2.15 on 2024-09-03 03:48
22

3-
import api.utils
4-
from django.db import migrations, models
5-
import django.db.models.deletion
3+
from django.db import migrations
64
from guardian.shortcuts import assign_perm, get_users_with_perms, remove_perm
75
from api.models.app import App, VIEW_APP_PERMISSION, CHANGE_APP_PERMISSION
86
from api.models.domain import Domain
@@ -34,34 +32,10 @@ def migration_certificate(apps, schema_editor):
3432
class Migration(migrations.Migration):
3533

3634
dependencies = [
37-
('api', '0011_appsettings_autodeploy'),
35+
('api', '0012_alter_app_options_rename_procfile_type_domain_ptype_and_more'),
3836
]
3937

4038
operations = [
41-
migrations.AlterModelOptions(
42-
name='app',
43-
options={'ordering': ['id'], 'verbose_name': 'Application'},
44-
),
45-
migrations.AddField(
46-
model_name='certificate',
47-
name='app',
48-
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='api.app'),
49-
preserve_default=False,
50-
),
51-
migrations.AddField(
52-
model_name='release',
53-
name='conditions',
54-
field=models.JSONField(default=list),
55-
),
56-
migrations.AlterField(
57-
model_name='certificate',
58-
name='name',
59-
field=models.CharField(max_length=253, validators=[api.utils.validate_label]),
60-
),
61-
migrations.AlterUniqueTogether(
62-
name='certificate',
63-
unique_together={('app', 'name')},
64-
),
6539
migrations.RunPython(migration_permission),
6640
migrations.RunPython(migration_certificate),
6741
]

0 commit comments

Comments
 (0)