Skip to content

ROSAENG-61040 | refactor: remove github.com/PuerkitoBio/goquery#3422

Open
markirish wants to merge 1 commit into
openshift:masterfrom
markirish:ROSAENG-61040-remove-goquery
Open

ROSAENG-61040 | refactor: remove github.com/PuerkitoBio/goquery#3422
markirish wants to merge 1 commit into
openshift:masterfrom
markirish:ROSAENG-61040-remove-goquery

Conversation

@markirish

@markirish markirish commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Replace goquery HTML DOM parsing with a ~50-line golang.org/x/net/html tokenizer for extracting version links from the OpenShift mirror page. Promote golang.org/x/net from indirect to direct dependency.

Detailed Description of the Issue

Our ROSA CLI project currently imports several third-party libraries that are only utilized in a single file (e.g., exclusively within a test file or for a single validation function). Relying on entire external dependencies for isolated use cases unnecessarily increases our security attack surface, complicates dependency management, and bloats the project.

This PR is part of that initiative to remove github.com/PuerkitoBio/goquery

Related Issues and PRs

Type of Change

  • feat - adds a new user-facing capability.
  • fix - resolves an incorrect behavior or bug.
  • docs - updates documentation only.
  • style - formatting or naming changes with no logic impact.
  • refactor - code restructuring with no behavior change.
  • test - adds or updates tests only.
  • chore - maintenance work (tooling, housekeeping, non-product code).
  • build - changes build system, packaging, or dependencies for build output.
  • ci - changes CI pipelines, jobs, or automation workflows.
  • perf - improves performance without changing intended behavior.

Previous Behavior

Query can parse the ROSA mirror page

Behavior After This Change

unchanged

How to Test (Step-by-Step)

Preconditions

Test Steps

  1. run make test

Expected Results

All tests pass

Proof of the Fix

  • Screenshots:
  • Videos:
  • Logs/CLI output:
  • Other artifacts:

Breaking Changes

  • No breaking changes
  • Yes, this PR introduces a breaking change (describe impact and migration plan below)

Breaking Change Details / Migration Plan

New query logic is more correct, as it will search <tr class="file"> elements instead of any HTML element with "file" class. The ROSA mirror page it searches has the files we are searching for under tr elements

Developer Verification Checklist

  • Commit subject/title follows [JIRA-TICKET] | [TYPE]: <MESSAGE>.
  • PR description clearly explains both what changed and why.
  • Relevant Jira/GitHub issues and related PRs are linked.
  • make install-hooks has been run in this clone.
  • Tests were added/updated where appropriate.
  • I manually tested the change.
  • make test passes.
  • make lint passes.
  • make rosa passes.
  • Documentation or repo-local agent guidance was added/updated where appropriate.
  • Any risk, limitation, or follow-up work is documented.

Summary by CodeRabbit

  • Bug Fixes

    • Improved version discovery from mirror directory listings.
    • Added support for table-based listings and more reliable extraction of available versions.
    • Improved error handling when mirror content cannot be parsed.
  • Tests

    • Expanded coverage for retrieving the latest available version, including newer release entries and cached results.

Replace goquery HTML DOM parsing with a ~50-line golang.org/x/net/html
tokenizer for extracting version links from the OpenShift mirror page.
Promote golang.org/x/net from indirect to direct dependency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Mirror version discovery now uses Go’s streaming HTML tokenizer instead of DOM parsing. It extracts version links from file rows, excludes the latest link, trims directory suffixes, and propagates parsing errors. The module requirements remove the former HTML parsing dependencies and make golang.org/x/net direct. Tests update the mirror fixture and expected latest version to 4.0.0.

