Skip to content

Commit 8cdf90e

Browse files
committed
label namespace to comply with Pod Security Admission
1 parent 05aa355 commit 8cdf90e

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/deployment/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
_LOAD_BALANCER_POLL_INTERVAL_SECONDS = float(2)
7878
_OVERLAY_IP_TIMEOUT_SECONDS = float(300)
7979
_OVERLAY_IP_POLL_INTERVAL_SECONDS = float(5)
80+
_POD_SECURITY_LABELS = {
81+
"pod-security.kubernetes.io/enforce": "privileged",
82+
"pod-security.kubernetes.io/audit": "privileged",
83+
"pod-security.kubernetes.io/warn": "privileged",
84+
}
8085
DNSRecordType = Literal["AAAA", "CNAME"]
8186
DATABASE_DNS_RECORD_TYPE: Literal["AAAA"] = "AAAA"
8287

@@ -494,6 +499,8 @@ async def create_vela_config(
494499
branch_id,
495500
)
496501

502+
await kube_service.ensure_namespace(namespace, labels=_POD_SECURITY_LABELS)
503+
497504
chart = resources.files(__package__) / "charts" / "vela"
498505
compose_file = _configure_compose_storage(
499506
_load_compose_manifest(),

src/deployment/kubernetes/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import math
3+
from collections.abc import Mapping
34
from copy import deepcopy
45
from typing import Any
56

@@ -18,9 +19,13 @@ async def delete_namespace(self, namespace: str) -> None:
1819
async with core_v1_client() as core_v1:
1920
await core_v1.delete_namespace(name=namespace)
2021

21-
async def ensure_namespace(self, namespace: str) -> None:
22+
async def ensure_namespace(self, namespace: str, *, labels: Mapping[str, str] | None = None) -> None:
23+
metadata_kwargs: dict[str, Any] = {"name": namespace}
24+
if labels:
25+
metadata_kwargs["labels"] = labels
26+
2227
async with core_v1_client() as core_v1:
23-
body = client.V1Namespace(metadata=client.V1ObjectMeta(name=namespace))
28+
body = client.V1Namespace(metadata=client.V1ObjectMeta(**metadata_kwargs))
2429
try:
2530
await core_v1.create_namespace(body=body)
2631
except client.exceptions.ApiException as exc:

0 commit comments

Comments
 (0)