Skip to content
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

fix(list-images): filter images by environment=production #9601

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
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
14 changes: 7 additions & 7 deletions sdcm/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,14 @@ def filter_k8s_clusters_by_tags(tags_dict: dict, clusters: list[
@lru_cache
def get_scylla_ami_versions(region_name: str, arch: AwsArchType = 'x86_64', version: str = None) -> list[EC2Image]:
Copy link
Contributor

Choose a reason for hiding this comment

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

it's used by get_latest_scylla_ami_release which is not used anywhere, maybe remove this function along so it's not distracting?

Copy link
Contributor

Choose a reason for hiding this comment

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

$ git grep get_scylla_ami_versions
sdcm/sct_config.py:    get_scylla_ami_versions,
sdcm/sct_config.py:                            ami = get_scylla_ami_versions(version=scylla_version, region_name=region, arch=aws_arch)[0]
sdcm/sct_config.py:                            ami = get_scylla_ami_versions(version=oracle_scylla_version,
sdcm/utils/common.py:def get_scylla_ami_versions(region_name: str, arch: AwsArchType = 'x86_64', version: str = None) -> list[EC2Image]:
sdcm/utils/common.py:    for ami in get_scylla_ami_versions(region_name=region):
sdcm/utils/common.py:            for ami in get_scylla_ami_versions(region_name=region_name, arch=arch, version=version)]
unit_tests/test_scylla_yaml_builders.py:            with patch("sdcm.sct_config.get_scylla_ami_versions", return_value=[self.get_scylla_ami_version_output]), \

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant get_latest_scylla_ami_release to be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not in use, but the removal of it isn't really have anything with this PR

"""Get the list of all the formal scylla ami from specific region."""
name_filter = "ScyllaDB *"
scylla_version_filter = "*"

if version and version != "all":
name_filter = f"ScyllaDB *{version.replace('enterprise-', 'Enterprise ')}"
scylla_version_filter = f"*{version.replace('enterprise-', '')}-*"

if len(version.split('.')) < 3:
# if version is not exact version, we need to add the wildcard to the end, to catch all minor versions
name_filter = f"{name_filter}*"
scylla_version_filter = f"*{version.replace('enterprise-', '')}*"

ec2_resource: EC2ServiceResource = boto3.resource('ec2', region_name=region_name)
images = []
Expand All @@ -1148,8 +1148,9 @@ def get_scylla_ami_versions(region_name: str, arch: AwsArchType = 'x86_64', vers
images += client.images.filter(
Owners=[owner],
Filters=[
{'Name': 'name', 'Values': [name_filter]},
{"Name": "tag:scylla_version", "Values": [scylla_version_filter, ], },
{'Name': 'architecture', 'Values': [arch]},
{'Name': 'tag:environment', 'Values': ['production']},
],
)
images = sorted(images, key=lambda x: x.creation_date, reverse=True)
Expand All @@ -1166,10 +1167,9 @@ def get_scylla_gce_images_versions(project: str = SCYLLA_GCE_IMAGES_PROJECT, ver
# RE2 syntax: https://github.com/google/re2/blob/master/doc/syntax.txt
# or you can see brief explanation here:
# https://github.com/apache/libcloud/blob/trunk/libcloud/compute/drivers/gce.py#L274
filters = "(family eq 'scylla(-enterprise)?')(name ne .+-build-.+)"

filters = "(family eq 'scylla(-enterprise)?')( labels.environment eq 'production' )"
if version and version != "all":
filters += f"(name eq 'scylla(db)?(-enterprise)?-{version.replace('.', '-')}"
filters += f"(labels.scylla_version eq '{version.replace('.', '-')}.*"
if 'rc' not in version and len(version.split('.')) < 3:
filters += "(-\\d)?(\\d)?(\\d)?(-rc)?(\\d)?(\\d)?')"
else:
Expand Down
Loading