Skip to content

reconciler: fix correctImages panic when pod has no containers - #3904

Open
sebrandon1 wants to merge 1 commit into
operator-framework:masterfrom
sebrandon1:fix/correct-images-empty-containers
Open

reconciler: fix correctImages panic when pod has no containers#3904
sebrandon1 wants to merge 1 commit into
operator-framework:masterfrom
sebrandon1:fix/correct-images-empty-containers

Conversation

@sebrandon1

@sebrandon1 sebrandon1 commented Aug 27, 2026

Copy link
Copy Markdown

Summary

  • correctImages accessed pod.Spec.Containers[0] without a length guard in the non-ExtractContent path, causing a panic for pods with an empty containers slice (e.g. evicted or malformed pods)
  • The ExtractContent path already had an equivalent len(pod.Spec.Containers) != 1 guard; this brings the fallback path in line
  • Adds TestCorrectImages covering both paths, including the empty-containers regression case and an ExtractContent serving-image mismatch case

Test plan

  • go test ./pkg/controller/registry/reconciler/... -run TestCorrectImages — all 6 cases pass

Summary by CodeRabbit

  • Bug Fixes

    • Prevented reconciliation errors when evaluating workloads with no regular containers.
    • Improved image validation across standard and content-extraction configurations.
  • Tests

    • Added coverage for empty-container scenarios, matching and mismatched images, container layouts, and invalid configurations.

pod.Spec.Containers[0] was accessed without a length guard in the
non-ExtractContent path of correctImages, causing a panic for any pod
with an empty containers slice (e.g. evicted or malformed pods). The
ExtractContent path already had an equivalent guard.

Add TestCorrectImages covering both paths including the empty-containers
case and the ExtractContent serving-image mismatch case.
@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 27, 2026
@openshift-ci

openshift-ci Bot commented Aug 27, 2026

Copy link
Copy Markdown

Hi @sebrandon1. Thanks for your PR.

I'm waiting for a operator-framework member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0167e697-d578-4a19-a699-eb54859334a7

📥 Commits

Reviewing files that changed from the base of the PR and between f8f3f72 and e47833c.

📒 Files selected for processing (2)
  • pkg/controller/registry/reconciler/grpc.go
  • pkg/controller/registry/reconciler/grpc_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The correctImages helper now avoids indexing an empty container list. New table-driven tests cover non-ExtractContent and ExtractContent catalog sources, image mismatches, empty containers, and invalid container layouts.

Changes

Image validation

Layer / File(s) Summary
Correct image guard and validation tests
pkg/controller/registry/reconciler/grpc.go, pkg/controller/registry/reconciler/grpc_test.go
correctImages returns false when a pod has no containers. Tests cover matching and mismatched images, ExtractContent container layouts, and incorrect init-container counts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to e4783

This change prevents a panic when a pod has no containers while preserving the existing behavior for normal pods. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: pdudley

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 describes the main change: fixing the correctImages panic when a pod has no containers.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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.

@tmshort

tmshort commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@openshift-ci openshift-ci Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 27, 2026
@tmshort

tmshort commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci

openshift-ci Bot commented Aug 27, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tmshort

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 Aug 27, 2026
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants