Skip to content

olm: return webhook cleanup delete failures instead of swallowing them - #3950

Open
sebrandon1 wants to merge 1 commit into
operator-framework:masterfrom
sebrandon1:CNF-29070-webhook-cleanup-error-handling
Open

sebrandon1 wants to merge 1 commit into
operator-framework:masterfrom
sebrandon1:CNF-29070-webhook-cleanup-error-handling

Conversation

@sebrandon1

@sebrandon1 sebrandon1 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description of the change:

cleanUpRemovedWebhooks guarded both webhook delete loops with an inverted error check:

err = ...ValidatingWebhookConfigurations().Delete(...)
if err != nil && apierrors.IsNotFound(err) {
    return err
}

This is the opposite of the convention used everywhere else in the tree (if err != nil && !apierrors.IsNotFound(err)). Negate the condition in both loops (validating and mutating) so that:

  • a genuine delete failure (Forbidden, Conflict, apiserver 5xx) is returned rather than silently discarded, and
  • a NotFound delete — the normal benign race where the object is already gone — is treated as success.

Adds TestCleanUpRemovedWebhooks in a new pkg/controller/operators/olm/apiservices_test.go, covering stale validating and mutating config deletion, retention of configs still referenced by the CSV, Forbidden delete failures returning an error with the object left in place, and NotFound being treated as success.

Motivation for the change:

With the inverted check, a failed delete of a ValidatingWebhookConfiguration / MutatingWebhookConfiguration owned by a CSV whose webhook definition was removed is swallowed. The stale config stays registered and keeps intercepting matching CREATE/UPDATE requests after its backing Service is gone — the cluster-wide "failed calling webhook" outage class. In the other direction, a benign NotFound was surfaced as a hard error, causing areWebhooksAvailable to fail and the CSV install to retry pointlessly.

Architectural changes:

None. Error-handling only; no signatures, APIs, or install logic change.

Testing remarks:

  • go test ./pkg/controller/operators/olm/ -run TestCleanUpRemovedWebhooks -count=1 — passes (6 subtests).
  • go test ./pkg/controller/operators/olm/... -count=1 — 334 tests pass.
  • Regression proof: with the pre-fix condition restored, 4 subtests fail (both swallowed-failure cases and both NotFound cases); the fix makes them pass.
  • go vet ./pkg/controller/operators/olm/ and gofmt are clean. Note make lint in this environment fails repo-wide on a golangci-lint/Go toolchain mismatch (export data version 5 is greater than maximum supported version 2) unrelated to this change.

Fixes: https://redhat.atlassian.net/browse/CNF-29070

/cc @sebrandon1

Summary by CodeRabbit

  • Bug Fixes

    • Cleanup now succeeds when obsolete webhook configurations have already been removed, avoiding errors in that case.
    • Other deletion failures continue to be reported, helping surface problems during cleanup.
  • Tests

    • Added coverage for removing obsolete configurations, retaining referenced ones, and handling deletion errors.

@openshift-ci

openshift-ci Bot commented Oct 28, 2026

Copy link
Copy Markdown

@sebrandon1: GitHub didn't allow me to request PR reviews from the following users: sebrandon1.

Note that only operator-framework members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

Description of the change:

cleanUpRemovedWebhooks guarded both webhook delete loops with an inverted error check:

err = ...ValidatingWebhookConfigurations().Delete(...)
if err != nil && apierrors.IsNotFound(err) {
   return err
}

This is the opposite of the convention used everywhere else in the tree (if err != nil && !apierrors.IsNotFound(err)). Negate the condition in both loops (validating and mutating) so that:

  • a genuine delete failure (Forbidden, Conflict, apiserver 5xx) is returned rather than silently discarded, and
  • a NotFound delete — the normal benign race where the object is already gone — is treated as success.

Adds TestCleanUpRemovedWebhooks in a new pkg/controller/operators/olm/apiservices_test.go, covering stale validating and mutating config deletion, retention of configs still referenced by the CSV, Forbidden delete failures returning an error with the object left in place, and NotFound being treated as success.

Motivation for the change:

