Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apiexport/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import (

"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
toolscache "k8s.io/client-go/tools/cache"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
Expand Down Expand Up @@ -92,15 +94,15 @@ type Options struct {
func New(cfg *rest.Config, endpointSliceName string, options Options) (*Provider, error) {
// Do the defaulting controller-runtime would do for those fields we need.
if options.Scheme == nil {
return nil, fmt.Errorf("scheme must be provided")
options.Scheme = scheme.Scheme
Copy link
Contributor

Choose a reason for hiding this comment

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

This is open to discussion. The problem is that if one uses a dedicated schema object when initialising this code, it will not work as the schemas will not match. So, should we be explicit here and ask the user to provide the schema, or are we ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case we can use the scheme from client-go, since controller-runtime has the same default:
https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/cluster/cluster.go#L264

}

if options.ObjectToWatch == nil {
options.ObjectToWatch = &apisv1alpha1.APIBinding{}
}

if options.Log == nil {
l := log.Log.WithName("kcp-apiexport-cluster-provider")
options.Log = &l
options.Log = ptr.To(log.Log.WithName("kcp-apiexport-cluster-provider"))
}

c, err := cache.New(cfg, cache.Options{
Expand All @@ -115,10 +117,9 @@ func New(cfg *rest.Config, endpointSliceName string, options Options) (*Provider
return nil, err
}

clusters := clusters.New[cluster.Cluster]()
return &Provider{
// func to pass into iner provider to lifecycle clusters
clusters: &clusters,
clusters: ptr.To(clusters.New[cluster.Cluster]()),
providers: map[string]*provider.Provider{},

config: cfg,
Expand Down