2020-11-04 09:41:18 +00:00
|
|
|
# Generated by Django 3.1.3 on 2020-11-04 09:11
|
|
|
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
import django.db.models.deletion
|
|
|
|
from django.apps.registry import Apps
|
2020-11-08 20:02:52 +00:00
|
|
|
from django.core.exceptions import FieldError
|
2020-11-04 09:41:18 +00:00
|
|
|
from django.db import migrations, models
|
|
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
2020-11-08 20:02:52 +00:00
|
|
|
|
2020-11-04 12:01:38 +00:00
|
|
|
import passbook.lib.models
|
|
|
|
|
2020-11-04 09:41:18 +00:00
|
|
|
|
|
|
|
def migrate_to_service_connection(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
|
|
|
db_alias = schema_editor.connection.alias
|
|
|
|
Outpost = apps.get_model("passbook_outposts", "Outpost")
|
2020-11-04 09:54:44 +00:00
|
|
|
DockerServiceConnection = apps.get_model(
|
|
|
|
"passbook_outposts", "DockerServiceConnection"
|
|
|
|
)
|
|
|
|
KubernetesServiceConnection = apps.get_model(
|
|
|
|
"passbook_outposts", "KubernetesServiceConnection"
|
|
|
|
)
|
2020-11-04 09:41:18 +00:00
|
|
|
from passbook.outposts.apps import PassbookOutpostConfig
|
2020-11-04 09:54:44 +00:00
|
|
|
|
2020-11-04 09:41:18 +00:00
|
|
|
# Ensure that local connection have been created
|
|
|
|
PassbookOutpostConfig.init_local_connection(None)
|
|
|
|
|
|
|
|
docker = DockerServiceConnection.objects.filter(local=True)
|
|
|
|
k8s = KubernetesServiceConnection.objects.filter(local=True)
|
|
|
|
|
2020-11-04 14:36:31 +00:00
|
|
|
try:
|
|
|
|
for outpost in (
|
|
|
|
Outpost.objects.using(db_alias).all().exclude(deployment_type="custom")
|
|
|
|
):
|
|
|
|
if outpost.deployment_type == "kubernetes":
|
|
|
|
outpost.service_connection = k8s
|
|
|
|
elif outpost.deployment_type == "docker":
|
|
|
|
outpost.service_connection = docker
|
|
|
|
outpost.save()
|
|
|
|
except FieldError:
|
|
|
|
# This is triggered during e2e tests when this function is called on an already-upgraded
|
|
|
|
# schema
|
|
|
|
pass
|
2020-11-04 09:41:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2020-11-04 09:54:44 +00:00
|
|
|
("passbook_outposts", "0009_fix_missing_token_identifier"),
|
2020-11-04 09:41:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.CreateModel(
|
2020-11-04 09:54:44 +00:00
|
|
|
name="OutpostServiceConnection",
|
2020-11-04 09:41:18 +00:00
|
|
|
fields=[
|
2020-11-04 09:54:44 +00:00
|
|
|
(
|
|
|
|
"uuid",
|
|
|
|
models.UUIDField(
|
|
|
|
default=uuid.uuid4,
|
|
|
|
editable=False,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
("name", models.TextField()),
|
|
|
|
(
|
|
|
|
"local",
|
|
|
|
models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text="If enabled, use the local connection. Required Docker socket/Kubernetes Integration",
|
|
|
|
unique=True,
|
|
|
|
),
|
|
|
|
),
|
2020-11-04 09:41:18 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
2020-11-04 09:54:44 +00:00
|
|
|
name="DockerServiceConnection",
|
2020-11-04 09:41:18 +00:00
|
|
|
fields=[
|
2020-11-04 09:54:44 +00:00
|
|
|
(
|
|
|
|
"outpostserviceconnection_ptr",
|
|
|
|
models.OneToOneField(
|
|
|
|
auto_created=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
parent_link=True,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
to="passbook_outposts.outpostserviceconnection",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
("url", models.TextField()),
|
|
|
|
("tls", models.BooleanField()),
|
2020-11-04 09:41:18 +00:00
|
|
|
],
|
2020-11-04 09:54:44 +00:00
|
|
|
bases=("passbook_outposts.outpostserviceconnection",),
|
2020-11-04 09:41:18 +00:00
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
2020-11-04 09:54:44 +00:00
|
|
|
name="KubernetesServiceConnection",
|
2020-11-04 09:41:18 +00:00
|
|
|
fields=[
|
2020-11-04 09:54:44 +00:00
|
|
|
(
|
|
|
|
"outpostserviceconnection_ptr",
|
|
|
|
models.OneToOneField(
|
|
|
|
auto_created=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
parent_link=True,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
to="passbook_outposts.outpostserviceconnection",
|
|
|
|
),
|
|
|
|
),
|
2020-11-04 12:01:38 +00:00
|
|
|
("kubeconfig", models.JSONField()),
|
2020-11-04 09:41:18 +00:00
|
|
|
],
|
2020-11-04 09:54:44 +00:00
|
|
|
bases=("passbook_outposts.outpostserviceconnection",),
|
2020-11-04 09:41:18 +00:00
|
|
|
),
|
|
|
|
migrations.AddField(
|
2020-11-04 09:54:44 +00:00
|
|
|
model_name="outpost",
|
|
|
|
name="service_connection",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
blank=True,
|
|
|
|
default=None,
|
|
|
|
help_text="Select Service-Connection passbook should use to manage this outpost. Leave empty if passbook should not handle the deployment.",
|
|
|
|
null=True,
|
|
|
|
on_delete=django.db.models.deletion.SET_DEFAULT,
|
|
|
|
to="passbook_outposts.outpostserviceconnection",
|
|
|
|
),
|
2020-11-04 09:41:18 +00:00
|
|
|
),
|
|
|
|
migrations.RunPython(migrate_to_service_connection),
|
|
|
|
migrations.RemoveField(
|
2020-11-04 09:54:44 +00:00
|
|
|
model_name="outpost",
|
|
|
|
name="deployment_type",
|
2020-11-04 09:41:18 +00:00
|
|
|
),
|
2020-11-04 12:01:38 +00:00
|
|
|
migrations.AlterModelOptions(
|
|
|
|
name="dockerserviceconnection",
|
|
|
|
options={
|
|
|
|
"verbose_name": "Docker Service-Connection",
|
|
|
|
"verbose_name_plural": "Docker Service-Connections",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
migrations.AlterModelOptions(
|
|
|
|
name="kubernetesserviceconnection",
|
|
|
|
options={
|
|
|
|
"verbose_name": "Kubernetes Service-Connection",
|
|
|
|
"verbose_name_plural": "Kubernetes Service-Connections",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
migrations.AlterField(
|
|
|
|
model_name="outpost",
|
|
|
|
name="service_connection",
|
|
|
|
field=passbook.lib.models.InheritanceForeignKey(
|
|
|
|
blank=True,
|
|
|
|
default=None,
|
|
|
|
help_text="Select Service-Connection passbook should use to manage this outpost. Leave empty if passbook should not handle the deployment.",
|
|
|
|
null=True,
|
|
|
|
on_delete=django.db.models.deletion.SET_DEFAULT,
|
|
|
|
to="passbook_outposts.outpostserviceconnection",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
migrations.AlterModelOptions(
|
|
|
|
name="outpostserviceconnection",
|
|
|
|
options={
|
|
|
|
"verbose_name": "Outpost Service-Connection",
|
|
|
|
"verbose_name_plural": "Outpost Service-Connections",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
migrations.AlterField(
|
|
|
|
model_name="kubernetesserviceconnection",
|
|
|
|
name="kubeconfig",
|
|
|
|
field=models.JSONField(
|
|
|
|
default=None,
|
|
|
|
help_text="Paste your kubeconfig here. passbook will automatically use the currently selected context.",
|
|
|
|
),
|
|
|
|
preserve_default=False,
|
|
|
|
),
|
2020-11-04 09:41:18 +00:00
|
|
|
]
|