Skip to content
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

Feat: Adding a short-cut for registering post-start hook #68

Merged
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
13 changes: 13 additions & 0 deletions pkg/builder/builder_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package builder
import (
"k8s.io/apimachinery/pkg/runtime"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/klog/v2"
openapicommon "k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/apiserver-runtime/internal/sample-apiserver/pkg/cmd/server"
"sigs.k8s.io/apiserver-runtime/pkg/util/loopback"
Expand All @@ -24,6 +25,18 @@ func (a *Server) WithOpenAPIDefinitions(
return a
}

// WithPostStartHook registers a post start hook which will be invoked after the apiserver is started
// and before it's ready for serving requests.
func (a *Server) WithPostStartHook(name string, hookFunc genericapiserver.PostStartHookFunc) *Server {
a.WithServerFns(func(server *GenericAPIServer) *GenericAPIServer {
if err := server.AddPostStartHook(name, hookFunc); err != nil {
klog.Fatal("failed registering post-start hook %v: %v", name, err)
}
return server
})
return a
}

// WithAdditionalSchemeInstallers registers functions to install additional functions or resources into the Scheme.
// This can be used to manually registering defaulting functions, conversion functions, or resource types, rather
// than registering them automatically by implementing the corresponding interfaces on the resources.
Expand Down