Skip to content

feat(prow): auto-inject metadata labels to kubevirt prowjobs#4841

Draft
Aneesh-Hegde wants to merge 1 commit into
kubevirt:mainfrom
Aneesh-Hegde:add-labels-prow
Draft

feat(prow): auto-inject metadata labels to kubevirt prowjobs#4841
Aneesh-Hegde wants to merge 1 commit into
kubevirt:mainfrom
Aneesh-Hegde:add-labels-prow

Conversation

@Aneesh-Hegde
Copy link
Copy Markdown

What this PR does / why we need it:
Injects explicit metadata labels (ci.kubevirt.io/k8s-version, ci.kubevirt.io/sig, and ci.kubevirt.io/category) into KubeVirt ProwJobs. This allows the prow-exporter to scrape these dimensions, enabling Grafana admins to filter metrics using clean Prometheus label queries instead of relying on fragile regex matching against the job_name.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #4733

Special notes for your reviewer:
To avoid human error and preserve existing YAML formatting/comments, I used an automated ruamel.yaml Python script to parse the name strings and inject the labels across the jobs/kubevirt/kubevirt/ directory.

Questions for Maintainers:
I currently extracted Version, SIG, and Category based on the issue description. Looking at the job names, I could also extract architecture (arm64/s390x) and provider/hardware (kind/vgpu/sriov). Would you like those added to this PR, or should we keep the scope narrow for now?

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

NONE

Signed-off-by: Aneesh Hegde <aneeshhegde7110@gmail.com>
@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Mar 18, 2026
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Sorry @Aneesh-Hegde, your pull request is larger than the review limit of 150000 diff characters

@kubevirt-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign vasiliy-ul for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot
Copy link
Copy Markdown
Contributor

Hi @Aneesh-Hegde. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Aneesh-Hegde
Copy link
Copy Markdown
Author

/cc @dhiller

@kubevirt-bot kubevirt-bot requested a review from dhiller March 18, 2026 20:26
@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 20, 2026
@kubevirt-bot
Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Aneesh-Hegde
Copy link
Copy Markdown
Author

Hey @dhiller ! Since this PR modifies over 2,000 lines, I want to make reviewing it as painless as possible.

I did not hand edit these files. To prevent human error and perfectly preserve your existing YAML formatting and comments, I wrote a Python script using the ruamel.yaml library (which preserves AST).

Instead of reading the massive diff, you only need to review the regex logic in this script.

Click here to view the exact Python script used
Details
import os
import re
from ruamel.yaml import YAML

def process_yaml(filepath):
    yaml = YAML()
    yaml.allow_duplicate_keys = True
    yaml.preserve_quotes = True
    yaml.indent(mapping=2, sequence=2, offset=0)
    yaml.width = 4096 

    try:
        with open(filepath, 'r') as f:
            data = yaml.load(f)
    except Exception as e:
        return

    if not data or not isinstance(data, dict):
        return

    modified = False
    job_types = ['presubmits', 'postsubmits', 'periodics']
    
    for j_type in job_types:
        if j_type in data and isinstance(data[j_type], dict):
            for repo, jobs in data[j_type].items():
                if not jobs or not isinstance(jobs, list):
                    continue

                for job in jobs:
                    if not isinstance(job, dict) or 'name' not in job:
                        continue
                    
                    job_name = job['name']
                    new_labels = {}

                    # 1. Extract Version
                    k8s_match = re.search(r'(?:k8s|kind)-(\d+\.\d+)', job_name)
                    if k8s_match:
                        new_labels['ci.kubevirt.io/k8s-version'] = k8s_match.group(1)

                    # 2. Extract SIG
                    sig_match = re.search(r'sig-([a-zA-Z0-9]+)', job_name)
                    if sig_match:
                        new_labels['ci.kubevirt.io/sig'] = sig_match.group(1)

                    # 3. Extract Category
                    if '-e2e-' in job_name:
                        new_labels['ci.kubevirt.io/category'] = 'e2e'
                    elif '-unit-' in job_name:
                        new_labels['ci.kubevirt.io/category'] = 'unit'
                    elif '-build-' in job_name:
                        new_labels['ci.kubevirt.io/category'] = 'build'
                    elif '-lint' in job_name:
                        new_labels['ci.kubevirt.io/category'] = 'lint'

                    if new_labels:
                        if 'labels' not in job:
                            job['labels'] = {}
                        for key, val in new_labels.items():
                            if key not in job['labels']:
                                job['labels'][key] = val
                                modified = True

    if modified:
        with open(filepath, 'w') as f:
            yaml.dump(data, f)

def main():
    for filename in os.listdir('.'):
        if filename.endswith('.yaml'):
            process_yaml(filename)

if __name__ == '__main__':
    main()

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

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add labels to prowjobs to make better selections

2 participants