Skip to content

OCPBUGS-82192: fix(webhookcerts): handle upgrade from service-ca managed certs - #8189

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
enxebre:webhook-certs-upgrade-fix
Apr 9, 2026
Merged

OCPBUGS-82192: fix(webhookcerts): handle upgrade from service-ca managed certs#8189
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
enxebre:webhook-certs-upgrade-fix

Conversation

@enxebre

@enxebre enxebre commented Apr 8, 2026

Copy link
Copy Markdown
Member

Summary

  • On existing OpenShift clusters upgrading to self-managed webhook certs (CNTRLPLANE-2207: feat(install): self-manage webhook certs instead of relying on service-ca #8174), the service-ca operator may still have its annotations on the operator Service and the serving cert secret it created. This causes a CA mismatch: webhook configs contain the self-managed CA bundle but the serving cert is signed by service-ca's CA, resulting in x509: certificate signed by unknown authority.
  • Adds removeServiceCAResources() to WebhookCertReconciler following the same pattern as removeServiceCAAnnotationAndSecret in the CPO. It removes service-ca annotations from the Service and deletes the serving cert secret if it was created by service-ca, so the reconciler recreates it signed by the self-managed CA.
  • Adds 3 unit tests covering the upgrade scenarios.

Test plan

  • Unit tests pass (go test ./hypershift-operator/controllers/webhookcerts/...)
  • make verify passes
  • Verify on an existing OpenShift cluster that previously used service-ca for webhook certs

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Webhook certificate reconciliation now properly detects and removes legacy certificate configurations, ensuring clean state transitions during upgrades.

Tests

  • Added comprehensive test coverage for webhook certificate upgrade scenarios, verifying proper handling of certificate migrations and state cleanup.

On existing OpenShift clusters upgrading to self-managed webhook certs,
the service-ca operator may still have its annotations on the operator
Service and may have created the serving cert secret. This causes a CA
mismatch: the webhook configs contain the self-managed CA bundle but
the serving cert is signed by service-ca's CA, resulting in
"x509: certificate signed by unknown authority" errors.

Add removeServiceCAResources() to the WebhookCertReconciler following
the same pattern as removeServiceCAAnnotationAndSecret in the CPO.
It removes the service-ca annotations from the Service and deletes the
serving cert secret if it was created by service-ca, allowing the
reconciler to recreate it signed by the self-managed CA.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@openshift-ci-robot

Copy link
Copy Markdown

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: LGTM mode

@enxebre enxebre changed the title fix(webhookcerts): handle upgrade from service-ca managed certs CNTRLPLANE-2207: fix(webhookcerts): handle upgrade from service-ca managed certs Apr 8, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 8, 2026
@openshift-ci-robot

openshift-ci-robot commented Apr 8, 2026

Copy link
Copy Markdown

@enxebre: This pull request references CNTRLPLANE-2207 which is a valid jira issue.

Details

In response to this:

Summary

  • On existing OpenShift clusters upgrading to self-managed webhook certs (CNTRLPLANE-2207: feat(install): self-manage webhook certs instead of relying on service-ca #8174), the service-ca operator may still have its annotations on the operator Service and the serving cert secret it created. This causes a CA mismatch: webhook configs contain the self-managed CA bundle but the serving cert is signed by service-ca's CA, resulting in x509: certificate signed by unknown authority.
  • Adds removeServiceCAResources() to WebhookCertReconciler following the same pattern as removeServiceCAAnnotationAndSecret in the CPO. It removes service-ca annotations from the Service and deletes the serving cert secret if it was created by service-ca, so the reconciler recreates it signed by the self-managed CA.
  • Adds 3 unit tests covering the upgrade scenarios.

Test plan

  • Unit tests pass (go test ./hypershift-operator/controllers/webhookcerts/...)
  • make verify passes
  • Verify on an existing OpenShift cluster that previously used service-ca for webhook certs

🤖 Generated with Claude Code

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The webhook certificates controller is updated to support migration away from service-ca-managed serving certificates. New constants define annotation keys used by service-ca. The reconciliation flow now includes a preliminary step that removes service-ca-related state: it fetches the operator Service and removes service-ca annotations, then fetches and deletes the serving-cert Secret if it is service-ca-managed. Detection of service-ca management is performed by checking for originating-service annotation keys on the Secret. After cleanup, normal self-signed CA reconciliation proceeds.

Sequence Diagram

sequenceDiagram
    participant Reconciler as Webhook Cert Reconciler
    participant K8sAPI as Kubernetes API
    participant Service as Operator Service
    participant Secret as Manager Serving Cert Secret

    Reconciler->>Reconciler: Reconcile called
    
    Reconciler->>K8sAPI: removeServiceCAResources()
    
    K8sAPI->>Service: Fetch operator Service
    Service-->>K8sAPI: Service object
    K8sAPI-->>Reconciler: Service retrieved
    
    rect rgba(255, 107, 107, 0.5)
    Reconciler->>Reconciler: Check for service-ca annotations
    Reconciler->>K8sAPI: Remove annotations from Service
    K8sAPI->>Service: Update Service (annotations removed)
    Service-->>K8sAPI: Service updated
    K8sAPI-->>Reconciler: Update confirmed
    end
    
    K8sAPI->>Secret: Fetch manager-serving-cert Secret
    Secret-->>K8sAPI: Secret object (if exists)
    K8sAPI-->>Reconciler: Secret retrieved
    
    rect rgba(255, 107, 107, 0.5)
    Reconciler->>Reconciler: isServiceCAManaged(Secret)
    Reconciler->>Reconciler: Check originating-service annotations
    alt Secret is service-ca managed
        Reconciler->>K8sAPI: Delete Secret
        K8sAPI->>Secret: Delete Secret
        Secret-->>K8sAPI: Deleted
    else Secret is self-managed
        Reconciler->>Reconciler: Skip deletion
    end
    end
    
    Reconciler->>Reconciler: Reconcile self-signed CA (original flow)
Loading
✨ 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 openshift-ci Bot added area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Apr 8, 2026
@openshift-ci
openshift-ci Bot requested review from bryan-cox and csrwng April 8, 2026 21:43
@openshift-ci

openshift-ci Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enxebre

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 8, 2026
@openshift-ci-robot

openshift-ci-robot commented Apr 8, 2026

Copy link
Copy Markdown

@enxebre: This pull request references CNTRLPLANE-2207 which is a valid jira issue.

Details

In response to this:

Summary

  • On existing OpenShift clusters upgrading to self-managed webhook certs (CNTRLPLANE-2207: feat(install): self-manage webhook certs instead of relying on service-ca #8174), the service-ca operator may still have its annotations on the operator Service and the serving cert secret it created. This causes a CA mismatch: webhook configs contain the self-managed CA bundle but the serving cert is signed by service-ca's CA, resulting in x509: certificate signed by unknown authority.
  • Adds removeServiceCAResources() to WebhookCertReconciler following the same pattern as removeServiceCAAnnotationAndSecret in the CPO. It removes service-ca annotations from the Service and deletes the serving cert secret if it was created by service-ca, so the reconciler recreates it signed by the self-managed CA.
  • Adds 3 unit tests covering the upgrade scenarios.

Test plan

  • Unit tests pass (go test ./hypershift-operator/controllers/webhookcerts/...)
  • make verify passes
  • Verify on an existing OpenShift cluster that previously used service-ca for webhook certs

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Webhook certificate reconciliation now properly detects and removes legacy certificate configurations, ensuring clean state transitions during upgrades.

Tests

  • Added comprehensive test coverage for webhook certificate upgrade scenarios, verifying proper handling of certificate migrations and state cleanup.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
hypershift-operator/controllers/webhookcerts/webhookcerts_controller_test.go (1)

233-258: Add explicit alpha-annotation coverage and reuse controller constants in tests.

The new tests only exercise beta keys via string literals. Since controller logic handles both alpha and beta keys, add an alpha case and reference serviceCABetaAnnotation / serviceCAAlphaAnnotation and originatingServiceBetaAnnotation / originatingServiceAlphaAnnotation to avoid drift.

As per coding guidelines, **: Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Also applies to: 260-315, 317-335

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hypershift-operator/controllers/webhookcerts/webhookcerts_controller_test.go`
around lines 233 - 258, Test currently only asserts removal of the beta
service-ca annotation using string literals; add an equivalent test case that
covers the alpha annotation too and replace any hard-coded annotation keys in
these tests with the controller constants serviceCABetaAnnotation,
serviceCAAlphaAnnotation, originatingServiceBetaAnnotation and
originatingServiceAlphaAnnotation so the tests exercise both alpha and beta
paths and stay in sync with controller logic (update the test in the t.Run block
and the other referenced blocks around lines 260-335 to use those constants and
add the extra alpha-case assertion).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@hypershift-operator/controllers/webhookcerts/webhookcerts_controller_test.go`:
- Around line 233-258: Test currently only asserts removal of the beta
service-ca annotation using string literals; add an equivalent test case that
covers the alpha annotation too and replace any hard-coded annotation keys in
these tests with the controller constants serviceCABetaAnnotation,
serviceCAAlphaAnnotation, originatingServiceBetaAnnotation and
originatingServiceAlphaAnnotation so the tests exercise both alpha and beta
paths and stay in sync with controller logic (update the test in the t.Run block
and the other referenced blocks around lines 260-335 to use those constants and
add the extra alpha-case assertion).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: c8bcac3a-25cb-4462-bbdb-c9f4f9107193

📥 Commits

Reviewing files that changed from the base of the PR and between c674483 and 7988c1a.

📒 Files selected for processing (2)
  • hypershift-operator/controllers/webhookcerts/webhookcerts_controller.go
  • hypershift-operator/controllers/webhookcerts/webhookcerts_controller_test.go

@sjenning sjenning changed the title CNTRLPLANE-2207: fix(webhookcerts): handle upgrade from service-ca managed certs OCPBUGS-82192: fix(webhookcerts): handle upgrade from service-ca managed certs Apr 8, 2026
@openshift-ci-robot openshift-ci-robot added the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Apr 8, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@enxebre: This pull request references Jira Issue OCPBUGS-82192, which is invalid:

  • expected the bug to target the "4.22.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • On existing OpenShift clusters upgrading to self-managed webhook certs (CNTRLPLANE-2207: feat(install): self-manage webhook certs instead of relying on service-ca #8174), the service-ca operator may still have its annotations on the operator Service and the serving cert secret it created. This causes a CA mismatch: webhook configs contain the self-managed CA bundle but the serving cert is signed by service-ca's CA, resulting in x509: certificate signed by unknown authority.
  • Adds removeServiceCAResources() to WebhookCertReconciler following the same pattern as removeServiceCAAnnotationAndSecret in the CPO. It removes service-ca annotations from the Service and deletes the serving cert secret if it was created by service-ca, so the reconciler recreates it signed by the self-managed CA.
  • Adds 3 unit tests covering the upgrade scenarios.

Test plan

  • Unit tests pass (go test ./hypershift-operator/controllers/webhookcerts/...)
  • make verify passes
  • Verify on an existing OpenShift cluster that previously used service-ca for webhook certs

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Webhook certificate reconciliation now properly detects and removes legacy certificate configurations, ensuring clean state transitions during upgrades.

Tests

  • Added comprehensive test coverage for webhook certificate upgrade scenarios, verifying proper handling of certificate migrations and state cleanup.

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 openshift-eng/jira-lifecycle-plugin repository.

@sjenning

sjenning commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Apr 8, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@sjenning: This pull request references Jira Issue OCPBUGS-82192, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.22.0) matches configured target version for branch (4.22.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

/jira refresh

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 openshift-eng/jira-lifecycle-plugin repository.

@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.09091% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.13%. Comparing base (c674483) to head (7988c1a).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...ontrollers/webhookcerts/webhookcerts_controller.go 59.09% 12 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8189      +/-   ##
==========================================
+ Coverage   33.11%   33.13%   +0.01%     
==========================================
  Files         768      768              
  Lines       93116    93159      +43     
==========================================
+ Hits        30840    30865      +25     
- Misses      59665    59677      +12     
- Partials     2611     2617       +6     
Files with missing lines Coverage Δ
...ontrollers/webhookcerts/webhookcerts_controller.go 66.00% <59.09%> (-2.16%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@clebs

clebs commented Apr 9, 2026

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 9, 2026
@openshift-ci-robot

Copy link
Copy Markdown

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks-4-21
/test e2e-aws-4-21
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-azure-self-managed
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws

@cwbotbot

cwbotbot commented Apr 9, 2026

Copy link
Copy Markdown

Test Results

e2e-aws

e2e-aks

@clebs

clebs commented Apr 9, 2026

Copy link
Copy Markdown
Member

/test e2e-aws-4-21

@clebs

clebs commented Apr 9, 2026

Copy link
Copy Markdown
Member

/verified by e2e and @sjenning

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Apr 9, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@clebs: This PR has been marked as verified by e2e and @sjenning.

Details

In response to this:

/verified by e2e and @sjenning

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

@enxebre: all tests passed!

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.

@openshift-merge-bot
openshift-merge-bot Bot merged commit 57057ce into openshift:main Apr 9, 2026
29 checks passed
@openshift-ci-robot

Copy link
Copy Markdown

@enxebre: Jira Issue Verification Checks: Jira Issue OCPBUGS-82192
✔️ This pull request was pre-merge verified.
✔️ All associated pull requests have merged.
✔️ All associated, merged pull requests were pre-merge verified.

Jira Issue OCPBUGS-82192 has been moved to the MODIFIED state and will move to the VERIFIED state when the change is available in an accepted nightly payload. 🕓

Details

In response to this:

Summary

  • On existing OpenShift clusters upgrading to self-managed webhook certs (CNTRLPLANE-2207: feat(install): self-manage webhook certs instead of relying on service-ca #8174), the service-ca operator may still have its annotations on the operator Service and the serving cert secret it created. This causes a CA mismatch: webhook configs contain the self-managed CA bundle but the serving cert is signed by service-ca's CA, resulting in x509: certificate signed by unknown authority.
  • Adds removeServiceCAResources() to WebhookCertReconciler following the same pattern as removeServiceCAAnnotationAndSecret in the CPO. It removes service-ca annotations from the Service and deletes the serving cert secret if it was created by service-ca, so the reconciler recreates it signed by the self-managed CA.
  • Adds 3 unit tests covering the upgrade scenarios.

Test plan

  • Unit tests pass (go test ./hypershift-operator/controllers/webhookcerts/...)
  • make verify passes
  • Verify on an existing OpenShift cluster that previously used service-ca for webhook certs

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Webhook certificate reconciliation now properly detects and removes legacy certificate configurations, ensuring clean state transitions during upgrades.

Tests

  • Added comprehensive test coverage for webhook certificate upgrade scenarios, verifying proper handling of certificate migrations and state cleanup.

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

Fix included in release 4.22.0-0.nightly-2026-04-10-145151

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. area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants