From 3e2c3161b7c0eb4c9a585a34362ba88e85a55f17 Mon Sep 17 00:00:00 2001 From: Dimitris Moraitis Date: Tue, 4 Jun 2024 14:09:00 +0300 Subject: [PATCH] Add support for overriding images of target containers --- operator/crd.yaml | 3 +++ operator/op.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/operator/crd.yaml b/operator/crd.yaml index ad66b7a..c583737 100644 --- a/operator/crd.yaml +++ b/operator/crd.yaml @@ -112,6 +112,9 @@ spec: description: Override the entrypoint of specific containers in the target Deployment or Statefulset when mounting the code volume. additionalProperties: type: string + images: + type: object + description: Override the image of specific containers in the target Deployment or Statefulset when mounting the code volume. mounted: type: boolean description: Whether the volume should actually be mounted. diff --git a/operator/op.py b/operator/op.py index e4cd64b..e19b09d 100644 --- a/operator/op.py +++ b/operator/op.py @@ -311,3 +311,19 @@ def restore_entrypoints(*, manifest: dict, entrypoints: dict) -> None: if container.get("command"): del container["command"] del container["args"] + + +def update_images(*, manifest: dict, images: dict) -> None: + for container in manifest["spec"]["template"]["spec"]["containers"]: + image = images.get(container["name"]) + if image is None: + continue + container["x-original-image"] = container["image"] + container["image"] = image + + +def restore_images(*, manifest: dict) -> None: + for container in manifest["spec"]["template"]["spec"]["containers"]: + if container.get("x-original-image"): + container["image"] = container["x-original-image"] + del container["x-original-image"]