Skip to content

Commit cc5193a

Browse files
authoredMar 30, 2022
Merge pull request #68 from yue9944882/feat/post-start-hook-shortcut
Feat: Adding a short-cut for registering post-start hook
2 parents b96e1fb + 45e61ee commit cc5193a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎pkg/builder/builder_misc.go

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package builder
33
import (
44
"k8s.io/apimachinery/pkg/runtime"
55
genericapiserver "k8s.io/apiserver/pkg/server"
6+
"k8s.io/klog/v2"
67
openapicommon "k8s.io/kube-openapi/pkg/common"
78
"sigs.k8s.io/apiserver-runtime/internal/sample-apiserver/pkg/cmd/server"
89
"sigs.k8s.io/apiserver-runtime/pkg/util/loopback"
@@ -24,6 +25,18 @@ func (a *Server) WithOpenAPIDefinitions(
2425
return a
2526
}
2627

28+
// WithPostStartHook registers a post start hook which will be invoked after the apiserver is started
29+
// and before it's ready for serving requests.
30+
func (a *Server) WithPostStartHook(name string, hookFunc genericapiserver.PostStartHookFunc) *Server {
31+
a.WithServerFns(func(server *GenericAPIServer) *GenericAPIServer {
32+
if err := server.AddPostStartHook(name, hookFunc); err != nil {
33+
klog.Fatal("failed registering post-start hook %v: %v", name, err)
34+
}
35+
return server
36+
})
37+
return a
38+
}
39+
2740
// WithAdditionalSchemeInstallers registers functions to install additional functions or resources into the Scheme.
2841
// This can be used to manually registering defaulting functions, conversion functions, or resource types, rather
2942
// than registering them automatically by implementing the corresponding interfaces on the resources.

0 commit comments

Comments
 (0)
Please sign in to comment.