Skip to content

Add option to build Kolla container images by service groups instead of pattern matching#2206

Closed
seunghun1ee wants to merge 5 commits into
stackhpc/2025.1from
group-container-image-build
Closed

Add option to build Kolla container images by service groups instead of pattern matching#2206
seunghun1ee wants to merge 5 commits into
stackhpc/2025.1from
group-container-image-build

Conversation

@seunghun1ee

Copy link
Copy Markdown
Member

Currently we build Kolla container images with regex filter which will limit the image getting built with pattern matching.
This brings the problem of Kolla building images from unrelated service or not building related images because of image naming.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new get-service-images command to the kolla-images.py script, allowing users to retrieve a list of Kolla container images based on service groups. The implementation involves refactoring the existing check_hierarchy function for better code reuse. My review focuses on improving type safety and enhancing the readability of the new logic. I've suggested using more precise type hints and refactoring the main logic to be more concise and easier to understand.

Comment thread tools/kolla-images.py
Comment on lines +342 to +343
def get_hierarchy(kolla_ansible_path: str) -> yaml:
"""Return the tag variable hierarchy against Kolla Ansible variables"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The return type hint yaml is incorrect as yaml is a module, not a type. This function returns a dictionary, so Dict[str, str] would be the correct type hint. Also, I've added a period at the end of the docstring for consistency with others in the file.

Suggested change
def get_hierarchy(kolla_ansible_path: str) -> yaml:
"""Return the tag variable hierarchy against Kolla Ansible variables"""
def get_hierarchy(kolla_ansible_path: str) -> Dict[str, str]:
"""Return the tag variable hierarchy against Kolla Ansible variables."""

Comment thread tools/kolla-images.py
Comment on lines +376 to +411
def get_service_images(kolla_ansible_path: str, services: str):
"""Get space separated list of images used by selected services in Kolla Ansible"""
hierarchy = get_hierarchy(kolla_ansible_path)
services_list = []
is_filtered = False
if services:
services_list = services.split(" ")
is_filtered = True
images_list = []
child_re = re.compile(r"^([a-z0-9_]+)_tag$")
parent_re = re.compile(r"{{[\s]*([a-z0-9_]+)_tag[\s]*}}")
parents_no_child_set = set()
for child, parent in hierarchy.items():
child_name = child_re.match(child).group(1)
parent_name = parent_re.match(parent).group(1)
# This is parent
if parent_name == "openstack":
# And part of the query or no services specified
if is_filtered and child_name in services_list or not is_filtered:
parents_no_child_set.add(child_name) # Add to parent list
continue # Then move on
# This service is not part of the query
if is_filtered and parent_name not in services_list:
continue # ignore
# Child found
if parent_name in parents_no_child_set:
parents_no_child_set.discard(parent_name) # Remove parent that has child
images_list.append(child_name) # Add the child to the list
# Add parent with no child
images_list += list(parents_no_child_set)
# NOTE(seunghun1ee): Currently K-A has inconsistency on mariadb tag on 2025.1 release
# Adding manually
if is_filtered and "mariadb" in services_list or not is_filtered:
images_list.append("mariadb")
images_str = " ".join(images_list).replace("_", "-")
print(images_str)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This function can be simplified for better readability and maintainability:

  1. The services argument can be None, so its type hint should be Optional[str].
  2. The is_filtered boolean flag can be removed by checking services_list directly, which simplifies the conditional logic.

Here is a suggested refactoring that applies these improvements:

def get_service_images(kolla_ansible_path: str, services: Optional[str]):
    """Get space separated list of images used by selected services in Kolla Ansible"""
    hierarchy = get_hierarchy(kolla_ansible_path)
    services_list = services.split(" ") if services else []
    images_list = []
    child_re = re.compile(r"^([a-z0-9_]+)_tag$")
    parent_re = re.compile(r"{{[\s]*([a-z0-9_]+)_tag[\s]*}}")
    parents_no_child_set = set()
    for child, parent in hierarchy.items():
        child_name = child_re.match(child).group(1)
        parent_name = parent_re.match(parent).group(1)
        # This is parent
        if parent_name == "openstack":
            # And part of the query or no services specified
            if not services_list or child_name in services_list:
                parents_no_child_set.add(child_name)  # Add to parent list
            continue  # Then move on
        # This service is not part of the query
        if services_list and parent_name not in services_list:
            continue  # ignore
        # Child found
        if parent_name in parents_no_child_set:
            parents_no_child_set.discard(parent_name)  # Remove parent that has child
        images_list.append(child_name)  # Add the child to the list
    # Add parent with no child
    images_list.extend(parents_no_child_set)
    # NOTE(seunghun1ee): Currently K-A has inconsistency on mariadb tag on 2025.1 release
    # Adding manually
    if not services_list or "mariadb" in services_list:
        images_list.append("mariadb")
    images_str = " ".join(images_list).replace("_", "-")
    print(images_str)

@Alex-Welsh Alex-Welsh added the waiting-author-response PR is waiting for the author to respond label May 22, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Happy Friday @seunghun1ee, this is a friendly reminder that this PR is waiting for your changes or response. Please take a look when you have a moment!

Note: Once your changes are ready, remove the waiting-author-response label and add the waiting-review label.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Happy Friday @seunghun1ee, this is a friendly reminder that this PR is waiting for your changes or response. Please take a look when you have a moment!

Note: Once your changes are ready, remove the waiting-author-response label and add the waiting-review label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-author-response PR is waiting for the author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants