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

⚠️ adding multi namespaces cache #267

Conversation

shawn-hurley
Copy link

@shawn-hurley shawn-hurley commented Dec 28, 2018

This will add the ability to set up a multi-namespace cache. This also has a backward incompatible change in the Informers interface which effects the cache interface.

This is based on the discussion from the BoF.
/cc @DirectXMan12 @mhrivnak @hasbro17

Wanted to get some early feedback before starting on tests.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 28, 2018
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 28, 2018
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

overall looks pretty solid. couple of comments inline, but it's pretty simple and straightforward to understand. Needs godoc on the internal objects, plus a bit more explanation of when you might want to use this, but in general 👍

pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Show resolved Hide resolved
@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from 9ad3d39 to 2f6a0b3 Compare January 22, 2019 21:26
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 22, 2019
@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from 5c59791 to a6adef3 Compare January 23, 2019 18:38
@shawn-hurley shawn-hurley changed the title WIP/POC ⚠️ adding multi namespaced cache. ⚠️ adding multi namespaces cache Jan 24, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 24, 2019
@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from a6adef3 to 35bbe4b Compare January 24, 2019 16:11
@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from 35bbe4b to b8dca46 Compare February 1, 2019 16:58
@sebgl
Copy link
Contributor

sebgl commented Feb 14, 2019

Drive-by comment: I think this is great and would love to see it merged 🎉

Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

Need rebase.

if err != nil {
return err
}
return json.Unmarshal(data, list)
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid marshal and then unmarshal to improve performance?

Copy link
Author

Choose a reason for hiding this comment

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

I don't have a good way to do this when say someone is asking for a PodList that I can think of.

Maybe we could do some reflection bits to make sure that the Items field is there and use the scheme to create a new Object each time. I don't know how much better performance this would be though, WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think the code snippet you linked look reasonable. I believe it can improve performance by avoiding some unnecessary work.
But what confused me is why you treat ResourceVersion specially. How about other metadata fields?

Copy link
Author

Choose a reason for hiding this comment

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

so here was my thinking:

  1. SelfLink string - would think that this also does not make sense because we are combining multiple calls into one list. There is not a link that one could call to get the same list. This is also optional, so I figured it was fine to ignore.

  2. Continue string - I think this also does not make a ton of sense because we should be handling this value in the cache by getting all the values. I would imagine that this is not necessary to set.

and the only other field is ResourceVersion which we will need.

Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

It makes sense.
Re. Continue string, I found we currently don't support it in controller-runtime's ListOptions comparing to upstream ListOptions. So I guess we don't need to worry about it ATM.

Copy link
Member

Choose a reason for hiding this comment

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

@droot @DirectXMan12 thoughts regarding the reflection bits linked above?

Copy link
Author

Choose a reason for hiding this comment

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

I am pushing up an even better implementation in my mind. It will use api-machinery to manipulate the list, instead of using reflection directly.

}(ns, cache)
}
<-stopCh
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Should the multiNamespaceCache main goroutine wait for each cache goroutine to finish before returning?
Or it doesn't matter?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think that it matters, just following the pattern that I think we started here:
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/cache/internal/deleg_map.go#L60-L62

Thoughts?

@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from b8dca46 to 5559c19 Compare February 17, 2019 17:57
@shawn-hurley
Copy link
Author

@DirectXMan12 or @mengqiy can you guys re-start the build I think it was a flake.

Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

Using apimachinery helpers make it look much better!

pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from e2d83e8 to 72316bb Compare February 21, 2019 13:46
* Add Multinamespace Cache type
* ⚠️ Change the GetInformer methods to return a controller runtime Informer
interface
* Add multinamespace Informer type to handle namespaced infromers
* ⚠️ move NewCacheFunc from manager package to Cache pacakge
@shawn-hurley shawn-hurley force-pushed the feature/poc-multinamespaced-cache branch from 72316bb to fc804a4 Compare February 21, 2019 14:15
@mengqiy
Copy link
Member

mengqiy commented Feb 21, 2019