Suggested reviewers: olucasfreitas

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and clearly states the main change: removing goquery from the ROSAENG-61040 refactor.
Description check ✅ Passed The description matches the template and includes the required sections, issue link, testing notes, and change summary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All Ginkgo titles in pkg/version/retriever_test.go are static descriptive strings; none include dynamic or generated values.
Test Structure And Quality ✅ Passed PASS: The updated Ginkgo tests are unit-only, use BeforeEach/AfterEach cleanup, keep one behavior per It, and add no cluster waits or resource lifecycles.
Microshift Test Compatibility ✅ Passed PASS: The added Ginkgo tests are unit tests for version parsing/cache logic and don’t reference any MicroShift-unsafe OpenShift APIs, namespaces, or assumptions.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new e2e/SNO-sensitive tests were added; only pkg/version unit tests were updated, and they don't interact with cluster topology.
Topology-Aware Scheduling Compatibility ✅ Passed PR only changes version parsing/tests and dependency metadata; no deployment manifests, controllers, or scheduling constraints were modified.
Ote Binary Stdout Contract ✅ Passed Changed files add only parser helpers and Ginkgo tests; no main/init/TestMain/BeforeSuite code or stdout print calls were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new e2e tests were added; the Ginkgo specs are unit tests with mocked HTTP/cache and no IPv4 assumptions or external connectivity.
No-Weak-Crypto ✅ Passed Diff only swaps HTML parsing deps; retriever.go adds x/net/html tokenizer and no weak crypto, custom crypto, or secret comparisons appear.
Container-Privileges ✅ Passed PR only changes Go deps and version-parsing code; no container/K8s manifests were modified, and no privileged settings appear in the changed files.
No-Sensitive-Data-In-Logs ✅ Passed No new logs expose secrets or PII; added messages only mention public mirror URLs and version strings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from davidleerh and dustman9000 July 24, 2026 20:45
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: markirish
Once this PR has been reviewed and has the lgtm label, please assign davidleerh 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
pkg/version/retriever_test.go (1)

20-30: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the new row and latest filters.

This fixture cannot detect accepting links outside tr.file or retaining latest. Add a non-file high version and a tr.file latest/ link, then assert the parsed slice excludes both.

As per coding guidelines, “Add focused automated tests when behavior changes could regress; tests should prove correctness.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/version/retriever_test.go` around lines 20 - 30, Add focused fixture
coverage around the version-parsing test using expectedVersions and htmlContent:
include a high-version link outside tr.file and a latest/ link inside tr.file,
then assert the parsed versions exclude both while preserving the existing valid
versions.

Sources: Coding guidelines, Path instructions

pkg/version/retriever.go (1)

105-107: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid shadowing err on the cache write.

Line 105 shadows the parser error variable. Use a distinct cacheErr to keep error paths unambiguous.

Proposed fix
-if err := r.cache.Set(cache.VersionCacheKey, possibleVersions); err != nil {
-	r.logger.Debugf("Failed to set possible versions in cache : %v", err)
+if cacheErr := r.cache.Set(cache.VersionCacheKey, possibleVersions); cacheErr != nil {
+	r.logger.Debugf("Failed to set possible versions in cache : %v", cacheErr)
}

As per coding guidelines, “Avoid variable shadowing, especially err.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/version/retriever.go` around lines 105 - 107, Update the cache write
error handling in the version retrieval flow to avoid shadowing the existing
parser error variable: bind the result of r.cache.Set to a distinct cacheErr
name and use that variable in the logger.Debugf call, preserving the current
behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/version/retriever_test.go`:
- Around line 20-30: Add focused fixture coverage around the version-parsing
test using expectedVersions and htmlContent: include a high-version link outside
tr.file and a latest/ link inside tr.file, then assert the parsed versions
exclude both while preserving the existing valid versions.

In `@pkg/version/retriever.go`:
- Around line 105-107: Update the cache write error handling in the version
retrieval flow to avoid shadowing the existing parser error variable: bind the
result of r.cache.Set to a distinct cacheErr name and use that variable in the
logger.Debugf call, preserving the current behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 8cb133ed-1182-48e2-bb4a-7e8375210c7d

📥 Commits

Reviewing files that changed from the base of the PR and between 8eff35d and a00bcfa.

⛔ Files ignored due to path filters (25)
  • go.sum is excluded by !**/*.sum
  • vendor/github.com/PuerkitoBio/goquery/.gitattributes is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/.gitignore is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/LICENSE is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/README.md is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/array.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/doc.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/expand.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/filter.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/iteration.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/manipulation.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/property.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/query.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/traversal.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/type.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/PuerkitoBio/goquery/utilities.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/.travis.yml is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/LICENSE is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/README.md is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/parser.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/pseudo_classes.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/selector.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/serialize.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/andybalholm/cascadia/specificity.go is excluded by !vendor/**, !**/vendor/**
  • vendor/modules.txt is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (3)
  • go.mod
  • pkg/version/retriever.go
  • pkg/version/retriever_test.go

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 25, 2026
@openshift-ci

openshift-ci Bot commented Jul 25, 2026

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.

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

Labels

dco-signoff: yes needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant