api

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

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"

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

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

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

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

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 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

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 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