Skip to content

Commit 19d27c9

Browse files
dilyevskyclaude
andcommitted
[apiserver] Add WithOpenAPIDefinitions option for custom resources
Allow callers to provide custom OpenAPI definitions for resources registered with the apiserver. This enables external components (like infra-apiserver) to register their own types with proper OpenAPI schema support. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e28d330 commit 19d27c9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/apiserver/manager.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/client-go/kubernetes"
3232
"k8s.io/client-go/rest"
3333
"k8s.io/klog/v2"
34+
"k8s.io/kube-openapi/pkg/common"
3435
netutils "k8s.io/utils/net"
3536
"sigs.k8s.io/apiserver-runtime/pkg/builder"
3637
"sigs.k8s.io/apiserver-runtime/pkg/builder/resource"
@@ -193,6 +194,7 @@ type options struct {
193194
vniPool *vni.VNIPool
194195
tokenValidator token.Validator
195196
tokenIssuer token.TokenIssuer
197+
openAPIDefinitions common.GetOpenAPIDefinitions
196198
}
197199

198200
// WithJWTKeys sets the JWT key pair.
@@ -334,6 +336,16 @@ func WithResource(obj resource.Object) Option {
334336
}
335337
}
336338

339+
// WithOpenAPIDefinitions sets a custom OpenAPI definitions function.
340+
// If not provided, the default apoxy OpenAPI definitions will be used.
341+
// This is useful when registering custom resources that need their own
342+
// OpenAPI schema definitions.
343+
func WithOpenAPIDefinitions(getter common.GetOpenAPIDefinitions) Option {
344+
return func(o *options) {
345+
o.openAPIDefinitions = getter
346+
}
347+
}
348+
337349
// WithProxyIPAM sets the IPAM for proxy.
338350
func WithProxyIPAM(ipam tunnet.IPAM) Option {
339351
return func(o *options) {
@@ -793,8 +805,13 @@ func start(
793805
for _, r := range opts.resources {
794806
srvBuilder = srvBuilder.WithResourceAndStorage(r, kineStore)
795807
}
808+
// Use custom OpenAPI definitions if provided, otherwise use the default.
809+
openAPIGetter := opts.openAPIDefinitions
810+
if openAPIGetter == nil {
811+
openAPIGetter = apoxyopenapi.GetOpenAPIDefinitions
812+
}
796813
if err := srvBuilder.
797-
WithOpenAPIDefinitions("apoxy", "0.1.0", apoxyopenapi.GetOpenAPIDefinitions).
814+
WithOpenAPIDefinitions("apoxy", "0.1.0", openAPIGetter).
798815
DisableAuthorization().
799816
WithOptionsFns(func(o *builder.ServerOptions) *builder.ServerOptions {
800817
o.StdErr = io.Discard

0 commit comments

Comments
 (0)