Skip to content

Fix ListImages JSON parsing when extension binaries emit log lines#31009

Open
stbenjam wants to merge 3 commits intoopenshift:mainfrom
stbenjam:fix-list-images-json-parsing
Open

Fix ListImages JSON parsing when extension binaries emit log lines#31009
stbenjam wants to merge 3 commits intoopenshift:mainfrom
stbenjam:fix-list-images-json-parsing

Conversation

@stbenjam
Copy link
Copy Markdown
Member

@stbenjam stbenjam commented Apr 14, 2026

Summary

  • ListImages was directly unmarshalling the entire stdout from extension binaries, so any warning/debug log lines before the JSON payload caused parse failures (invalid character 'W' looking for beginning of value).
  • Extracted a shared extractJSON helper used by both Info and ListImages, eliminating duplicated JSON detection logic.
  • The helper also handles binaries that output null (no images to report), which previously caused an unhelpful parse error.

Test plan

  • Ran openshift-tests images --to-repository=repo/localimages/asdf with a local extension binary override that emits warning lines before JSON output — previously failed, now succeeds.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • More robust JSON extraction from binary outputs, improved error messages when parsing fails, and correct handling of "null" or empty image results.
  • Refactor

    • Consolidated JSON extraction logic used across binary extension workflows to simplify and standardize parsing behavior.
  • Tests

    • Added comprehensive tests covering JSON extraction (objects, arrays, leading/trailing noise, and error cases).

… lines

ListImages was unmarshalling the entire stdout output directly, so any
warning or debug log lines emitted by extension binaries before the JSON
payload caused parsing failures (e.g. "invalid character 'W' looking for
beginning of value"). The Info method already handled this by scanning
for the first JSON-starting line, but ListImages did not.

Extract a shared extractJSON helper that both Info and ListImages now
use, eliminating the duplicated JSON detection logic. The helper also
handles the case where a binary outputs "null" (no images), which
previously fell through to an unhelpful parse error.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 900fdae1-a9d8-4227-97a6-b457a7eae974

📥 Commits

Reviewing files that changed from the base of the PR and between 5cb9f3e and 019f184.

📒 Files selected for processing (2)
  • pkg/test/extensions/binary.go
  • pkg/test/extensions/extract_json_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/test/extensions/extract_json_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/test/extensions/binary.go

Walkthrough

Added an extractJSON helper that scans program output to locate and decode the first JSON value (object or array). Info and ListImages in pkg/test/extensions/binary.go were refactored to use this helper; ListImages also improves error logging and treats null outputs as empty image sets.

Changes

Cohort / File(s) Summary
Binary JSON handling
pkg/test/extensions/binary.go
Added extractJSON(output []byte) ([]byte, error) and refactored (*TestBinary).Info and (*TestBinary).ListImages to use it. Updated ListImages error messaging (from listimages), log JSON payload on unmarshal failures, and treat outputs containing "null" as no images (return empty ImageSet).
Tests for extractor
pkg/test/extensions/extract_json_test.go
Added tests covering successful extraction of object/array JSON, ignoring leading non-JSON lines, ignoring trailing junk, and error cases (no JSON, empty input, null content).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Stable And Deterministic Test Names ❓ Inconclusive Test files mentioned in PR summary do not exist in repository; PR describes standard Go testing patterns, not Ginkgo tests. Verify that PR files are available and clarify whether repository uses Ginkgo framework for testing.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing JSON parsing in ListImages when extension binaries emit log lines before JSON output.
Test Structure And Quality ✅ Passed PR contains standard Go tests using testing.T and table-driven tests, not Ginkgo tests, so the Ginkgo-specific quality check is not applicable.
Microshift Test Compatibility ✅ Passed PR adds only a standard Go unit test for JSON extraction utility, not Ginkgo e2e tests using unsupported MicroShift APIs.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds only unit tests using Go's testing package and testify/assert, with no Ginkgo e2e test patterns detected.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies test utility code in pkg/test/extensions/binary.go and adds extract_json_test.go. Changes are purely test infrastructure with no impact on deployment manifests, operator code, controllers, or cluster scheduling constraints.
Ote Binary Stdout Contract ✅ Passed The PR does not introduce new stdout writes in process-level code and improves stdout contract compliance through proper JSON extraction.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The pull request does not introduce new Ginkgo e2e tests. The added extract_json_test.go contains standard Go unit tests using testing.T, not Ginkgo patterns, and binary.go modifications are utility function refactorings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 14, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: stbenjam

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

The pull request process is described 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 14, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/test/extensions/binary.go`:
- Around line 354-356: The helper extractJSON currently returns JSON "null" to
all callers which lets callers like Info unmarshal into zero-value Extension
silently; change extractJSON to either accept an allowNull bool parameter or
create a separate extractNullableJSON so that extractJSON fails when trimmed ==
[]byte("null") unless the caller explicitly allows null; update callers
(including Info and the other callers referenced around the same spots) to pass
true only where null is acceptable and false (or call the non-nullable helper)
where it should be treated as an error.
- Around line 359-365: The current end detection using LastIndexByte on output
is brittle (variables: jsonBegins, jsonEnds, endChar, output); replace the
manual end-boundary logic by feeding output[jsonBegins:] into a json.Decoder and
decode into a json.RawMessage (or interface{}) so the decoder extracts exactly
the first JSON value and returns its raw bytes, rather than relying on
LastIndexByte which can be thrown off by trailing logs; update the return to use
the decoded RawMessage result instead of slicing by jsonEnds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a352c1f-4639-4ef9-b0e6-88ce63de0946

📥 Commits

Reviewing files that changed from the base of the PR and between 9df27cd and 5cb9f3e.

📒 Files selected for processing (1)
  • pkg/test/extensions/binary.go

stbenjam and others added 2 commits April 14, 2026 09:16
…tImages

- Replace brittle LastIndexByte end-boundary detection with json.Decoder,
  which correctly extracts the first complete JSON value regardless of
  trailing log output.
- Remove allowNull parameter from extractJSON; handle the null case in
  ListImages where it's semantically relevant, keeping the helper simple.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Drop the startChar parameter — the helper now finds the first line
starting with '{' or '[' automatically. Use json.Decoder to extract
the complete JSON value, which correctly handles trailing log lines
that might contain braces. Keep null handling in ListImages where
it's semantically relevant.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@ropatil010
Copy link
Copy Markdown

/test e2e-agnostic-ipv6

@ropatil010
Copy link
Copy Markdown

/test e2e-metal-ipi-ovn-ipv6

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 14, 2026

@stbenjam: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-ovn 019f184 link true /test e2e-gcp-ovn
ci/prow/e2e-vsphere-ovn 019f184 link true /test e2e-vsphere-ovn
ci/prow/e2e-vsphere-ovn-upi 019f184 link true /test e2e-vsphere-ovn-upi
ci/prow/e2e-metal-ipi-ovn-ipv6 019f184 link true /test e2e-metal-ipi-ovn-ipv6
ci/prow/e2e-aws-ovn-fips 019f184 link true /test e2e-aws-ovn-fips

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants