Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Applies overrides to the image descriptor.
"""
if not overrides:
return
for override in overrides:
if override.name:
self.name = override.name
if override.version:
self.version = override.version
if override.base:
self.base = override.base
if override.description:
self.description = override.description
labels = Image._to_dict(self.labels)
for label in override.labels:
name = label.name
if name in labels:
labels[name] = label.merge(labels[name])
else:
labels[name] = label
self._descriptor['labels'] = list(labels.values())
envs = Image._to_dict(self.envs)
for env in override.envs:
name = env.name
if name in envs:
envs[name] = env.merge(envs[name])
else:
envs[name] = env
self._descriptor['envs'] = list(envs.values())
if name in labels:
labels[name] = label.merge(labels[name])
else:
labels[name] = label
self._descriptor['labels'] = list(labels.values())
envs = Image._to_dict(self.envs)
for env in override.envs:
name = env.name
if name in envs:
envs[name] = env.merge(envs[name])
else:
envs[name] = env
self._descriptor['envs'] = list(envs.values())
ports = Image._to_dict(self.ports)
for port in override.ports:
name = port.value
if name in ports:
ports[name] = port.merge(ports[name])
else:
ports[name] = port
self._descriptor['ports'] = list(ports.values())
module_repositories = Image._to_dict(self.modules.repositories)
for repository in override.modules.repositories:
name = repository.name
if name in module_repositories:
module_repositories[name] = repository.merge(module_repositories[name])
else:
module_repositories[name] = repository
self.modules._descriptor['repositories'] = list(module_repositories.values())
if name in envs:
envs[name] = env.merge(envs[name])
else:
envs[name] = env
self._descriptor['envs'] = list(envs.values())
ports = Image._to_dict(self.ports)
for port in override.ports:
name = port.value
if name in ports:
ports[name] = port.merge(ports[name])
else:
ports[name] = port
self._descriptor['ports'] = list(ports.values())
module_repositories = Image._to_dict(self.modules.repositories)
for repository in override.modules.repositories:
name = repository.name
if name in module_repositories:
module_repositories[name] = repository.merge(module_repositories[name])
else:
module_repositories[name] = repository
self.modules._descriptor['repositories'] = list(module_repositories.values())
package_repositories = Image._to_dict(self.packages.repositories)
for repository in override.packages.repositories:
name = repository.name
if name in package_repositories:
package_repositories[name] = repository.merge(package_repositories[name])
else:
package_repositories[name] = repository
self.packages._descriptor['repositories'] = list(package_repositories.values())
self.packages.install.append(package)
artifact_overrides = self._image_overrides['artifacts']
image_artifacts = Image._to_dict(self.artifacts)
for artifact in override.artifacts:
name = artifact.name
# collect override so we can apply it to modules
artifact_overrides[name] = artifact
# add it to the list of everything
self._all_artifacts[name] = artifact
# Apply override to image descriptor
image_artifacts[name] = artifact
self._descriptor['artifacts'] = list(image_artifacts.values())
module_overrides = self._image_overrides['modules']
image_modules = Image._to_dict(self.modules.install)
for module in override.modules.install:
name = module.name
# collect override so we can apply it to modules.
# this allows us to override module versions without affecting ordering.
module_overrides[name] = module
# Apply override to image descriptor
# If the module does not exists in the original descriptor, add it there
image_modules[name] = module
self.modules._descriptor['install'] = list(image_modules.values())
if override.run != None:
if self.run:
self.run = override.run.merge(self.run)
else:
self.run = override.run
self.packages.content_sets_file = override.packages.content_sets_file
else:
# If key exists and value is None - remove it from the main packages section
# Remove 'content_sets' too, because this is where it should already be translated into
self.packages._descriptor.pop('content_sets_file', None)
self.packages._descriptor.pop('content_sets', None)
if override.osbs != None:
self.osbs = override.osbs.merge(self.osbs)
for package in override.packages.install:
if package not in self.packages.install:
self.packages.install.append(package)
artifact_overrides = self._image_overrides['artifacts']
image_artifacts = Image._to_dict(self.artifacts)
for artifact in override.artifacts:
name = artifact.name
# collect override so we can apply it to modules
artifact_overrides[name] = artifact
# add it to the list of everything
self._all_artifacts[name] = artifact
# Apply override to image descriptor
image_artifacts[name] = artifact
self._descriptor['artifacts'] = list(image_artifacts.values())
module_overrides = self._image_overrides['modules']
image_modules = Image._to_dict(self.modules.install)
for module in override.modules.install:
name = module.name
# collect override so we can apply it to modules.
# this allows us to override module versions without affecting ordering.
existing = install_list.get(to_install.name, None)
# see if we've already processed this
if existing:
# check for a version conflict
if existing.version != to_install.version:
logger.warning("Module version inconsistency for {}: {} requested, but {} will be used.".format(
to_install.name, to_install.version, existing.version))
continue
module = module_registry.get_module(to_install.name, to_install.version)
if not module:
raise CekitError("Could not locate module %s version %s. Please verify that it is included in one of the "
"specified module repositories." % (to_install.name, to_install.version))
# collect artifacts and apply overrides
module_artifacts = Image._to_dict(module.artifacts)
for artifact in module.artifacts:
name = artifact.name
if name in artifact_overrides:
override = artifact_overrides[name]
self._all_artifacts[name] = override
module_artifacts[name] = override
else:
self._all_artifacts[name] = artifact
module._descriptor['artifacts'] = list(module_artifacts.values())
# collect package repositories
for repo in module.packages.repositories:
name = repo.name
if not name in self._package_repositories:
self._package_repositories[name] = repo
self.version = override.version
if override.base:
self.base = override.base
if override.description:
self.description = override.description
labels = Image._to_dict(self.labels)
for label in override.labels:
name = label.name
if name in labels:
labels[name] = label.merge(labels[name])
else:
labels[name] = label
self._descriptor['labels'] = list(labels.values())
envs = Image._to_dict(self.envs)
for env in override.envs:
name = env.name
if name in envs:
envs[name] = env.merge(envs[name])
else:
envs[name] = env
self._descriptor['envs'] = list(envs.values())
ports = Image._to_dict(self.ports)
for port in override.ports:
name = port.value
if name in ports:
ports[name] = port.merge(ports[name])
else:
ports[name] = port
self._descriptor['ports'] = list(ports.values())