api

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 25 Imported by: 56

Documentation

Overview

Package api implements HTTP handlers for handling requests that the kubelet would normally implement, such as pod logs, exec, etc.

Index

Constants

View Source
const MetricsResourceRouteSuffix = "/metrics/resource"
View Source
const (
	PrometheusTextFormatContentType = "text/plain; version=0.0.4"
)

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 added in v1.9.0

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

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 added in v1.9.0

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 HandlePortForward added in v1.10.0

HandlePortForward makes an http handler func from a Provider which forward ports to a container Note that this handler currently depends on gorrilla/mux to get url parts as variables.

func HandleRunningPods

func HandleRunningPods(getPods PodListerFunc) http.HandlerFunc

func InstrumentHandler

func InstrumentHandler(h http.Handler) http.Handler

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 added in v1.9.0

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 added in v1.9.0

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 added in v1.3.0

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 added in v1.3.0

type ContainerExecHandlerOption func(*ContainerExecHandlerConfig)

ContainerExecHandlerOption configures a ContainerExecHandlerConfig It is used as functional options passed to `HandleContainerExec`

func WithExecStreamCreationTimeout added in v1.3.0

func WithExecStreamCreationTimeout(dur time.Duration) ContainerExecHandlerOption

WithExecStreamCreationTimeout sets the creation timeout for a container exec stream

func WithExecStreamIdleTimeout added in v1.3.0

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
	PortForward       PortForwardHandlerFunc
	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 PodListerFunc

type PodListerFunc func(context.Context) ([]*v1.Pod, error) //nolint:golint

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 added in v1.9.0

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

type PortForwardHandlerConfig added in v1.10.0

type PortForwardHandlerConfig 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
}

PortForwardHandlerConfig is used to pass options to options to the container exec handler.

type PortForwardHandlerFunc added in v1.10.0

type PortForwardHandlerFunc func(ctx context.Context, namespace, pod string, port int32, stream io.ReadWriteCloser) error

PortForwardHandlerFunc defines the handler function used to portforward, passing through the original dataStream

type PortForwardHandlerOption added in v1.10.0

type PortForwardHandlerOption func(*PortForwardHandlerConfig)

PortForwardHandlerOption configures a PortForwardHandlerConfig It is used as functional options passed to `HandlePortForward`

func WithPortForwardCreationTimeout added in v1.10.0

func WithPortForwardCreationTimeout(dur time.Duration) PortForwardHandlerOption

WithPortForwardCreationTimeout sets the creation timeout for a container exec stream

func WithPortForwardStreamIdleTimeout added in v1.10.0

func WithPortForwardStreamIdleTimeout(dur time.Duration) PortForwardHandlerOption

WithPortForwardStreamIdleTimeout sets the idle timeout for a container port forward streaming

type ServeMux

type ServeMux interface {
	Handle(path string, h http.Handler)
}

ServeMux defines an interface used to attach routes to an existing http serve mux. It is used to enable callers creating a new server to completely manage their own HTTP server while allowing us to attach the required routes to satisfy the Kubelet HTTP interfaces.

type TermSize

type TermSize struct {
	Width  uint16
	Height uint16
}

TermSize is used to set the terminal size from attached clients.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL