Documentation ¶
Index ¶
- func GinLogFormatter(layout string) func(param gin.LogFormatterParams) string
- func GinMuxer(muxer gin.IRouter) healthz.Muxer
- type CertKey
- type Factory
- func (f *Factory) Config() FactoryConfig
- func (f *Factory) DialOptions(opts ...grpc.DialOption) []grpc.DialOption
- func (f *Factory) GetBackendBindHostPort() string
- func (f *Factory) GetBackendExternalHostPort() string
- func (f *Factory) GetBackendServeHostPort(external bool) string
- func (f *Factory) HTTPScheme() string
- func (f *Factory) HttpHandlerDecorators(decorators ...http_.HandlerDecorator) []http_.HandlerDecorator
- func (f *Factory) New() (*WebServer, error)
- func (f *Factory) ResolveBackendLocalUrl(relativePaths ...string) string
- func (f *Factory) ResolveLocalIp() string
- func (f *Factory) ServeMuxOptions(opts ...runtime.ServeMuxOption) []runtime.ServeMuxOption
- func (f *Factory) ServerOptions(opts ...grpc.ServerOption) []grpc.ServerOption
- func (f *Factory) StreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) []grpc.StreamClientInterceptor
- func (f *Factory) StreamServerInterceptors(interceptors ...grpc.StreamServerInterceptor) []grpc.StreamServerInterceptor
- func (f *Factory) UnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) []grpc.UnaryClientInterceptor
- func (f *Factory) UnaryHandlers(handlers ...grpc_.UnaryHandlerDecorator) []grpc_.UnaryHandlerDecorator
- func (f *Factory) UnaryServerInterceptors(interceptors ...grpc.UnaryServerInterceptor) []grpc.UnaryServerInterceptor
- type FactoryConfig
- type FactoryConfigFunc
- type LocalIpResolver
- type Net
- type PostStartHookFunc
- type PostStartHookProvider
- type PreShutdownHookFunc
- type TLS
- type WebHandler
- type WebServer
- func (s *WebServer) AddBootSequenceHealthChecks(checks ...healthz.HealthChecker) error
- func (s *WebServer) AddBootSequencePostStartHook(name string, hook PostStartHookFunc) error
- func (s *WebServer) AddBootSequencePreShutdownHook(name string, hook PreShutdownHookFunc) error
- func (s *WebServer) AddHealthChecks(checks ...healthz.HealthChecker) error
- func (s *WebServer) AddPostStartHook(name string, hook PostStartHookFunc) error
- func (s *WebServer) AddPostStartHookOrDie(name string, hook PostStartHookFunc)
- func (s *WebServer) AddPreShutdownHook(name string, hook PreShutdownHookFunc) error
- func (s *WebServer) AddPreShutdownHookOrDie(name string, hook PreShutdownHookFunc)
- func (s *WebServer) InstallWebHandlers(handlers ...WebHandler)
- func (s *WebServer) PrepareRun() (preparedWebServer, error)
- func (s *WebServer) RunPostStartHooks(ctx context.Context) error
- func (s *WebServer) RunPreShutdownHooks() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GinLogFormatter ¶ added in v1.2.99
func GinLogFormatter(layout string) func(param gin.LogFormatterParams) string
GinLogFormatter is the log format function gin.Logger middleware uses.
Types ¶
type CertKey ¶
type CertKey struct { Cert string // public key, containing a PEM-encoded certificate, and possibly the complete certificate chain Key string // private key, containing a PEM-encoded private key for the certificate specified by CertFile }
CertKey a public/private key pair
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
func NewFactory ¶
func NewFactory(fc FactoryConfig, configs ...FactoryConfigFunc) (Factory, error)
func (*Factory) Config ¶
func (f *Factory) Config() FactoryConfig
func (*Factory) DialOptions ¶ added in v1.2.120
func (f *Factory) DialOptions(opts ...grpc.DialOption) []grpc.DialOption
func (*Factory) GetBackendBindHostPort ¶
GetBackendBindHostPort returns a address to listen.
func (*Factory) GetBackendExternalHostPort ¶
GetBackendExternalHostPort returns an address to expose with domain, if not set, use host instead.
func (*Factory) GetBackendServeHostPort ¶
GetBackendServeHostPort returns an address to expose without domain, if not set, use resolver to resolve an ip
func (*Factory) HTTPScheme ¶
func (*Factory) HttpHandlerDecorators ¶ added in v1.2.120
func (f *Factory) HttpHandlerDecorators(decorators ...http_.HandlerDecorator) []http_.HandlerDecorator
func (*Factory) New ¶
New creates a new server which logically combines the handling chain with the passed server. name is used to differentiate for logging. The handler chain in particular can be difficult as it starts delgating.
func (*Factory) ResolveBackendLocalUrl ¶
func (*Factory) ResolveLocalIp ¶
func (*Factory) ServeMuxOptions ¶ added in v1.2.120
func (f *Factory) ServeMuxOptions(opts ...runtime.ServeMuxOption) []runtime.ServeMuxOption
func (*Factory) ServerOptions ¶ added in v1.2.120
func (f *Factory) ServerOptions(opts ...grpc.ServerOption) []grpc.ServerOption
func (*Factory) StreamClientInterceptors ¶ added in v1.2.120
func (f *Factory) StreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) []grpc.StreamClientInterceptor
func (*Factory) StreamServerInterceptors ¶ added in v1.2.120
func (f *Factory) StreamServerInterceptors(interceptors ...grpc.StreamServerInterceptor) []grpc.StreamServerInterceptor
func (*Factory) UnaryClientInterceptors ¶ added in v1.2.120
func (f *Factory) UnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) []grpc.UnaryClientInterceptor
func (*Factory) UnaryHandlers ¶ added in v1.2.120
func (f *Factory) UnaryHandlers(handlers ...grpc_.UnaryHandlerDecorator) []grpc_.UnaryHandlerDecorator
UnaryHandlers returns new unary server handlers.
gRPC-Gateway does not support gRPC interceptors when call gRPC's service handler in process. See: https://github.com/grpc-ecosystem/grpc-gateway/issues/1043
func (*Factory) UnaryServerInterceptors ¶ added in v1.2.120
func (f *Factory) UnaryServerInterceptors(interceptors ...grpc.UnaryServerInterceptor) []grpc.UnaryServerInterceptor
type FactoryConfig ¶
type FactoryConfig struct { // Name is the human-readable server name, optional Name string // BindAddress is the host port to bind to (local internet) // Will default to a value based on secure serving info and available ipv4 IPs. BindAddress string // ExternalAddress is the address advertised, even if BindAddress is a loopback. By default, this // is set to BindAddress if the later no loopback, or to the first host interface address. ExternalAddress string // ShutdownDelayDuration allows to block shutdown for some time, e.g. until endpoints pointing to this API server // have converged on all node. During this time, the API server keeps serving, /healthz will return 200, // but /readyz will return failure. ShutdownDelayDuration time.Duration TlsConfig *tls.Config Cors cors.Options // for cors ForceDisableTls bool // disable tls LocalIpResolver *LocalIpResolver // for resolve local ip to expose, used if advertise_addr is empty NoGrpcProxy bool // disable http proxy for grpc client to connect grpc server PreferRegisterHTTPFromEndpoint bool // prefer register http handler from endpoint // grpc middlewares MaxConcurrencyUnary int // for concurrent parallel requests of unary server, The default is 0 (no limit is given) MaxConcurrencyStream int // for concurrent parallel requests of stream server, The default is 0 (no limit is given) BurstLimitTimeoutUnary time.Duration // for concurrent parallel requests of unary server, The default is 0 (no limit is given) BurstLimitTimeoutStream time.Duration // for concurrent parallel requests of stream server, The default is 0 (no limit is given) HandledTimeoutUnary time.Duration // for max handing time of unary server, The default is 0 (no limit is given) HandledTimeoutStream time.Duration // for max handing time of unary server, The default is 0 (no limit is given) MaxReceiveMessageSizeInBytes int // sets the maximum message size in bytes the grpc server can receive, The default is 0 (no limit is given). MaxSendMessageSizeInBytes int // sets the maximum message size in bytes the grpc server can send, The default is 0 (no limit is given). StatsHandling bool // log for the related stats handling (e.g., RPCs, connections). Validator *validator.Validate // for value validations for structs and individual fields based on tags (e.g., request). FillRequestId bool // for the field "RequestId" filling in Request and Response. OtelHandling bool // captures traces and metrics and send them to an observability platform by OpenTelemetry. // Deprecated: takes no effect, use slog instead. EnableLogrusMiddleware bool // disable logrus middleware GatewayOptions []grpc_.GatewayOption GinMiddlewares []gin.HandlerFunc }
FactoryConfig Config of Factory
func (*FactoryConfig) SetDefaults ¶
func (fc *FactoryConfig) SetDefaults()
SetDefaults sets sensible values for unset fields in config. This is exported for testing: Configs passed to repository functions are copied and have default values set automatically.
func (*FactoryConfig) Validate ¶
func (fc *FactoryConfig) Validate() error
Validate inspects the fields of the type to determine if they are valid.
type FactoryConfigFunc ¶
type FactoryConfigFunc func(os *FactoryConfig) error
FactoryConfigFunc is an alias for a function that will take in a pointer to an FactoryConfig and modify it
type LocalIpResolver ¶
type PostStartHookFunc ¶
PostStartHookFunc is a function that is called after the server has started. It must properly handle cases like:
- asynchronous start in multiple API server processes
- conflicts between the different processes all trying to perform the same action
- partially complete work (API server crashes while running your hook)
- API server access **BEFORE** your hook has completed
Think of it like a mini-controller that is super privileged and gets to run in-process If you use this feature, tag @deads2k on github who has promised to review code for anyone's PostStartHook until it becomes easier to use. ctx will be cancelled when WebServer is Closed or any other PostStartHookFunc failed.
type PostStartHookProvider ¶
type PostStartHookProvider interface {
PostStartHook() (string, PostStartHookFunc, error)
}
PostStartHookProvider is an interface in addition to provide a post start hook for the api server
type PreShutdownHookFunc ¶
type PreShutdownHookFunc func() error
PreShutdownHookFunc is a function that can be added to the shutdown logic.
type TLS ¶
type TLS struct { Enable bool KeyPairBase64 *CertKey // key pair in base64 format encoded from pem KeyPairPath *CertKey // key pair stored in file from pem // service_name is used to verify the hostname on the returned // certificates unless InsecureSkipVerify is given. It is also included // in the client's handshake to support virtual hosting unless it is // an IP address. ServiceName string AllowedTlsCidrs []string //"127.0.0.1/24" WhitelistedPaths []string }
type WebHandler ¶
type WebServer ¶
type WebServer struct { Name string // BindAddress is the host name to use for bind (local internet) facing URLs (e.g. Loopback) // Will default to a value based on secure serving info and available ipv4 IPs. BindAddress string // ExternalAddress is the host name to use for external (public internet) facing URLs (e.g. Swagger) // Will default to a value based on secure serving info and available ipv4 IPs. ExternalAddress string PreferRegisterHTTPFromEndpoint bool // prefer register http handler from endpoint // ShutdownDelayDuration allows to block shutdown for some time, e.g. until endpoints pointing to this API server // have converged on all node. During this time, the API server keeps serving, /healthz will return 200, // but /readyz will return failure. ShutdownDelayDuration time.Duration // ShutdownTimeout is the timeout used for server shutdown. This specifies the timeout before server // gracefully shutdown returns. ShutdownTimeout time.Duration // contains filtered or unexported fields }
func NewWebServer ¶
func NewWebServer(fc FactoryConfig, configs ...FactoryConfigFunc) (*WebServer, error)
func (*WebServer) AddBootSequenceHealthChecks ¶
func (s *WebServer) AddBootSequenceHealthChecks(checks ...healthz.HealthChecker) error
AddBootSequenceHealthChecks adds health checks to the old healthz endpoint (for backwards compatibility reasons) as well as livez and readyz. The livez grace period is defined by the value of the command-line flag --livez-grace-period; before the grace period elapses, the livez health checks will default to healthy. One may want to set a grace period in order to prevent the kubelet from restarting the kube-apiserver due to long-ish boot sequences. Readyz health checks, on the other hand, have no grace period, since readyz should fail until boot fully completes.
func (*WebServer) AddBootSequencePostStartHook ¶ added in v1.2.111
func (s *WebServer) AddBootSequencePostStartHook(name string, hook PostStartHookFunc) error
AddBootSequencePostStartHook allows you to add a PostStartHook in order.
func (*WebServer) AddBootSequencePreShutdownHook ¶ added in v1.2.111
func (s *WebServer) AddBootSequencePreShutdownHook(name string, hook PreShutdownHookFunc) error
AddBootSequencePreShutdownHook allows you to add a PreShutdownHook in reverse order.
func (*WebServer) AddHealthChecks ¶
func (s *WebServer) AddHealthChecks(checks ...healthz.HealthChecker) error
AddHealthChecks adds HealthCheck(s) to health endpoints (healthz, livez, readyz) but configures the liveness grace period to be zero, which means we expect this health check to immediately indicate that the apiserver is unhealthy.
func (*WebServer) AddPostStartHook ¶
func (s *WebServer) AddPostStartHook(name string, hook PostStartHookFunc) error
AddPostStartHook allows you to add a PostStartHook.
func (*WebServer) AddPostStartHookOrDie ¶
func (s *WebServer) AddPostStartHookOrDie(name string, hook PostStartHookFunc)
AddPostStartHookOrDie allows you to add a PostStartHook, but dies on failure
func (*WebServer) AddPreShutdownHook ¶
func (s *WebServer) AddPreShutdownHook(name string, hook PreShutdownHookFunc) error
AddPreShutdownHook allows you to add a PreShutdownHook.
func (*WebServer) AddPreShutdownHookOrDie ¶
func (s *WebServer) AddPreShutdownHookOrDie(name string, hook PreShutdownHookFunc)
AddPreShutdownHookOrDie allows you to add a PostStartHook, but dies on failure
func (*WebServer) InstallWebHandlers ¶
func (s *WebServer) InstallWebHandlers(handlers ...WebHandler)
func (*WebServer) PrepareRun ¶
PrepareRun does post API installation setup steps. It calls recursively the same function of the delegates.
func (*WebServer) RunPostStartHooks ¶
RunPostStartHooks runs the PostStartHooks for the server
func (*WebServer) RunPreShutdownHooks ¶
RunPreShutdownHooks runs the PreShutdownHooks for the server