Documentation ¶
Overview ¶
Package api implements HTTP handlers for handling requests that the kubelet would normally implement, such as pod logs, exec, etc.
Index ¶
- Constants
- func AttachPodMetricsRoutes(p PodMetricsConfig, mux ServeMux)
- func AttachPodRoutes(p PodHandlerConfig, mux ServeMux, debug bool)
- func HandleContainerAttach(h ContainerAttachHandlerFunc, opts ...ContainerExecHandlerOption) http.HandlerFunc
- func HandleContainerExec(h ContainerExecHandlerFunc, opts ...ContainerExecHandlerOption) http.HandlerFunc
- func HandleContainerLogs(h ContainerLogsHandlerFunc) http.HandlerFunc
- func HandlePodMetricsResource(h PodMetricsResourceHandlerFunc) http.HandlerFunc
- func HandlePodStatsSummary(h PodStatsSummaryHandlerFunc) http.HandlerFunc
- func HandleRunningPods(getPods PodListerFunc) http.HandlerFunc
- func InstrumentHandler(h http.Handler) http.Handler
- func NotFound(w http.ResponseWriter, r *http.Request)
- func NotImplemented(w http.ResponseWriter, r *http.Request)
- func PodHandler(p PodHandlerConfig, debug bool) http.Handler
- func PodMetricsResourceHandler(f PodMetricsResourceHandlerFunc) http.Handler
- func PodStatsSummaryHandler(f PodStatsSummaryHandlerFunc) http.Handler
- type AttachIO
- type ContainerAttachHandlerFunc
- type ContainerExecHandlerConfig
- type ContainerExecHandlerFunc
- type ContainerExecHandlerOption
- type ContainerLogOpts
- type ContainerLogsHandlerFunc
- type PodHandlerConfig
- type PodListerFunc
- type PodMetricsConfig
- type PodMetricsResourceHandlerFunc
- type PodStatsSummaryHandlerFunc
- type ServeMux
- type TermSize
Constants ¶
const MetricsResourceRouteSuffix = "/metrics/resource"
Variables ¶
This section is empty.
Functions ¶
func AttachPodMetricsRoutes ¶
func AttachPodMetricsRoutes(p PodMetricsConfig, mux ServeMux)
AttachPodMetricsRoutes adds the http routes for pod/node metrics to the passed in serve mux.
Callers should take care to namespace the serve mux as they see fit, however these routes get called by the Kubernetes API server.
func AttachPodRoutes ¶
func AttachPodRoutes(p PodHandlerConfig, mux ServeMux, debug bool)
AttachPodRoutes adds the http routes for pod stuff to the passed in serve mux.
Callers should take care to namespace the serve mux as they see fit, however these routes get called by the Kubernetes API server.
func HandleContainerAttach ¶
func HandleContainerAttach(h ContainerAttachHandlerFunc, opts ...ContainerExecHandlerOption) http.HandlerFunc
HandleContainerAttach makes an http handler func from a Provider which execs a command in a pod's container Note that this handler currently depends on gorrilla/mux to get url parts as variables. TODO(@cpuguy83): don't force gorilla/mux on consumers of this function
func HandleContainerExec ¶
func HandleContainerExec(h ContainerExecHandlerFunc, opts ...ContainerExecHandlerOption) http.HandlerFunc
HandleContainerExec makes an http handler func from a Provider which execs a command in a pod's container Note that this handler currently depends on gorrilla/mux to get url parts as variables. TODO(@cpuguy83): don't force gorilla/mux on consumers of this function
func HandleContainerLogs ¶
func HandleContainerLogs(h ContainerLogsHandlerFunc) http.HandlerFunc
HandleContainerLogs creates an http handler function from a provider to serve logs from a pod
func HandlePodMetricsResource ¶
func HandlePodMetricsResource(h PodMetricsResourceHandlerFunc) http.HandlerFunc
HandlePodMetricsResource makes an HTTP handler for implementing the kubelet /metrics/resource endpoint
func HandlePodStatsSummary ¶
func HandlePodStatsSummary(h PodStatsSummaryHandlerFunc) http.HandlerFunc
HandlePodStatsSummary makes an HTTP handler for implementing the kubelet summary stats endpoint
func HandleRunningPods ¶
func HandleRunningPods(getPods PodListerFunc) http.HandlerFunc
func InstrumentHandler ¶
InstrumentHandler wraps an http.Handler and injects instrumentation into the request context.
func NotFound ¶
func NotFound(w http.ResponseWriter, r *http.Request)
NotFound provides a handler for cases where the requested endpoint doesn't exist
func NotImplemented ¶
func NotImplemented(w http.ResponseWriter, r *http.Request)
NotImplemented provides a handler for cases where a provider does not implement a given API
func PodHandler ¶
func PodHandler(p PodHandlerConfig, debug bool) http.Handler
PodHandler creates an http handler for interacting with pods/containers.
func PodMetricsResourceHandler ¶
func PodMetricsResourceHandler(f PodMetricsResourceHandlerFunc) http.Handler
PodMetricsResourceHandler creates an http handler for serving pod metrics.
If the passed in handler func is nil this will create handlers which only serves http.StatusNotImplemented
func PodStatsSummaryHandler ¶
func PodStatsSummaryHandler(f PodStatsSummaryHandlerFunc) http.Handler
PodStatsSummaryHandler creates an http handler for serving pod metrics.
If the passed in handler func is nil this will create handlers which only serves http.StatusNotImplemented
Types ¶
type AttachIO ¶
type AttachIO interface { Stdin() io.Reader Stdout() io.WriteCloser Stderr() io.WriteCloser TTY() bool Resize() <-chan TermSize }
AttachIO is used to pass in streams to attach to a container process
type ContainerAttachHandlerFunc ¶
type ContainerAttachHandlerFunc func(ctx context.Context, namespace, podName, containerName string, attach AttachIO) error
ContainerAttachHandlerFunc defines the handler function used for "execing" into a container in a pod.
type ContainerExecHandlerConfig ¶
type ContainerExecHandlerConfig struct { // StreamIdleTimeout is the maximum time a streaming connection // can be idle before the connection is automatically closed. StreamIdleTimeout time.Duration // StreamCreationTimeout is the maximum time for streaming connection StreamCreationTimeout time.Duration }
ContainerExecHandlerConfig is used to pass options to options to the container exec handler.
type ContainerExecHandlerFunc ¶
type ContainerExecHandlerFunc func(ctx context.Context, namespace, podName, containerName string, cmd []string, attach AttachIO) error
ContainerExecHandlerFunc defines the handler function used for "execing" into a container in a pod.
type ContainerExecHandlerOption ¶
type ContainerExecHandlerOption func(*ContainerExecHandlerConfig)
ContainerExecHandlerOption configures a ContainerExecHandlerConfig It is used as functional options passed to `HandleContainerExec`
func WithExecStreamCreationTimeout ¶
func WithExecStreamCreationTimeout(dur time.Duration) ContainerExecHandlerOption
WithExecStreamCreationTimeout sets the creation timeout for a container exec stream
func WithExecStreamIdleTimeout ¶
func WithExecStreamIdleTimeout(dur time.Duration) ContainerExecHandlerOption
WithExecStreamIdleTimeout sets the idle timeout for a container exec stream
type ContainerLogOpts ¶
type ContainerLogOpts struct { Tail int LimitBytes int Timestamps bool Follow bool Previous bool SinceSeconds int SinceTime time.Time }
ContainerLogOpts are used to pass along options to be set on the container log stream.
type ContainerLogsHandlerFunc ¶
type ContainerLogsHandlerFunc func(ctx context.Context, namespace, podName, containerName string, opts ContainerLogOpts) (io.ReadCloser, error)
ContainerLogsHandlerFunc is used in place of backend implementations for getting container logs
type PodHandlerConfig ¶
type PodHandlerConfig struct { RunInContainer ContainerExecHandlerFunc AttachToContainer ContainerAttachHandlerFunc GetContainerLogs ContainerLogsHandlerFunc // GetPods is meant to enumerate the pods that the provider knows about GetPods PodListerFunc // GetPodsFromKubernetes is meant to enumerate the pods that the node is meant to be running GetPodsFromKubernetes PodListerFunc GetStatsSummary PodStatsSummaryHandlerFunc GetMetricsResource PodMetricsResourceHandlerFunc StreamIdleTimeout time.Duration StreamCreationTimeout time.Duration }
type PodMetricsConfig ¶
type PodMetricsConfig struct { GetStatsSummary PodStatsSummaryHandlerFunc GetMetricsResource PodMetricsResourceHandlerFunc }
PodMetricsConfig stores the handlers for pod metrics routes It is used by AttachPodMetrics.
The main reason for this struct is in case of expansion we do not need to break the package level API.
type PodMetricsResourceHandlerFunc ¶
type PodMetricsResourceHandlerFunc func(context.Context) ([]*dto.MetricFamily, error)
PodMetricsResourceHandlerFunc defines the handler for getting pod metrics
type PodStatsSummaryHandlerFunc ¶
type PodStatsSummaryHandlerFunc func(context.Context) (*statsv1alpha1.Summary, error)
PodStatsSummaryHandlerFunc defines the handler for getting pod stats summaries