With the inverted check, a failed delete of a ValidatingWebhookConfiguration / MutatingWebhookConfiguration owned by a CSV whose webhook definition was removed is swallowed. The stale config stays registered and keeps intercepting matching CREATE/UPDATE requests after its backing Service is gone — the cluster-wide "failed calling webhook" outage class. In the other direction, a benign NotFound was surfaced as a hard error, causing areWebhooksAvailable to fail and the CSV install to retry pointlessly.

Architectural changes:

None. Error-handling only; no signatures, APIs, or install logic change.

Testing remarks:

  • go test ./pkg/controller/operators/olm/ -run TestCleanUpRemovedWebhooks -count=1 — passes (6 subtests).
  • go test ./pkg/controller/operators/olm/... -count=1 — 334 tests pass.
  • Regression proof: with the pre-fix condition restored, 4 subtests fail (both swallowed-failure cases and both NotFound cases); the fix makes them pass.
  • go vet ./pkg/controller/operators/olm/ and gofmt are clean. Note make lint in this environment fails repo-wide on a golangci-lint/Go toolchain mismatch (export data version 5 is greater than maximum supported version 2) unrelated to this change.

Fixes: https://redhat.atlassian.net/browse/CNF-29070

/cc @sebrandon1

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.

@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 32bd2df and 932967e.

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 cleanup now ignores NotFound errors when deleting obsolete validating and mutating webhook configurations. It returns other deletion errors. Added tests cover cleanup outcomes and remaining configurations.

Changes: Webhook Cleanup

Layer / File(s) Summary
Cleanup behavior and validation
pkg/controller/operators/olm/apiservices.go, pkg/controller/operators/olm/apiservices_test.go
Cleanup ignores NotFound deletion errors and returns other deletion errors. Tests cover stale and referenced configurations, forbidden and NotFound errors, and the resulting configuration lists.

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

Change: Bug fix

Suggested reviewers: timflannagan

Merge Risk: Minimal · previous review 9f187

No merge-blocking issue is established in the webhook cleanup change.

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 describes the main change: webhook cleanup now returns genuine delete failures instead of ignoring them.
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 2 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: ad625a0e-1eea-4ea9-b0f9-85836cf13c17
Commits

Reviewing files that changed from the base of the PR and between e046b5c and 9f187fd.

Files selected for processing: 2

  • pkg/controller/operators/olm/apiservices.go
  • pkg/controller/operators/olm/apiservices_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.

@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

@tmshort

tmshort commented Dec 1, 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 Dec 1, 2026
@tmshort

tmshort commented Dec 1, 2026

Copy link
Copy Markdown
Member

I seem to be unable to re-run release. So I'm closing/re-opening.

@tmshort tmshort closed this Dec 1, 2026
@tmshort tmshort reopened this Dec 1, 2026
@sebrandon1
sebrandon1 force-pushed the CNF-29070-webhook-cleanup-error-handling branch from fc4bc4c to 32bd2df Compare December 2, 2026 21:21
cleanUpRemovedWebhooks treated a Delete error as fatal only when it was
a NotFound, which is backwards from the rest of the tree:

  if err != nil && apierrors.IsNotFound(err) { return err }

As a result a real delete failure (Forbidden, Conflict, apiserver 5xx)
was silently discarded, leaving a stale ValidatingWebhookConfiguration
or MutatingWebhookConfiguration owned by a CSV whose webhook definition
had been removed. Such a leftover config keeps intercepting matching
CREATE/UPDATE requests after its backing Service is gone, which is the
cluster-wide "failed calling webhook" outage class. Conversely a benign
NotFound (object already deleted) was surfaced as a hard error and made
areWebhooksAvailable retry the CSV install pointlessly.

Negate the condition in both loops so genuine failures propagate and
NotFound is treated as success.

Add TestCleanUpRemovedWebhooks covering stale-config deletion, retention
of configs still referenced by the CSV, Forbidden delete failures, and
NotFound deletes.

Signed-off-by: Brandon Palm <bpalm@redhat.com>
@sebrandon1
sebrandon1 force-pushed the CNF-29070-webhook-cleanup-error-handling branch from 32bd2df to 932967e Compare December 4, 2026 14:16
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