Repository navigation
Conversation
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]>
|
Hi @fjvbn2003. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions 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. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
| return ok && bundle == "" && | ||
| len(existing.Data) == 1 && | ||
| len(existing.BinaryData) == 0 && | ||
| objectMatchesVersion(&existing.ObjectMeta, version, imageRegistry, id, generation) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does
Before this PR:
createOrUpdateComponentsWithCertificatescallscleanupExternalCACertson every reconcile, and that functionalways sends
PUT configmaps/kubevirt-external-cawhen 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 thenumber of reconciles (
LIST nodes= 843,995).data: {ca-bundle: ""}, no binaryData, operator labels andinstall-strategy-version/registry/identifier/generationannotations matching the KubeVirt CR, and itsresourceVersiondoes not move. The apiserver turns these PUTs into no-ops, but each one is still a writerequest through admission and audit.
After this PR:
The update is skipped when the cached ConfigMap already has exactly
ca-bundle: "", no binaryData and currentoperator metadata (
objectMatchesVersion). It is still sent when an external CA was added (the normal cleanuppath) and when the metadata is outdated, e.g. after an upgrade or a KubeVirt CR generation change.
References
reconcile frequency.
Why we need it and why it was done in this way
The following tradeoffs were made:
createOrUpdate*helpers in this file do.The following alternatives were considered:
getRemotePublicCasreturned certificates. That misses the case where theConfigMap 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
core_test.go: empty and current → no API call (the context's default reactor fails on anycall); holds a CA bundle → updated to empty; outdated version annotation → updated.
-mod=vendor, base 580886a): the three new specs pass, and the first onefails without the
core.gochange (the PUT hits the default reactor).go test ./pkg/virt-operator/resource/apply/:195 of 195 specs pass.
go vetandgofmtare clean.Checklist
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-bytrailer.Release note