Skip to content

Commit 4257ba3

Browse files
authored
Merge pull request #22 from embik/apiexport-vw-option
apiexport: make object to watch optional, default to `APIBindings`
2 parents 65529bf + 2932315 commit 4257ba3

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $(YQ):
7373
yq_*
7474

7575
KCP = _tools/kcp
76-
KCP_VERSION = 0.26.1
76+
KCP_VERSION = 0.27.1
7777

7878
.PHONY: $(KCP)
7979
$(KCP):

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")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.23.5
55
require (
66
github.com/go-logr/logr v1.4.2
77
github.com/hashicorp/golang-lru/v2 v2.0.7
8-
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20240817110845-a9eb9752bfeb
9-
github.com/kcp-dev/kcp/sdk v0.26.1
8+
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3
9+
github.com/kcp-dev/kcp/sdk v0.27.1
1010
github.com/kcp-dev/logicalcluster/v3 v3.0.5
1111
github.com/martinlindhe/base36 v1.1.1
1212
github.com/onsi/ginkgo/v2 v2.22.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
6767
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
6868
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
6969
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
70-
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20240817110845-a9eb9752bfeb h1:W11F/dp6NdUnHeB0SrpyWLiifRosu1qaMJvdFGGLXc0=
71-
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20240817110845-a9eb9752bfeb/go.mod h1:mEDD1K5BVUXJ4CP6wcJ0vZUf+7tbFMjkCFzBKsUNj18=
72-
github.com/kcp-dev/kcp/sdk v0.26.1 h1:kzowAqlO6gfSmNFOXtcskg0tOhd8etG72XqvW06BUb0=
73-
github.com/kcp-dev/kcp/sdk v0.26.1/go.mod h1:XjabYVlKkpuRr1qATymS0gMTEjC6McuuwdoVGSar2fE=
70+
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3 h1:YwNX7ZIpQXg9u5vav/fobmf4nnO0WhbELWaL3X74Oe4=
71+
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3/go.mod h1:n0+EV+LGKl1MXXqGbGcn0AaBv7hdKsdazSYuq8nM8Us=
72+
github.com/kcp-dev/kcp/sdk v0.27.1 h1:jBVdrZoJd5hy2RqaBnmCCzldimwOqDkf8FXtNq5HaWA=
73+
github.com/kcp-dev/kcp/sdk v0.27.1/go.mod h1:3eRgW42d81Ng60DbG1xbne0FSS2znpcN/GUx4rqJgUo=
7474
github.com/kcp-dev/logicalcluster/v3 v3.0.5 h1:JbYakokb+5Uinz09oTXomSUJVQsqfxEvU4RyHUYxHOU=
7575
github.com/kcp-dev/logicalcluster/v3 v3.0.5/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY=
7676
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

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)