Skip to content

olm: guard empty webhooks slice in getWebhookCABundle - #3951

Open
sebrandon1 wants to merge 1 commit into
operator-framework:masterfrom
sebrandon1:CNF-29071-guard-empty-webhook-cabundle
Open

sebrandon1 wants to merge 1 commit into
operator-framework:masterfrom
sebrandon1:CNF-29071-guard-empty-webhook-cabundle

Conversation

@sebrandon1

@sebrandon1 sebrandon1 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description of the change:

getWebhookCABundle guards only the outer slice before indexing the inner one:

if len(existingWebhooks.Items) > 0 {
    return existingWebhooks.Items[0].Webhooks[0].ClientConfig.CABundle, nil
}

Both the mutating and validating arms now also require len(existingWebhooks.Items[0].Webhooks) > 0. When the matching webhook configuration carries no webhooks, the function falls through to its existing unable to find CA error instead of panicking, and the caller wraps it as could not retrieve caBundle for WebhookDescription <name> — the same result as a missing configuration.

Motivation for the change:

A ValidatingWebhookConfiguration or MutatingWebhookConfiguration that still matches OLM's owner and olm.webhook-description-generate-name labels but has an empty Webhooks slice — hand-edited, partially applied, or left behind by an older OLM version — panics the OLM operator via updateDeploymentSpecsWithAPIServiceData → getWebhookCABundle on the CSV reconcile path. The result is a crashloop, so a single stale object takes down CSV management cluster-wide.

Architectural changes:

None. The two duplicated switch arms are left as they are; folding them behind a shared helper would be a refactor this maintenance-mode change does not need.

Testing remarks:

Three cases added to the existing TestWebhookCABundleRetrieval table in pkg/controller/operators/olm/operator_test.go:

  • FailFromValidatingAdmissionWebhookWithNoWebhooks
  • FailFromMutatingAdmissionWebhookWithNoWebhooks
  • MissingMutatingCAResource (the mutating arm previously had no missing-configuration case; only the validating arm did)

With the guard reverted, FailFromValidatingAdmissionWebhookWithNoWebhooks reproduces the defect: panic: runtime error: index out of range [0] with length 0. With the guard it returns unable to find CA. go test ./pkg/controller/operators/olm/ -race -count=1 passes (275 tests); gofmt and go vet clean. make lint cannot run in my environment due to a pre-existing toolchain export-data version mismatch unrelated to this diff.

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Bug fixes are accompanied by regression test(s)
  • e2e tests and flake fixes are accompanied evidence of flake testing, e.g. executing the test 100(0) times
  • tech debt/todo is accompanied by issue link(s) in comments in the surrounding code
  • Tests are comprehensible, e.g. Ginkgo DSL is being used appropriately
  • Docs updated or added to /doc
  • Commit messages sensible and descriptive
  • Tests marked as [FLAKE] are truly flaky and have an issue
  • Code is properly formatted

Summary by CodeRabbit

  • Bug Fixes
    • Corrected webhook CA bundle handling when a matching configuration has no webhooks or no CA resource. These cases now return the existing missing-CA error instead of attempting to access an empty webhook list.

@openshift-ci
openshift-ci Bot requested review from dtfranz and tmshort October 28, 2026 17:37
@openshift-ci

openshift-ci Bot commented Oct 28, 2026

Copy link
Copy Markdown

[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 tmshort 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

@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 Oct 28, 2026
@openshift-ci

openshift-ci Bot commented Oct 28, 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 Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between be30461 and 9597f08.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Webhook CA bundle retrieval now checks that the matching configuration contains a webhook before reading its CA bundle. Tests cover missing configurations and empty webhook lists.

Changes: Webhook CA bundle lookup

Layer / File(s) Summary
Guard webhook CA bundle access
pkg/controller/operators/olm/apiservices.go, pkg/controller/operators/olm/operator_test.go
The mutating and validating lookups check for a non-empty webhook list before accessing the first webhook’s CA bundle. Tests verify that missing configurations and empty lists return a nil bundle and missingCAError.

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

Change: Bug fix

Suggested reviewers: tmshort

Merge Risk: Minimal · previous review 6ea7b

The empty-webhook panic is prevented for both validating and mutating configurations, with focused test coverage.

Pre-merge checks: Passed 4 · Failed 1

Failed 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 with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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: preventing an empty webhooks slice from being indexed in getWebhookCABundle.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches

🧪 Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: d2f0f60e-42f7-477e-9b15-5fcc639a3fac
Commits

Reviewing files that changed from the base of the PR and between e046b5c and 6ea7b8e.

Files selected for processing: 2

  • pkg/controller/operators/olm/apiservices.go
  • pkg/controller/operators/olm/operator_test.go

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@tmshort

tmshort commented Nov 23, 2026

Copy link
Copy Markdown
Member

/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 Nov 23, 2026
@sebrandon1
sebrandon1 force-pushed the CNF-29071-guard-empty-webhook-cabundle branch from 6ea7b8e to be30461 Compare December 2, 2026 21:21
getWebhookCABundle indexes existingWebhooks.Items[0].Webhooks[0] after
checking only that Items is non-empty. A webhook configuration that
matches the OLM owner and generate-name labels but carries no webhooks
(hand-edited, partially applied, or left behind by an older OLM version)
panics the OLM operator on the CSV reconcile path, turning a single stale
object into a crashloop.

Require a non-empty Webhooks slice before indexing so the function falls
through to its existing "unable to find CA" error, matching the behavior
for a missing configuration.

Signed-off-by: Brandon Palm <bpalm@redhat.com>
@sebrandon1
sebrandon1 force-pushed the CNF-29071-guard-empty-webhook-cabundle branch from be30461 to 9597f08 Compare December 4, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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