diff --git a/examples/mounts-template.yaml b/examples/mounts-template.yaml index dd9d3b8..d4f230e 100644 --- a/examples/mounts-template.yaml +++ b/examples/mounts-template.yaml @@ -4,3 +4,5 @@ labels: ${LABELS} entrypoints: ${ENTRYPOINTS} + images: + ${IMAGES} 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"]