Skip to content

NO-JIRA: Add WithOptions constructor and StripManagedFieldsTransform for KubeInformersForNamespaces - #2379

Open
sanchezl wants to merge 2 commits into
openshift:masterfrom
sanchezl:informer-options
Open

NO-JIRA: Add WithOptions constructor and StripManagedFieldsTransform for KubeInformersForNamespaces#2379
sanchezl wants to merge 2 commits into
openshift:masterfrom
sanchezl:informer-options

Conversation

@sanchezl

@sanchezl sanchezl commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add NewKubeInformersForNamespacesWithOptions, a constructor that accepts SharedInformerOption arguments and forwards them to each per-namespace factory. This allows callers to use WithTransform and other informer options uniformly across all namespaces.
  • Add StripManagedFieldsTransform, a cache.TransformFunc that removes ManagedFields from objects before they are stored in the informer cache. ManagedFields can be 50-80% of serialized object size for server-side apply managed resources. Inspired by the pattern in the lister wrappers in informers.go and the inline transform used by upstream Kubernetes in pkg/controlplane/apiserver/config.go, which is not exported.

Test plan

  • go test ./pkg/operator/v1helpers/... passes
  • make verify passes

Summary by CodeRabbit

  • New Features
    • Added configurable Kubernetes informer creation across multiple namespaces, including cluster-wide and mixed scopes.
    • Added a cache transform to strip managed fields from cached Kubernetes objects.
  • Refactor
    • Updated existing namespace informer helpers to route through the new configurable informer-creation path for consistent behavior.
  • Tests
    • Added unit tests covering informer namespace registration and managed-field transform passthrough/removal behavior.

@openshift-ci
openshift-ci Bot requested review from bertinatto and p0lyn0mial July 24, 2026 20:13
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sanchezl
Once this PR has been reviewed and has the lgtm label, please assign jsafrane 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 Jul 24, 2026

Copy link
Copy Markdown

Walkthrough

Adds configurable Kubernetes informer factories for multiple namespaces and a cache transform that removes managed fields. Unit tests cover namespace registration, cluster-wide behavior, managed-field removal, absent fields, and non-object inputs.

Changes

Informer helper extensions

Layer / File(s) Summary
Configurable namespace informer construction
pkg/operator/v1helpers/informers.go, pkg/operator/v1helpers/informers_test.go
Adds an options-aware informer constructor, preserves existing wrapper behavior, and applies options across namespaced and cluster-wide factories.
Managed-fields cache transformation
pkg/operator/v1helpers/informers.go, pkg/operator/v1helpers/informers_test.go
Adds metadata-based managed-field removal while preserving unsupported inputs, with coverage for present, absent, and unsupported object cases.

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

Suggested reviewers: bertinatto, p0lyn0mial

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
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.
Stable And Deterministic Test Names ✅ Passed Added test titles are static, descriptive strings; no dynamic values, timestamps, IDs, or generated names appear in t.Run names.
Test Structure And Quality ✅ Passed No Ginkgo tests are present; the new unit tests are table-driven, self-contained, and avoid cluster resources, waits, and cleanup issues.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the changes are unit tests in pkg/operator/v1helpers and contain no MicroShift-sensitive APIs or guards.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The added tests are pure unit tests using a fake clientset; no Ginkgo e2e logic or multi-node/SNO assumptions were added.
Topology-Aware Scheduling Compatibility ✅ Passed Only informer-factory helpers and a cache transform changed; no pod specs, node selectors, affinity, replicas, or scheduling constraints were introduced.
Ote Binary Stdout Contract ✅ Passed No process-level stdout writes were added; the PR only adds helper code and ordinary tests, with no main/init/suite setup changes.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR adds only Go unit tests in pkg/operator/v1helpers, with no Ginkgo e2e tests, IP literals, or external connectivity usage.
No-Weak-Crypto ✅ Passed Changed files only add informer options and a ManagedFields-stripping transform; no weak crypto, custom crypto, or secret comparisons appear.
Container-Privileges ✅ Passed PASS: The PR only changes Go informer helpers/tests; no container manifests or privileged/securityContext settings were introduced.
No-Sensitive-Data-In-Logs ✅ Passed No new logging or error messages expose passwords, tokens, PII, session IDs, or customer data; the patch only handles namespace names and managed fields.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: a WithOptions constructor and StripManagedFieldsTransform for KubeInformersForNamespaces.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@sanchezl
sanchezl force-pushed the informer-options branch 2 times, most recently from 229fbe9 to 4b89708 Compare July 24, 2026 20:27
sanchezl added 2 commits July 24, 2026 16:30
Add a constructor that accepts SharedInformerOption arguments and
forwards them to each per-namespace factory. This allows callers to use
WithTransform and other informer options uniformly across all namespaces.

Rewrite NewKubeInformersForNamespaces and
NewKubeInformersForNamespacesWithResyncPeriod as thin wrappers around
the new constructor to consolidate factory-creation logic.
Add a cache.TransformFunc that removes ManagedFields from objects before
they are stored in the informer cache. ManagedFields can be 50-80% of
serialized object size for server-side apply managed resources.

This follows the same pattern used by upstream Kubernetes internally
but is not exported there. Usable with the WithOptions constructor via
informers.WithTransform(StripManagedFieldsTransform).
@sanchezl sanchezl changed the title Add WithOptions constructor and StripManagedFieldsTransform for KubeInformersForNamespaces NO-JIRA: Add WithOptions constructor and StripManagedFieldsTransform for KubeInformersForNamespaces Jul 24, 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 Jul 24, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@sanchezl: This pull request explicitly references no jira issue.

Details

In response to this:

Summary

  • Add NewKubeInformersForNamespacesWithOptions, a constructor that accepts SharedInformerOption arguments and forwards them to each per-namespace factory. This allows callers to use WithTransform and other informer options uniformly across all namespaces.
  • Add StripManagedFieldsTransform, a cache.TransformFunc that removes ManagedFields from objects before they are stored in the informer cache. ManagedFields can be 50-80% of serialized object size for server-side apply managed resources. Inspired by the pattern in the lister wrappers in informers.go and the inline transform used by upstream Kubernetes in pkg/controlplane/apiserver/config.go, which is not exported.

Test plan

  • go test ./pkg/operator/v1helpers/... passes
  • make verify passes

Summary by CodeRabbit

  • New Features

  • Added configurable Kubernetes informer creation across multiple namespaces, including cluster-wide and mixed scopes.

  • Added an option to strip managed fields from cached Kubernetes objects to reduce stored metadata.

  • Refactor

  • Updated existing namespace informer helpers to route through the new configurable informer-creation path for consistent behavior.

  • Tests

  • Added unit tests validating informer registration (including nil for unregistered namespaces) and safe managed-field removal/passthrough behavior.

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 Jul 24, 2026

Copy link
Copy Markdown
Contributor

@sanchezl: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants