vkubelet

package
v0.0.0-...-0deb509 Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Package vkubelet implements the core virtual-kubelet framework. It contains everything reuired to implement a virtuak-kubelet, including the core controller which reconciles pod states and API endpoints for things like pod logs, exec, attach, etc.

To get started, call the `New` with the appropriate config. When you are ready to start the controller, which registers the node and starts watching for pod changes, call `Run`. Taints can be used ensure the sceduler only schedules certain workloads to your virtual-kubelet.

vk := vkubelet.New(...)
// setup other things
...
vk.Run(ctx, ...)

After calling start, cancelling the passed in context will shutdown the controller.

Up to this point you have a running virtual kubelet controller, but no HTTP handlers to deal with requests forwarded from the API server for things like pod logs (e.g. user calls `kubectl logs myVKPod`). This package provides some helpers for this: `AttachPodRoutes` and `AttachMetricsRoutes`.

mux := http.NewServeMux()
vkubelet.AttachPodRoutes(provider, mux)

You must configure your own HTTP server, but these helpers will add handlers at the correct URI paths to your serve mux. You are not required to use go's built-in `*http.ServeMux`, but it does implement the `ServeMux` interface defined in this package which is used for these helpers.

Note: The metrics routes may need to be attached to a different HTTP server, depending on your configuration.

For more fine-grained control over the API, see the `vkubelet/api` package which only implements the HTTP handlers that you can use in whatever way you want.

This uses open-cenesus to implement tracing (but no internal metrics yet) which is propagated through the context. This is passed on even to the providers. We may look at supporting custom propagaters for providers who would like to use a different tracing format.

Index

Constants

View Source
const (
	// ReasonOptionalConfigMapNotFound is the reason used in events emitted when an optional configmap is not found.
	ReasonOptionalConfigMapNotFound = "OptionalConfigMapNotFound"
	// ReasonOptionalConfigMapKeyNotFound is the reason used in events emitted when an optional configmap key is not found.
	ReasonOptionalConfigMapKeyNotFound = "OptionalConfigMapKeyNotFound"
	// ReasonFailedToReadOptionalConfigMap is the reason used in events emitted when an optional configmap could not be read.
	ReasonFailedToReadOptionalConfigMap = "FailedToReadOptionalConfigMap"

	// ReasonOptionalSecretNotFound is the reason used in events emitted when an optional secret is not found.
	ReasonOptionalSecretNotFound = "OptionalSecretNotFound"
	// ReasonOptionalSecretKeyNotFound is the reason used in events emitted when an optional secret key is not found.
	ReasonOptionalSecretKeyNotFound = "OptionalSecretKeyNotFound"
	// ReasonFailedToReadOptionalSecret is the reason used in events emitted when an optional secret could not be read.
	ReasonFailedToReadOptionalSecret = "FailedToReadOptionalSecret"

	// ReasonMandatoryConfigMapNotFound is the reason used in events emitted when an mandatory configmap is not found.
	ReasonMandatoryConfigMapNotFound = "MandatoryConfigMapNotFound"
	// ReasonMandatoryConfigMapKeyNotFound is the reason used in events emitted when an mandatory configmap key is not found.
	ReasonMandatoryConfigMapKeyNotFound = "MandatoryConfigMapKeyNotFound"
	// ReasonFailedToReadMandatoryConfigMap is the reason used in events emitted when an mandatory configmap could not be read.
	ReasonFailedToReadMandatoryConfigMap = "FailedToReadMandatoryConfigMap"

	// ReasonMandatorySecretNotFound is the reason used in events emitted when an mandatory secret is not found.
	ReasonMandatorySecretNotFound = "MandatorySecretNotFound"
	// ReasonMandatorySecretKeyNotFound is the reason used in events emitted when an mandatory secret key is not found.
	ReasonMandatorySecretKeyNotFound = "MandatorySecretKeyNotFound"
	// ReasonFailedToReadMandatorySecret is the reason used in events emitted when an mandatory secret could not be read.
	ReasonFailedToReadMandatorySecret = "FailedToReadMandatorySecret"

	// ReasonInvalidEnvironmentVariableNames is the reason used in events emitted when a configmap/secret referenced in a ".spec.containers[*].envFrom" field contains invalid environment variable names.
	ReasonInvalidEnvironmentVariableNames = "InvalidEnvironmentVariableNames"
)
View Source
const (
	DefaultPingInterval         = 5 * time.Second
	DefaultStatusUpdateInterval = 1 * time.Minute
)

The default intervals used for lease and status updates.

Variables

This section is empty.

Functions

func AttachMetricsRoutes

func AttachMetricsRoutes(p providers.Provider, mux ServeMux)

AttachMetricsRoutes 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 providers.Provider, mux ServeMux)

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 InstrumentHandler

func InstrumentHandler(h http.Handler) http.Handler

InstrumentHandler wraps an http.Handler and injects instrumentation into the request context.

func MetricsSummaryHandler

func MetricsSummaryHandler(p providers.Provider) http.Handler

MetricsSummaryHandler creates an http handler for serving pod metrics.

If the passed in provider does not implement providers.PodMetricsProvider, it will create handlers that just serves http.StatusNotImplemented

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 PatchNodeStatus

