Skip to content

Commit 2932315

Browse files
committed
Make passing object to watch optional, default to APIBindings
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent 68b1ad3 commit 2932315

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

apiexport/provider.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"sigs.k8s.io/multicluster-runtime/pkg/multicluster"
4040

4141
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
42+
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
4243
"github.com/kcp-dev/logicalcluster/v3"
4344
)
4445

@@ -70,13 +71,21 @@ type Options struct {
7071
// WildcardCache is the wildcard cache to use for the provider. If this is
7172
// nil, a new wildcard cache will be created for the given rest.Config.
7273
WildcardCache WildcardCache
74+
75+
// ObjectToWatch is the object type that the provider watches via a /clusters/*
76+
// wildcard endpoint to extract information about logical clusters joining and
77+
// leaving the "fleet" of (logical) clusters in kcp. If this is nil, it defaults
78+
// to [apisv1alpha1.APIBinding]. This might be useful when using this provider
79+
// against custom virtual workspaces that are not the APIExport one but share
80+
// the same endpoint semantics.
81+
ObjectToWatch client.Object
7382
}
7483

7584
// New creates a new kcp virtual workspace provider. The provided [rest.Config]
7685
// must point to a virtual workspace apiserver base path, i.e. up to but without
7786
// the '/clusters/*' suffix. This information can be extracted from the APIExport
7887
// status (deprecated) or an APIExportEndpointSlice status.
79-
func New(cfg *rest.Config, obj client.Object, options Options) (*Provider, error) {
88+
func New(cfg *rest.Config, options Options) (*Provider, error) {
8089
// Do the defaulting controller-runtime would do for those fields we need.
8190
if options.Scheme == nil {
8291
options.Scheme = scheme.Scheme
@@ -90,14 +99,17 @@ func New(cfg *rest.Config, obj client.Object, options Options) (*Provider, error
9099
return nil, fmt.Errorf("failed to create wildcard cache: %w", err)
91100
}
92101
}
102+
if options.ObjectToWatch == nil {
103+
options.ObjectToWatch = &apisv1alpha1.APIBinding{}
104+
}
93105

94106
return &Provider{
95107
config: cfg,
96108
scheme: options.Scheme,
97109
cache: options.WildcardCache,
98-
object: obj,
110+
object: options.ObjectToWatch,
99111

100-
log: log.Log.WithName("kcp-virtualworkspace-cluster-provider"),
112+
log: log.Log.WithName("kcp-apiexport-cluster-provider"),
101113

102114
clusters: map[logicalcluster.Name]cluster.Cluster{},
103115
cancelFns: map[logicalcluster.Name]context.CancelFunc{},

examples/apiexport/main.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,12 @@ func main() {
7979
opts := manager.Options{}
8080

8181
var err error
82-
provider, err = apiexport.New(cfg, &apisv1alpha1.APIBinding{}, apiexport.Options{})
82+
provider, err = apiexport.New(cfg, apiexport.Options{})
8383
if err != nil {
8484
entryLog.Error(err, "unable to construct cluster provider")
8585
os.Exit(1)
8686
}
8787

88-
cfg.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
89-
return RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
90-
fmt.Println(r.URL)
91-
return rt.RoundTrip(r)
92-
})
93-
}
94-
9588
mgr, err := mcmanager.New(cfg, provider, opts)
9689
if err != nil {
9790
entryLog.Error(err, "unable to set up overall controller manager")

test/e2e/apiexport_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ var _ = Describe("VirtualWorkspace Provider", Ordered, func() {
234234
vwConfig := rest.CopyConfig(kcpConfig)
235235
vwConfig.Host = vwEndpoint
236236
var err error
237-
p, err = apiexport.New(vwConfig, &apisv1alpha1.APIBinding{}, apiexport.Options{})
237+
p, err = apiexport.New(vwConfig, apiexport.Options{})
238238
Expect(err).NotTo(HaveOccurred())
239239

240240
By("waiting for discovery of the virtual workspace to show 'example.com'")

0 commit comments

Comments
 (0)