Skip to content

refactor: clean up the Kubernetes resource matchers - #3546

Open
csviri wants to merge 1 commit into
operator-framework:nextfrom
csviri:kubernetes-matcher-cleanups
Open

refactor: clean up the Kubernetes resource matchers#3546
csviri wants to merge 1 commit into
operator-framework:nextfrom
csviri:kubernetes-matcher-cleanups

Conversation

@csviri

@csviri csviri commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator
  • GenericKubernetesResourceMatcher allocated the path-prefix lists
    (List.of(SPEC), List.of(METADATA), the labels/annotations pair, List.of(STATUS))
    once per JSON-diff node while matching, and nodeIsChildOf built a stream per
    call. Both run for every node of every match, so hoist the lists to constants
    and use an indexed loop.
  • SSABasedGenericKubernetesResourceMatcher#sanitizeState nested the StatefulSet
    volume-claim-template handling four levels deep inside the type ladder;
    extract it into sanitizeVolumeClaimTemplates so the ladder reads as one
    dispatch per resource kind.

Quality-only change: no intended behavior difference. Cut from next and
touches a disjoint set of files from the sibling cleanup PRs, so it can be merged
independently and in any order.

Verified on this branch alone: mvn -o -pl operator-framework-core,operator-framework-junit -am test
(693 core + 6 junit tests, no failures) and mvn spotless:check.

- GenericKubernetesResourceMatcher allocated the path-prefix lists
  (List.of(SPEC), List.of(METADATA), the labels/annotations pair, List.of(STATUS))
  once per JSON-diff node while matching, and nodeIsChildOf built a stream per
  call. Both run for every node of every match, so hoist the lists to constants
  and use an indexed loop.
- SSABasedGenericKubernetesResourceMatcher#sanitizeState nested the StatefulSet
  volume-claim-template handling four levels deep inside the type ladder;
  extract it into sanitizeVolumeClaimTemplates so the ladder reads as one
  dispatch per resource kind.
Copilot AI lite review requested due to automatic review settings August 7, 2026 11:54
@openshift-ci
openshift-ci Bot requested review from metacosm and xstefank August 7, 2026 11:54
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0bbee890-b708-4173-bc4c-740e69cd06a3

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

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.

Copilot AI 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.

Pull request overview

This PR performs a small internal refactor of the Kubernetes resource matching/sanitization utilities in the operator framework core, focusing on reducing per-node allocations during JSON patch matching and flattening the SSA sanitizer’s kind-specific logic for StatefulSets.

Changes:

  • Hoist frequently recreated JSON-path prefix lists in GenericKubernetesResourceMatcher into static constants and replace a per-call stream with an indexed loop.
  • Extract StatefulSet volumeClaimTemplates sanitization from sanitizeState into a dedicated helper method for readability.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java Extracts StatefulSet volumeClaimTemplates sanitization into sanitizeVolumeClaimTemplates to simplify the dispatch ladder.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java Reduces allocation overhead by hoisting prefix lists and replacing stream().anyMatch(...) with a simple loop.

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.

2 participants