Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
[ART-3324] Ignore disabled dependents
Browse files Browse the repository at this point in the history
Currently a disabled (or wip) image will be loaded anyway if it is
listed as a dependent of an enabled image.

This PR changes the behavior to ignore disabled dependents unless
`--load-disabled` or `--load-wip` option is specified.
  • Loading branch information
vfreex authored and sosiouxme committed Feb 13, 2023
1 parent e90896a commit 6047bea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion doozerlib/image.py
Expand Up @@ -27,7 +27,9 @@ def __init__(self, runtime, data_obj: Dict, commitish: Optional[str] = None, clo
self.dependencies: Set[str] = set()
dependents = self.config.get('dependents', [])
for d in dependents:
dependent: ImageMetadata = self.runtime.late_resolve_image(d, add=True)
dependent = self.runtime.late_resolve_image(d, add=True, required=False)
if not dependent:
continue
dependent.dependencies.add(self.distgit_key)
self.children.append(dependent)
if clone_source:
Expand Down
16 changes: 14 additions & 2 deletions doozerlib/runtime.py
Expand Up @@ -1074,9 +1074,14 @@ def resolve_image(self, distgit_name, required=True):
raise DoozerFatalError("Unable to find image metadata in group / included images: %s" % distgit_name)
return self.image_map[distgit_name]

def late_resolve_image(self, distgit_name, add=False):
def late_resolve_image(self, distgit_name, add=False, required=True):
"""Resolve image and retrieve meta, optionally adding to image_map.
If image not found, error will be thrown"""
If image not found, error will be thrown
:param distgit_name: Distgit key
:param add: Add the image to image_map
:param required: If False, return None if the image is not enabled
:return: Image meta
"""

if distgit_name in self.image_map:
return self.image_map[distgit_name]
Expand All @@ -1086,6 +1091,13 @@ def late_resolve_image(self, distgit_name, add=False):
if not data_obj:
raise DoozerFatalError('Unable to resolve image metadata for {}'.format(distgit_name))

mode = data_obj.data.get("mode", "enabled")
if mode == "disabled" and not self.load_disabled or mode == "wip" and not self.load_wip:
if required:
raise DoozerFatalError('Attempted to load image {} but it has mode {}'.format(distgit_name, mode))
self.logger.warning("Image %s will not be loaded because it has mode %s", distgit_name, mode)
return None

meta = ImageMetadata(self, data_obj, self.upstream_commitish_overrides.get(data_obj.key))
if add:
self.image_map[distgit_name] = meta
Expand Down

0 comments on commit 6047bea

Please sign in to comment.