Skip to content

Commit

Permalink
feat(images): detect more images from crds
Browse files Browse the repository at this point in the history
  • Loading branch information
buroa committed Feb 26, 2025
1 parent 83a1cd5 commit e620962
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions flux_local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,38 @@
"CronJob",
"Job",
"ReplicationController",
"EMQX", # apps.emqx.io/v2beta1
"Cluster", # postgresql.cnpg.io/v1
"CephCluster", # ceph.rook.io/v1
"Alertmanager", # monitoring.coreos.com/v1
"Prometheus", # monitoring.coreos.com/v1
"AutoscalingRunnerSet", # actions.github.com/v1alpha1
]

# Default image key for most object types.
IMAGE_KEY = "image"

# Override the default image key for some object types.
KINDS_IMAGE_KEY = {
"Cluster": "imageName"
}


def _extract_images(doc: dict[str, Any]) -> set[str]:
def _extract_images(kind: str, doc: dict[str, Any]) -> set[str]:
"""Extract the image from a Kubernetes object."""
images: set[str] = set({})
image_key = KINDS_IMAGE_KEY.get(kind) or IMAGE_KEY

for key, value in doc.items():
if key == IMAGE_KEY:
if key == image_key:
images.add(value)
elif isinstance(value, dict):
images.update(_extract_images(value))
images.update(_extract_images(kind, value))
elif isinstance(value, list):
for item in value:
if isinstance(item, dict):
images.update(_extract_images(item))
images.update(_extract_images(kind, item))

return images


Expand All @@ -56,7 +72,8 @@ def add_image(name: str, doc: dict[str, Any]) -> None:
Updates the image set with the images found in the document.
"""
images = _extract_images(doc)
kind = doc.get("kind")
images = _extract_images(kind, doc)
if not images:
return
if name in self.images:
Expand Down

0 comments on commit e620962

Please sign in to comment.