Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion etc/kayobe/kolla/globals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ kolla_base_distro_and_version: "{% raw %}{{ kolla_base_distro }}-{{ kolla_base_d
# Dict of Kolla image tags to deploy for each service.
# Each key is the tag variable prefix name, and the value is another dict,
# where the key is the OS distro and the value is the tag to deploy.
# NOTE: This is defined in etc/kayobe/kolla-image-tags.yml.
# NOTE: This is loaded from etc/kayobe/kolla-image-tags.yml and optionally
# overridden by etc/kayobe/environments/$KAYOBE_ENVIRONMENT/kolla-image-tags.yml.
kolla_image_tags:
{{ kolla_image_tags | to_nice_yaml | indent(width=4, first=true) }}

Expand Down
70 changes: 62 additions & 8 deletions tools/kolla-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
import re
import subprocess
import sys
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple

import yaml


# Dict of Kolla image tags to deploy for each service.
# Each key is the tag variable prefix name, and the value is another dict,
# where the key is the OS distro and the value is the tag to deploy.
# This is the content of etc/kayobe/kolla-image-tags.yml.
# Tags are loaded from etc/kayobe/kolla-image-tags.yml and optionally
# overridden by etc/kayobe/environments/$KAYOBE_ENVIRONMENT/kolla-image-tags.yml.
KollaImageTags = Dict[str, Dict[str, str]]

# Maps a Kolla image to a list of containers that use the image.
Expand Down Expand Up @@ -151,11 +152,64 @@ def read_unbuildable_images(images_file: str) -> Dict[str, List[str]]:
return variables["stackhpc_kolla_unbuildable_images"]


def read_kolla_image_tags(tags_file: str) -> KollaImageTags:
"""Read kolla image tags kolla-image-tags.yml config file."""
with open(get_abs_path(tags_file), "r") as f:
variables = yaml.safe_load(f)
return variables["kolla_image_tags"]
def read_kolla_image_tags_file(tags_file: pathlib.Path) -> KollaImageTags:
"""Read kolla image tags from a single YAML file."""
with tags_file.open("r") as f:
variables = yaml.safe_load(f) or {}
kolla_image_tags = variables.get("kolla_image_tags")
if not isinstance(kolla_image_tags, dict):
raise ValueError(f"Missing or invalid kolla_image_tags in {tags_file}")
return kolla_image_tags


def merge_kolla_image_tags(base: KollaImageTags, override: KollaImageTags) -> KollaImageTags:
"""Deep-merge Kolla image tags where override values take precedence."""
merged = {tag_var: dict(tags) for tag_var, tags in base.items()}
for tag_var, tags in override.items():
existing = merged.setdefault(tag_var, {})
existing.update(tags)
return merged


def get_kolla_image_tag_files() -> Tuple[pathlib.Path, Optional[pathlib.Path]]:
"""Return main and environment-specific kolla image tags files."""
main_tags_file = get_abs_path("etc/kayobe/kolla-image-tags.yml")
kayobe_environment = os.environ.get("KAYOBE_ENVIRONMENT")
if kayobe_environment:
env_tags_file = get_abs_path(f"etc/kayobe/environments/{kayobe_environment}/kolla-image-tags.yml")
else:
env_tags_file = None
return main_tags_file, env_tags_file


def load_kolla_image_tags() -> KollaImageTags:
"""Load and merge Kolla image tags from main and env-specific files."""
main_tags_file, env_tags_file = get_kolla_image_tag_files()
checked_files = [main_tags_file]
if env_tags_file is not None:
checked_files.append(env_tags_file)

loaded_files = []
kolla_image_tags: KollaImageTags = {}
for tags_file in checked_files:
if not tags_file.is_file():
continue
loaded_files.append(tags_file)
kolla_image_tags = merge_kolla_image_tags(kolla_image_tags, read_kolla_image_tags_file(tags_file))

if loaded_files:
return kolla_image_tags

kayobe_environment = os.environ.get("KAYOBE_ENVIRONMENT", "<unset>")
print("Failed to find kolla-image-tags.yml. Checked files:")
for tags_file in checked_files:
print(f" - {tags_file}")
print(f"KAYOBE_ENVIRONMENT={kayobe_environment}")
print("Expected YAML structure:")
print(" kolla_image_tags:")
print(" openstack:")
print(" rocky-9: <tag>")
sys.exit(1)
Comment thread
grzegorzkoper marked this conversation as resolved.
Outdated


def get_containers(image):
Expand Down Expand Up @@ -405,7 +459,7 @@ def list_tag_vars(kolla_image_tags: KollaImageTags):

def main():
args = parse_args()
kolla_image_tags = read_kolla_image_tags("etc/kayobe/kolla-image-tags.yml")
kolla_image_tags = load_kolla_image_tags()
base_distros = args.base_distros.split(",")

validate(kolla_image_tags)
Expand Down
Loading