Skip to content

🌱 Add unit tests for cache annotation-stripping transforms - #3213

Open
andretorresdg wants to merge 1 commit into
operator-framework:mainfrom
andretorresdg:test-cache-transform
Open

andretorresdg wants to merge 1 commit into
operator-framework:mainfrom
andretorresdg:test-cache-transform

Conversation

@andretorresdg

@andretorresdg andretorresdg commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

internal/shared/util/cache/transform.go strips the (potentially very large) kubectl.kubernetes.io/last-applied-configuration annotation, and optionally managed fields, from objects before they are stored in informer caches. It had no tests. This adds tests that cover: nil annotations, unrelated annotations preserved, the annotation removed, annotations cleared when it was the only entry, the original (shared) annotations map not being mutated, non-client.Object input passing through, and managed fields only being stripped by StripManagedFieldsAndAnnotations.

Tests only, no production code changes.

How I tested

  • go test ./internal/shared/util/cache/ passes.
  • Sanity check: replacing maps.Clone in stripAnnotations with an in-place mutation makes TestStripAnnotations_DoesNotMutateSharedMap fail; restored afterwards.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Summary by CodeRabbit

  • Tests
    • Added coverage for annotation stripping, managed-field preservation and removal, unchanged non-client objects, and avoiding mutation of shared annotations.

Cover removal of the kubectl last-applied-configuration annotation, that
other annotations are preserved, that the shared annotations map of the
cached object is not mutated, and that managed fields are only stripped
by StripManagedFieldsAndAnnotations.

Signed-off-by: Andre Devay <andretorresdg@alumni.usp.br>
@netlify

netlify Bot commented Nov 28, 2026

Copy link
Copy Markdown

👷 Deploy request for olmv1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0a4fced

@openshift-ci

openshift-ci Bot commented Nov 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 joelanford 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

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This change adds tests for annotation-stripping cache transforms. The tests cover last-applied annotation removal, managed-field handling, shared-map preservation, and non-client inputs.

Changes: Cache transform test coverage

Layer / File(s) Summary
Annotation transform behavior
internal/shared/util/cache/transform_test.go
Adds tests for StripAnnotations, StripManagedFieldsAndAnnotations, and ApplyStripAnnotationsTransform. Assertions cover annotation removal, managed-field preservation or clearing, object identity, shared-map immutability, and non-client inputs.

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

Change: Other

Suggested reviewers: perdasilva, fgiudici

Merge Risk: Minimal · up to 0a4fc

This PR adds tests for annotation-stripping cache transforms and does not change production behavior. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: adding unit tests for the cache annotation-stripping transforms. It uses the seedling icon, which matches the change type (other, no production code changes). The titl…
Description check Passed The description follows the template. It has a Description section that explains the motivation and lists the test coverage. It includes a How I tested section with the test command and a mutation san…
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: Title check

Explanation

The title names the main change: adding unit tests for the cache annotation-stripping transforms. It uses the seedling icon, which matches the change type (other, no production code changes). The title is concise and specific.

Full details: Description check

Explanation

The description follows the template. It has a Description section that explains the motivation and lists the test coverage. It includes a How I tested section with the test command and a mutation sanity check. The Reviewer Checklist is kept, but no boxes are checked and no related GitHub issue is linked. These are non-critical gaps, so the description is mostly complete.

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: Advanced
  • Run ID: dc583329-7f0e-4145-92a9-fbab828e2bd4
Commits

Reviewing files that changed from the base of the PR and between 66fe7c8 and 0a4fced.

Files selected for processing: 1

  • internal/shared/util/cache/transform_test.go

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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant