Skip to content

Commit

Permalink
Merge pull request #68 from yue9944882/feat/post-start-hook-shortcut
Browse files Browse the repository at this point in the history
Feat: Adding a short-cut for registering post-start hook
  • Loading branch information
k8s-ci-robot authored Mar 30, 2022
2 parents b96e1fb + 45e61ee commit cc5193a
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit cc5193a

Please sign in to comment.