Add labels and annotations to org namespaces
This commit is contained in:
parent
918c2a20ec
commit
0c6a76ea71
1 changed files with 21 additions and 2 deletions
|
@ -217,9 +217,28 @@ class ControlPlane(ServalaModelMixin, models.Model):
|
|||
api_instance.read_namespace(name=name)
|
||||
except kubernetes.client.ApiException as e:
|
||||
if e.status == 404:
|
||||
# Namespace does not exist, create it
|
||||
labels = {
|
||||
"servala.com/organization_id": str(organization.id),
|
||||
}
|
||||
annotations = {
|
||||
"servala.com/organization": organization.name,
|
||||
"servala.com/billing": organization.origin.name,
|
||||
"servala.com/origin": organization.billing_entity.name,
|
||||
}
|
||||
|
||||
for field in ("company_id", "invoice_id"):
|
||||
if value := getattr(organization.billing_entity, f"odoo_{field}"):
|
||||
labels[f"servala.com/erp_{field}"] = value
|
||||
|
||||
if organization.odoo_sale_order_id:
|
||||
annotations["servala.com/sales_order"] = str(
|
||||
organization.odoo_sale_order_id
|
||||
)
|
||||
|
||||
body = kubernetes.client.V1Namespace(
|
||||
metadata=kubernetes.client.V1ObjectMeta(name=name)
|
||||
metadata=kubernetes.client.V1ObjectMeta(
|
||||
name=name, labels=labels, annotations=annotations
|
||||
)
|
||||
)
|
||||
api_instance.create_namespace(body=body)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue