Skip to content

virt-operator: skip the no-op update of kubevirt-external-ca on every reconcile - #19530

Open
fjvbn2003 wants to merge 2 commits into
kubevirt:mainfrom
fjvbn2003:operator-skip-external-ca-noop-update
Open

fjvbn2003 wants to merge 2 commits into
kubevirt:mainfrom
fjvbn2003:operator-skip-external-ca-noop-update

Conversation

@fjvbn2003

@fjvbn2003 fjvbn2003 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Before this PR:

createOrUpdateComponentsWithCertificates calls cleanupExternalCACerts on every reconcile, and that function
always sends PUT configmaps/kubevirt-external-ca when the ConfigMap exists, even if it is already empty.

Measured on a homelab cluster (KubeVirt v1.9.0, Kubernetes v1.34.10, leader virt-operator up for 59 days):

  • kubevirt_rest_client_requests_total{verb="UPDATE",resource="configmaps",code="200"} = 843,995, the same as the
    number of reconciles (LIST nodes = 843,995).
  • The live object is already in the target state: data: {ca-bundle: ""}, no binaryData, operator labels and
    install-strategy-version/registry/identifier/generation annotations matching the KubeVirt CR, and its
    resourceVersion does not move. The apiserver turns these PUTs into no-ops, but each one is still a write
    request through admission and audit.

After this PR:

The update is skipped when the cached ConfigMap already has exactly ca-bundle: "", no binaryData and current
operator metadata (objectMatchesVersion). It is still sent when an external CA was added (the normal cleanup
path) and when the metadata is outdated, e.g. after an upgrade or a KubeVirt CR generation change.

References

Why we need it and why it was done in this way

The following tradeoffs were made:

  • Compare against the informer cache instead of a GET, as the other createOrUpdate* helpers in this file do.

The following alternatives were considered:

  • Only clear the ConfigMap when getRemotePublicCas returned certificates. That misses the case where the
    ConfigMap holds data that does not parse, which the current code also clears.

Links to places where the discussion took place: none

Special notes for your reviewer

  • New unit tests in core_test.go: empty and current → no API call (the context's default reactor fails on any
    call); holds a CA bundle → updated to empty; outdated version annotation → updated.
  • Test results (golang:1.27.2, linux/amd64, -mod=vendor, base 580886a): the three new specs pass, and the first one
    fails without the core.go change (the PUT hits the default reactor). go test ./pkg/virt-operator/resource/apply/:
    195 of 195 specs pass. go vet and gofmt are clean.

Checklist

  • Design: A VEP is not required
  • PR: The PR description is expressive enough and will help future contributors
  • Code: Write code that humans can understand and Keep it simple
  • Refactor: You have left the code cleaner than you found it (Boy Scout Rule)
  • Upgrade: metadata changes after an upgrade still trigger the update
  • Testing: unit tests added
  • Documentation: not required
  • Community: Announcement to kubevirt-dev was considered
  • AI Contributions: The PR abides by the KubeVirt AI Contribution Policy.

AI disclosure: I used Claude (Anthropic) to help trace the request counters to the code and to draft the change
and tests. The numbers above were measured on my own cluster, also with Claude's help. The commit carries an
Assisted-by trailer.

Release note

NONE

cleanupExternalCACerts empties the kubevirt-external-ca ConfigMap
after its certificates have been merged into the CA bundle. It sends
an unconditional Update on every reconcile, even when the ConfigMap is
already empty and carries the current operator metadata, which is the
normal state when nobody uses an external CA.

Skip the update when the cached ConfigMap already holds an empty CA
bundle and matches the current install strategy version, registry,
identifier and generation.

Assisted-by: Claude <[email protected]>
Signed-off-by: YoungjuKim <[email protected]>
@kubevirt-prow kubevirt-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Oct 19, 2026
@kubevirt-prow
kubevirt-prow Bot requested review from akalenyu and lyarwood October 19, 2026 15:49
@kubevirt-prow kubevirt-prow Bot added the size/M label Oct 19, 2026
@kubevirt-prow