/lgtm
Let's wait by EOD before merging just in case others may want to take a look.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 21, 2019
@mengqiy mengqiy added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 22, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: shawn-hurley

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 merged commit 68ae79e into kubernetes-sigs:master Feb 22, 2019
@shawn-hurley shawn-hurley deleted the feature/poc-multinamespaced-cache branch February 22, 2019 18:41
ironcladlou added a commit to ironcladlou/controller-runtime that referenced this pull request Apr 3, 2019
Before fc804a4 (kubernetes-sigs#267), the `cache.Informers` interface methods returned
`k8s.io/client-go/tools/cache.SharedIndexInformer`s which were by default
compatible with the built-in `source.Informer`. Users could create arbitrary
`cache.Cache` instances (or get them from the `Manager`) and then use
`controller.Watch` to drive a controller with a `source.Informer` from the
`cache.Cache`.

With fc804a4, the `cache.Informers` interface was changed to return
`cache.Informer` instances; however, `source.Informer` was not updated to accept
a `cache.Informer`, and so users can no longer use the built-in
`source.Informer` with `cache.Cache`.

The `cache.Informer` interface appears to satisfy the needs of
`source.Informer`. This commit broadens `source.Informer` to accept a
`source.Informer`, restoring the prior capability while remaining compatible
with `SharedIndexInformer` use.
ironcladlou added a commit to ironcladlou/controller-runtime that referenced this pull request Apr 3, 2019
Before fc804a4 (kubernetes-sigs#267), the `cache.Informers` interface methods returned
`k8s.io/client-go/tools/cache.SharedIndexInformer`s which were by default
compatible with the built-in `source.Informer`. Users could create arbitrary
`cache.Cache` instances (or get them from the `Manager`) and then use
`controller.Watch` to drive a controller with a `source.Informer` from the
`cache.Cache`.

With fc804a4, the `cache.Informers` interface was changed to return
`cache.Informer` instances; however, `source.Informer` was not updated to accept
a `cache.Informer`, and so users can no longer use the built-in
`source.Informer` with `cache.Cache`.

The `cache.Informer` interface appears to satisfy the needs of
`source.Informer`. This commit broadens `source.Informer` to accept a
`cache.Informer`, restoring the prior capability while remaining compatible
with `SharedIndexInformer` use.
anthonyho007 pushed a commit to anthonyho007/controller-runtime that referenced this pull request Apr 12, 2019
Before fc804a4 (kubernetes-sigs#267), the `cache.Informers` interface methods returned
`k8s.io/client-go/tools/cache.SharedIndexInformer`s which were by default
compatible with the built-in `source.Informer`. Users could create arbitrary
`cache.Cache` instances (or get them from the `Manager`) and then use
`controller.Watch` to drive a controller with a `source.Informer` from the
`cache.Cache`.

With fc804a4, the `cache.Informers` interface was changed to return
`cache.Informer` instances; however, `source.Informer` was not updated to accept
a `cache.Informer`, and so users can no longer use the built-in
`source.Informer` with `cache.Cache`.

The `cache.Informer` interface appears to satisfy the needs of
`source.Informer`. This commit broadens `source.Informer` to accept a
`cache.Informer`, restoring the prior capability while remaining compatible
with `SharedIndexInformer` use.
vincepri pushed a commit to vincepri/controller-runtime that referenced this pull request Jul 24, 2019
Before fc804a4 (kubernetes-sigs#267), the `cache.Informers` interface methods returned
`k8s.io/client-go/tools/cache.SharedIndexInformer`s which were by default
compatible with the built-in `source.Informer`. Users could create arbitrary
`cache.Cache` instances (or get them from the `Manager`) and then use
`controller.Watch` to drive a controller with a `source.Informer` from the
`cache.Cache`.

With fc804a4, the `cache.Informers` interface was changed to return
`cache.Informer` instances; however, `source.Informer` was not updated to accept
a `cache.Informer`, and so users can no longer use the built-in
`source.Informer` with `cache.Cache`.

The `cache.Informer` interface appears to satisfy the needs of
`source.Informer`. This commit broadens `source.Informer` to accept a
`cache.Informer`, restoring the prior capability while remaining compatible
with `SharedIndexInformer` use.
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants