-
Notifications
You must be signed in to change notification settings - Fork 52
ART-23298: fix(go:report): handle floating golang builder tags in streams.yml #3357
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,90 @@ | |
| from artcommonlib.format_util import green_print | ||
| from artcommonlib.release_util import split_el_suffix_in_release | ||
| from artcommonlib.rpm_utils import parse_nvr | ||
| from artcommonlib.util import oc_image_info_for_arch | ||
|
|
||
| from elliottlib.cli.common import cli | ||
| from elliottlib.runtime import Runtime | ||
| from elliottlib.util import get_golang_container_nvrs | ||
|
|
||
| _LOGGER = logutil.get_logger(__name__) | ||
|
|
||
| # Matches floating golang-builder tags such as: | ||
| # golang-builder-v1.22-rhel9 | ||
| # openshift-golang-builder-container-v1.22-rhel8 | ||
| # These lack the X.Y.Z patch version present in full NVR tags. | ||
| # Example matching string: "golang-builder-v1.22-rhel9" | ||
| _FLOATING_TAG_RE = re.compile(r'v(\d+\.\d+)-rhel(\d+)$') | ||
|
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. can you add an example of string matching the regex for reference? |
||
|
|
||
|
|
||
| def is_floating_golang_builder_tag(nvr_like: str) -> bool: | ||
|
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. can you improve the docstring by providing an example |
||
| """Return True when *nvr_like* is a floating tag (vX.Y-rhelN) rather than a full NVR string. | ||
|
|
||
| Example:: | ||
|
|
||
| is_floating_golang_builder_tag("openshift-golang-builder-container-v1.22-rhel9") # True | ||
| is_floating_golang_builder_tag("openshift-golang-builder-container-v1.22.5-202506011200.el9") # False | ||
| """ | ||
| return bool(_FLOATING_TAG_RE.search(nvr_like)) | ||
|
|
||
|
|
||
| def go_version_from_floating_tag(nvr_like: str, ignore_rhel: bool) -> str: | ||
| """Extract a go-version string from a floating tag like | ||
| ``openshift-golang-builder-container-v1.22-rhel9``. | ||
|
|
||
| Returns ``X.Y.elN`` normally, or just ``X.Y`` when *ignore_rhel* is True. | ||
| """ | ||
| m = _FLOATING_TAG_RE.search(nvr_like) | ||
| if not m: | ||
| raise ValueError(f"Not a floating golang-builder tag: {nvr_like!r}") | ||
| major_minor = m.group(1) | ||
| rhel_version = m.group(2) | ||
| if ignore_rhel: | ||
| return major_minor | ||
| return f"{major_minor}.el{rhel_version}" | ||
|
|
||
|
|
||
| def go_version_from_floating_tag_exact(image_pullspec: str) -> str: | ||
|
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. The PR reads the builder image’s own NVR labels:
Those identify the container build, not necessarily the exact golang RPM being reported. It then queries Brew/Konflux to derive the RPM NVR. However, builder images already carry the exact RPM NVR in: so we should read that label directly and return it. The database lookup should only be a fallback for older images without the label. This is both simpler and avoids an unnecessary external lookup. |
||
| """Resolve a floating-tag pullspec to the exact golang package NVR. | ||
|
|
||
| Calls ``oc image info`` to read the OCI labels from the resolved image. | ||
| First checks for the ``io.openshift.build.golang-nvr`` label (e.g. | ||
| ``golang-1.22.5-1.el9``), which is the direct golang RPM NVR and avoids a | ||
| database lookup. Falls back to reading the builder image NVR from | ||
| ``com.redhat.component`` / ``version`` / ``release`` labels and querying | ||
| Brew/Konflux via ``get_golang_container_nvrs`` for older images that do not | ||
| carry the ``io.openshift.build.golang-nvr`` label. | ||
| """ | ||
| _LOGGER.info(f"Resolving floating tag via oc image info: {image_pullspec}") | ||
| image_data = oc_image_info_for_arch(image_pullspec) | ||
| labels = image_data.get('config', {}).get('config', {}).get('Labels', {}) | ||
|
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. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Handle null
Use 🤖 Prompt for AI Agents |
||
|
|
||
| # Prefer the direct golang RPM NVR label — present on all modern builder images. | ||
| golang_nvr = labels.get('io.openshift.build.golang-nvr') | ||
| if golang_nvr: | ||
| _LOGGER.info(f"Found golang NVR directly in image label: {golang_nvr}") | ||
| return golang_nvr | ||
|
|
||
| # Fallback for older images without the label: derive NVR via DB lookup. | ||
| component = labels.get('com.redhat.component') | ||
| version = labels.get('version') | ||
| release = labels.get('release') | ||
| if not all([component, version, release]): | ||
| raise ValueError( | ||
| f"Cannot determine NVR from image labels for {image_pullspec}: " | ||
| f"component={component!r} version={version!r} release={release!r}" | ||
| ) | ||
| _LOGGER.info(f"Resolved floating tag to builder NVR: {component}-{version}-{release}") | ||
| go_builder_nvr_map = get_golang_container_nvrs([(component, version, release)], _LOGGER, exact=True) | ||
| if not go_builder_nvr_map: | ||
| raise ValueError(f"Could not determine golang package NVR for builder {component}-{version}-{release}") | ||
| if len(go_builder_nvr_map) != 1: | ||
| raise ValueError( | ||
| f"Expected exactly one golang version for builder {component}-{version}-{release}, " | ||
| f"got {list(go_builder_nvr_map.keys())}" | ||
| ) | ||
| return list(go_builder_nvr_map.keys())[0] | ||
|
|
||
|
|
||
| @cli.command("go:report", short_help="Report about golang streams configured in streams.yml") | ||
| @click.option('--ocp-versions', help="OCP versions to show report for. e.g. `4.14`. Comma separated") | ||
|
|
@@ -26,7 +103,7 @@ def get_golang_report_cli(runtime: Runtime, ocp_versions: str, ignore_rhel: bool | |
|
|
||
| Usage: | ||
|
|
||
| $ elliott go:report --versions 4.11,4.12,4.13,4.14,4.15,4.16 | ||
| $ elliott go:report --ocp-versions 4.11,4.12,4.13,4.14,4.15,4.16 | ||
|
|
||
| """ | ||
| results = {} | ||
|
|
@@ -93,11 +170,24 @@ def golang_report_for_version(runtime, ocp_version: str, ignore_rhel: bool = Fal | |
|
|
||
| _LOGGER.info(f"Detected stream {stream_name} with builder nvr: {nvr}") | ||
|
|
||
| if exact: | ||
| if is_floating_golang_builder_tag(nvr): | ||
| # Floating tag (e.g. openshift-golang-builder-container-v1.22-rhel9): no full NVR available. | ||
| # Non-exact mode: extract major.minor + RHEL suffix from the tag string directly. | ||
| # Exact mode: resolve to actual image via oc image info to obtain the real golang package NVR. | ||
| _LOGGER.info(f"Stream {stream_name} uses a floating tag; extracting version from tag") | ||
| if exact: | ||
| version = go_version_from_floating_tag_exact(image_nvr_like) | ||
| else: | ||
| version = go_version_from_floating_tag(nvr, ignore_rhel) | ||
| elif exact: | ||
| parsed_nvr = parse_nvr(nvr) | ||
| go_builder_nvr_map = get_golang_container_nvrs( | ||
| [(parsed_nvr['name'], parsed_nvr['version'], parsed_nvr['release'])], _LOGGER, exact=exact | ||
| ) | ||
| if len(go_builder_nvr_map) != 1: | ||
| raise ValueError( | ||
| f"Expected exactly one golang version for builder {nvr}, got {list(go_builder_nvr_map.keys())}" | ||
| ) | ||
| exact_pkg = list(go_builder_nvr_map.keys())[0] | ||
| version = exact_pkg | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.