-
Notifications
You must be signed in to change notification settings - Fork 25
Add option to build Kolla container images by service groups instead of pattern matching #2206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seunghun1ee
wants to merge
5
commits into
stackhpc/2025.1
Choose a base branch
from
group-container-image-build
base: stackhpc/2025.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fa563fe
Add get-service-images command on kolla-images.py
seunghun1ee 91d423e
Add step to process regex
seunghun1ee 66ebedf
Add kolla ansible checkout if service-group is used
seunghun1ee 28ce6af
Improve get-service-images
seunghun1ee d4b6643
Better description for new build method option
seunghun1ee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,10 @@ def parse_args() -> argparse.Namespace: | |
| subparser = subparsers.add_parser("check-hierarchy", help="Check tag variable hierarchy against kolla-ansible") | ||
| subparser.add_argument("--kolla-ansible-path", required=True, help="Path to kolla-ansible repostory checked out to correct branch") | ||
|
|
||
| subparser = subparsers.add_parser("get-service-images", help="Get space separated list of images used by services in kolla-ansible") | ||
| subparser.add_argument("--kolla-ansible-path", required=True, help="Path to kolla-ansible repostory checked out to correct branch") | ||
| subparser.add_argument("--services", default=None, required=False, help="Space separated list of services to get a list of images") | ||
|
|
||
| subparser = subparsers.add_parser("check-tags", help="Check specified tags for each image exist in the Ark registry") | ||
| subparser.add_argument("--registry", required=True, help="Hostname of container image registry") | ||
| subparser.add_argument("--namespace", required=True, help="Namespace in container image registry") | ||
|
|
@@ -335,13 +339,19 @@ def check_image_map(kolla_ansible_path: str): | |
| sys.exit(1) | ||
|
|
||
|
|
||
| def check_hierarchy(kolla_ansible_path: str): | ||
| """Check the tag variable hierarchy against Kolla Ansible variables.""" | ||
| def get_hierarchy(kolla_ansible_path: str) -> yaml: | ||
| """Return the tag variable hierarchy against Kolla Ansible variables""" | ||
| cmd = """git grep -h '^[a-z0-9_]*_tag:' ansible/roles/*/defaults/main.yml""" | ||
| hierarchy_str = subprocess.check_output(cmd, shell=True, cwd=os.path.realpath(kolla_ansible_path)) | ||
| hierarchy = yaml.safe_load(hierarchy_str) | ||
| # This one is not a container: | ||
| hierarchy.pop("octavia_amp_image_tag") | ||
| return hierarchy | ||
|
|
||
|
|
||
| def check_hierarchy(kolla_ansible_path: str): | ||
| """Check the tag variable hierarchy against Kolla Ansible variables.""" | ||
| hierarchy = get_hierarchy(kolla_ansible_path) | ||
| tag_var_re = re.compile(r"^([a-z0-9_]+)_tag$") | ||
| parent_re = re.compile(r"{{[\s]*([a-z0-9_]+)_tag[\s]*}}") | ||
| hierarchy = { | ||
|
|
@@ -363,6 +373,44 @@ def check_hierarchy(kolla_ansible_path: str): | |
| sys.exit(1) | ||
|
|
||
|
|
||
| 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) | ||
|
Comment on lines
+376
to
+411
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can be simplified for better readability and maintainability:
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) |
||
|
|
||
|
|
||
| def list_containers(base_distros: List[str]): | ||
| """List supported containers.""" | ||
| images = read_images("etc/kayobe/pulp.yml") | ||
|
|
@@ -414,6 +462,8 @@ def main(): | |
| check_image_map(args.kolla_ansible_path) | ||
| elif args.command == "check-hierarchy": | ||
| check_hierarchy(args.kolla_ansible_path) | ||
| elif args.command == "get-service-images": | ||
| get_service_images(args.kolla_ansible_path, args.services) | ||
| elif args.command == "check-tags": | ||
| check_tags(base_distros, kolla_image_tags, args.registry, args.namespace) | ||
| elif args.command == "list-containers": | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type hint
yamlis incorrect asyamlis a module, not a type. This function returns a dictionary, soDict[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.