Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠ cache.BuilderWithOptions inherit options from caller #1980

Merged

Conversation

joelanford
Copy link
Member

using cache.BuilderWithOptions does not properly inherit all
options passed in from the caller:

  • scheme was overridden instead of merged
  • selectors were not inherited at all, even if specified options
    selectors remained unset
  • transforms were not inherited at all, even if specified options
    transforms remained unset
  • disable deep copy settings were not inherited at all, even if
    specified options for disabling deep copies remained unset

This commit resolves this issues by implementing merge logic for all
fields in the cache.Options struct:

  • Schemes are merged
  • RESTMapper is chosen by precedence only falling back to inherited
    options if left unset in specified options
  • Resync is chosen by precedence only falling back to inherited
    options if left unset in specified options
  • Namespace is chosen by precedence only falling back to inherited
    options if left unset in specified options
  • Selectors are merged. If both inherited and specified Options defined
    selectors for a given type, those selectors are merged via logical
    AND.
  • DisableDeepCopy is combined via precedence. Only if a value for a
    particular GVK is unset in the specified options will a value from the
    inherited options be used.
  • Transform functions are combined via chaining. If both inherited and
    specified options define a transform function, the transform function
    from the inherited options will be called first, and the transform
    function from the specified options will be called second.

This is a breaking change if your code does all of the following:

  1. Uses cache.BuilderWithOptions
  2. Specifically depends on the fact that inherited options are not currently considered for selectors, disabling deep copies, and transform functions OR that the inherited scheme is ignored if it is defined in the options specified with cache.BuilderWithOptions.

Signed-off-by: Joe Lanford joe.lanford@gmail.com

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 16, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joelanford

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 16, 2022
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2022
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 29, 2022
Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

This fix does seem good to me. Except for my questions on having DisableDeepCopyByObject external. But that change isn't made here, and hence not concerning/blocking. Leaving it for others to review.

pkg/cache/cache.go Outdated Show resolved Hide resolved
using cache.BuilderWithOptions does not properly inherit all
options passed in from the caller:
- scheme was overridden instead of merged
- selectors were not inherited at all, even if specified options
  selectors remained unset
- transforms were not inherited at all, even if specified options
  transforms remained unset
- disable deep copy settings were not inherited at all, even if
  specified options for disabling deep copies remained unset

This commit resolves this issues by implementing merge logic for all
fields in the cache.Options struct:
- Schemes are merged
- RESTMapper is chosen by precedence only falling back to inherited
  options if left unset in specified options
- Resync is chosen by precedence only falling back to inherited
  options if left unset in specified options
- Namespace is chosen by precedence only falling back to inherited
  options if left unset in specified options
- Selectors are merged. If both inherited and specified Options defined
  selectors for a given type, those selectors are merged via logical
  AND.
- DisableDeepCopy is combined via precedence. Only if a value for a
  particular GVK is unset in the specified options will a value from the
  inherited options be used.
- Transform functions are combined via chaining. If both inherited and
  specified options define a transform function, the transform function
  from the inherited options will be called first, and the transform
  function from the specified options will be called second.

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
@joelanford
Copy link
Member Author

/retest

@sbueringer
Copy link
Member

/retest

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 31, 2022
@joelanford
Copy link
Member Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit 15b6689 into kubernetes-sigs:master Aug 31, 2022
@k8s-ci-robot k8s-ci-robot added this to the v0.10.x milestone Aug 31, 2022
@sbueringer
Copy link
Member

sbueringer commented Aug 31, 2022

Oh wasn't aware self-approve is enabled in this repo. Sorry if this wasn't intended to be merged already

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants