-
Notifications
You must be signed in to change notification settings - Fork 0
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
Kcp hacking #1
base: master
Are you sure you want to change the base?
Kcp hacking #1
Conversation
Clusterscope client
Add cluster scoped caches
pass clustername in context
Looks like all we need to do is modify the config to look at /clusters/*, that makes the controller watch events across admin and logical clusters.
Co-authored-by: Nick Hale <njohnhale@gmail.com>
Create minimal clusterscoped cache
update to latest kcp changes
pkg/cache/cache.go
Outdated
@@ -112,6 +112,9 @@ type Options struct { | |||
// Default watches all namespaces | |||
Namespace string | |||
|
|||
// ClusterName restricts cache's ListeWatch to the desired clusterscope | |||
ClusterName string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
|
||
import "k8s.io/client-go/rest" | ||
|
||
func MultiClusterMinCache() NewCacheFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can either remove and require user to pass in a rest config that is * scoped, or move to kcp-dev/apimachinery
pkg/client/client.go
Outdated
@@ -60,6 +60,9 @@ type Options struct { | |||
// Opts is used to configure the warning handler responsible for | |||
// surfacing and handling warnings messages sent by the API server. | |||
Opts WarningHandlerOptions | |||
|
|||
// Cluster refers to the name of the cluster this request is scoped to | |||
Cluster string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably remove this
pkg/client/options.go
Outdated
@@ -330,6 +330,9 @@ type ListOptions struct { | |||
// non-namespaced objects, or to list across all namespaces. | |||
Namespace string | |||
|
|||
// ClusterName refers to cluster from which to list objects | |||
ClusterName string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
pkg/client/typed_client.go
Outdated
createOpts := &CreateOptions{} | ||
createOpts.ApplyOptions(opts) | ||
return o.Post(). | ||
Cluster(clusterName). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing all of this to inject the cluster name here, see if instead we can supply a custom *http.Client
to some Options struct, and in pkg/client/apiutil/apimachinery.go near RESTClientForGVK
, add a new method that is RESTClientForGVKAndClient
. That way we can plumb through the kcp custom round tripper.
pkg/client/unstructured_client.go
Outdated
createOpts := &CreateOptions{} | ||
createOpts.ApplyOptions(opts) | ||
result := o.Post(). | ||
Cluster(clusterName). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as typed_client
@@ -33,10 +33,14 @@ func NewWithWatch(config *rest.Config, options Options) (WithWatch, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
dynamicClient, err := dynamic.NewForConfig(config) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo?
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &watchingClient{client: client, dynamic: dynamicClient}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to see what, if any, adjustments need to be made to work with * or cluster-specific watches.
@@ -41,25 +42,16 @@ func (e *EnqueueRequestForObject) Create(evt event.CreateEvent, q workqueue.Rate | |||
enqueueLog.Error(nil, "CreateEvent received with no metadata", "event", evt) | |||
return | |||
} | |||
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe write our own cluster-aware handlers in a separate kcp repo
Additional ideas from our chat:
|
Long term, if we want controller-runtime to work with kcp w/o any go.mod replace directives, controller-runtime will need
|
Edit: Ignore literally everything I say here Extending ObjectKey in a non-breaking way is proving to be pretty difficult due to the way embedded structs work, currently the usage/behavior is:
If I try to extend it in any way, I don't think it's possible to replicate that behavior. Ex:
Obviously incredibly easy to work around if we don't care about breaking changes but might make it hard to move this upstream as that's a pretty far-reaching change |
ctrl.SetLogger(zap.New()) | ||
|
||
cfg := ctrl.GetConfigOrDie() | ||
httpClient, err := rest.HTTPClientFor(cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably make a helper for this, like kcpclient.NewClientForConfig(cfg) that gives you an http.Client with the transport set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
ctrl.SetLogger(zap.New()) | ||
|
||
cfg := ctrl.GetConfigOrDie() | ||
httpClient, err := rest.HTTPClientFor(cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/cache/cache.go
Outdated
httpclient, err := rest.HTTPClientFor(config) | ||
if err != nil { | ||
log.WithName("setup").Error(err, "Failed to create HTTP client") | ||
return opts, fmt.Errorf("Could not create HTTPClient from config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return opts, fmt.Errorf("Could not create HTTPClient from config") | |
return opts, fmt.Errorf("could not create HTTPClient from config: %w", err) |
pkg/cache/cache.go
Outdated
if opts.HTTPClient == nil { | ||
httpclient, err := rest.HTTPClientFor(config) | ||
if err != nil { | ||
log.WithName("setup").Error(err, "Failed to create HTTP client") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need to both log and return an error?
@@ -26,7 +26,6 @@ import ( | |||
. "github.com/onsi/ginkgo" | |||
. "github.com/onsi/ginkgo/extensions/table" | |||
. "github.com/onsi/gomega" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo
@@ -54,7 +54,7 @@ type CacheReader struct { | |||
} | |||
|
|||
// Get checks the indexer for the object and writes a copy of it if found. | |||
func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Object) error { | |||
func (c *CacheReader) Get(ctx context.Context, key client.ObjectKey, out client.Object) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo?
pkg/cache/internal/informers_map.go
Outdated
@@ -54,9 +55,12 @@ func newSpecificInformersMap(config *rest.Config, | |||
namespace string, | |||
selectors SelectorsByGVK, | |||
disableDeepCopy DisableDeepCopyByGVK, | |||
createListWatcher createListWatcherFunc) *specificInformersMap { | |||
createListWatcher createListWatcherFunc, | |||
httpclient *http.Client) *specificInformersMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
httpclient *http.Client) *specificInformersMap { | |
httpClient *http.Client) *specificInformersMap { |
@@ -1,5 +1,5 @@ | |||
/* | |||
Copyright 2018 The Kubernetes Authors. | |||
opyright 2018 The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo
@@ -35,6 +36,9 @@ type clientCache struct { | |||
// config is the rest.Config to talk to an apiserver | |||
config *rest.Config | |||
|
|||
// httpclient is the httpClient to talk to an apiserver | |||
httpclient *http.Client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
httpclient *http.Client | |
httpClient *http.Client |
@@ -35,6 +36,9 @@ type clientCache struct { | |||
// config is the rest.Config to talk to an apiserver | |||
config *rest.Config | |||
|
|||
// httpclient is the httpClient to talk to an apiserver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// httpclient is the httpClient to talk to an apiserver | |
// httpClient is the http.Client to talk to an apiserver |
@@ -0,0 +1,85 @@ | |||
/* | |||
Copyright 2018 The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change copyright to kcp. Do you want to keep this in controller-runtime for now, or move to a kcp-owned repo?
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
more kcp plumbing
Controller-runtime allows building kcp-aware controllers
No description provided.