func PatchNodeStatus(nodes v1.NodeInterface, nodeName types.NodeName, oldNode *corev1.Node, newNode *corev1.Node) (*corev1.Node, []byte, error)

PatchNodeStatus patches node status. Copied from github.com/kubernetes/kubernetes/pkg/util/node

func PodHandler

func PodHandler(p providers.Provider) http.Handler

PodHandler creates an http handler for interacting with pods/containers.

func UpdateNodeLease

func UpdateNodeLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error)

UpdateNodeLease updates the node lease.

If this function returns an errors.IsNotFound(err) error, this likely means that node leases are not supported, if this is the case, call UpdateNodeStatus instead.

If you use this function, it is up to you to syncronize this with other operations.

func UpdateNodeStatus

func UpdateNodeStatus(ctx context.Context, nodes v1.NodeInterface, n *corev1.Node) (*corev1.Node, error)

UpdateNodeStatus triggers an update to the node status in Kubernetes. It first fetches the current node details and then sets the status according to the passed in node object.

If you use this function, it is up to you to syncronize this with other operations. This reduces the time to second-level precision.

Types

type Config

type Config struct {
	Client          *kubernetes.Clientset
	Namespace       string
	NodeName        string
	Provider        providers.Provider
	ResourceManager *manager.ResourceManager
	PodSyncWorkers  int
	PodInformer     corev1informers.PodInformer
}

Config is used to configure a new server.

type NaiveNodeProvider

type NaiveNodeProvider struct{}

NaiveNodeProvider is a basic node provider that only uses the passed in context on `Ping` to determine if the node is healthy.

func (NaiveNodeProvider) NotifyNodeStatus

func (NaiveNodeProvider) NotifyNodeStatus(ctx context.Context, f func(*corev1.Node))

NotifyNodeStatus implements the NodeProvider interface.

This NaiveNodeProvider does not support updating node status and so this function is a no-op.

func (NaiveNodeProvider) Ping

Ping just implements the NodeProvider interface. It returns the error from the passed in context only.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node deals with creating and managing a node object in Kubernetes. It can register a node with Kubernetes and periodically update its status.

func NewNode

func NewNode(p providers.NodeProvider, node *corev1.Node, leases v1beta1.LeaseInterface, nodes v1.NodeInterface, opts ...NodeOpt) (*Node, error)

NewNode creates a new node. This does not have any side-effects on the system or kubernetes.

Use the node's `Run` method to register and run the loops to update the node in Kubernetes.

func (*Node) Run

func (n *Node) Run(ctx context.Context) error

Run registers the node in kubernetes and starts loops for updating the node status in Kubernetes.

The node status must be updated periodically in Kubertnetes to keep the node active. Newer versions of Kubernetes support node leases, which are essentially light weight pings. Older versions of Kubernetes require updating the node status periodically.

If Kubernetes supports node leases this will use leases with a much slower node status update (because some things still expect the node to be updated periodically), otherwise it will only use node status update with the configured ping interval.

type NodeOpt

type NodeOpt func(*Node) error

NodeOpt are the functional options used for configuring a node

func WithNodeDisableLease

func WithNodeDisableLease(v bool) NodeOpt

WithNodeDisableLease forces node leases to be disabled and to only update using node status Note that this will force status updates to occur on the ping interval frequency

func WithNodeLease

func WithNodeLease(l *coord.Lease) NodeOpt

WithNodeLease sets the base node lease to use. If a lease time is set, it will be ignored.

func WithNodePingInterval

func WithNodePingInterval(d time.Duration) NodeOpt

WithNodePingInterval sets the inteval for checking node status

func WithNodeStatusUpdateInterval

func WithNodeStatusUpdateInterval(d time.Duration) NodeOpt

WithNodeStatusUpdateInterval sets the interval for updating node status This is only used when leases are supported and only for updating the actual node status, not the node lease.

type PodController

type PodController struct {
	// contains filtered or unexported fields
}

PodController is the controller implementation for Pod resources.

func NewPodController

func NewPodController(server *Server) *PodController

NewPodController returns a new instance of PodController.

func (*PodController) Run

func (pc *PodController) Run(ctx context.Context, threadiness int) error

Run will set up the event handlers for types we are interested in, as well as syncing informer caches and starting workers. It will block until stopCh is closed, at which point it will shutdown the work queue and wait for workers to finish processing their current work items.

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 Server

type Server struct {
	// contains filtered or unexported fields
}

Server masquarades itself as a kubelet and allows for the virtual node to be backed by non-vm/node providers.

func New

func New(cfg Config) *Server

New creates a new virtual-kubelet server. This is the entrypoint to this package.

This creates but does not start the server. You must call `Run` on the returned object to start the server.

func (*Server) Ready

func (s *Server) Ready() <-chan struct{}

Ready returns a channel which will be closed once the VKubelet is running

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run creates and starts an instance of the pod controller, blocking until it stops.

Note that this does not setup the HTTP routes that are used to expose pod info to the Kubernetes API Server, such as logs, metrics, exec, etc. See `AttachPodRoutes` and `AttachMetricsRoutes` to set these up.

Directories

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

Jump to

Keyboard shortcuts

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