kubevirt-prow Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Hi @fjvbn2003. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Comment on lines +401 to +404
return ok && bundle == "" &&
len(existing.Data) == 1 &&
len(existing.BinaryData) == 0 &&
objectMatchesVersion(&existing.ObjectMeta, version, imageRegistry, id, generation)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add separate specs for an extra Data key and non-empty BinaryData? Start each with an empty ca-bundle and matching operator metadata so that each guard is exercised independently. Please also assert that the submitted update contains exactly Data: {"ca-bundle": ""} and no BinaryData, rather than only checking that an update happened. The current specs cover an already-cleared ConfigMap, a non-empty bundle and an outdated version annotation, but neither of these guards.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added separate specs for an extra Data key and for non-empty BinaryData, each starting from an empty ca-bundle with matching metadata. All update specs now assert that the submitted object has exactly Data: {"ca-bundle": ""} and no BinaryData.

return fmt.Errorf("unable to create configMap %s: %v", configMap.Name, err)
}
} else {
} else if !isExternalCAConfigMapCleared(obj.(*corev1.ConfigMap), version, imageRegistry, id, r.kv.GetGeneration()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit (non-blocking): could we add a V(4) log when cleanup skips the update? The sibling createOrUpdateKubeVirtCAConfigMap logs configMap %v is up-to-date in its skip path. A matching message here would help confirm that this write is being skipped when debugging reconciliation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, it logs configMap %v is up-to-date at V(4), matching createOrUpdateKubeVirtCAConfigMap.

len(existing.Data) == 1 &&
len(existing.BinaryData) == 0 &&
objectMatchesVersion(&existing.ObjectMeta, version, imageRegistry, id, generation)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

objectMatchesVersion does not establish that all the metadata written by injectOperatorMetadata matches. It accepts a missing generation annotation and does not compare the product/component labels. An otherwise-cleared ConfigMap with either kind of metadata drift can therefore skip the update, whereas the previous unconditional update would repair it.

Could we compare the desired metadata using the sibling createOrUpdateKubeVirtCAConfigMap's resourcemerge.EnsureObjectMeta approach, operating on a copy of the cached object, and add regression coverage for a missing generation annotation and product/component label drift? This would make the skip preserve the existing metadata repair behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. Switched to the sibling's approach: resourcemerge.EnsureObjectMeta on a copy of the cached object, so the skip now requires the full metadata written by injectOperatorMetadata to match. Added regression specs for a missing generation annotation, component label drift and a missing product label; all three fail with the previous objectMatchesVersion check and pass now.

…l CA update

objectMatchesVersion accepts a missing generation annotation and does
not look at the product/component labels, so a cleared ConfigMap with
that kind of drift skipped the update that used to repair it. Compare
the desired ObjectMeta with resourcemerge.EnsureObjectMeta on a copy of
the cached object, as createOrUpdateKubeVirtCAConfigMap does, and log
at V(4) when the update is skipped.

Add specs for an extra Data key, non-empty BinaryData, a missing
generation annotation and component/product label drift, and assert
that the submitted update carries exactly the cleared data.

Assisted-by: Claude <[email protected]>
Signed-off-by: YoungjuKim <[email protected]>
@kubevirt-prow kubevirt-prow Bot added size/L and removed size/M labels Oct 22, 2026
@fjvbn2003

Copy link
Copy Markdown
Contributor Author

@lyarwood friendly ping: I addressed the three review comments in dc123fc on Oct 21 (replies are in the threads). Could you take another look when you have a moment? Thank you!

@lyarwood lyarwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/approve

Thanks!

@kubevirt-prow

kubevirt-prow Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lyarwood

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

@kubevirt-prow kubevirt-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 11, 2026

This branch has not been deployed

No deployments
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/operator dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note-none Denotes a PR that doesn't merit a release note. sig/control-plane size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants