virtual_kubelet

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRenewIntervalFraction is the fraction of lease duration to renew the lease
	DefaultRenewIntervalFraction = 0.25

	// DefaultLeaseDuration is from upstream kubelet, where the default lease duration is 40 seconds
	DefaultLeaseDuration = 40
)
View Source
const (
	DefaultPingInterval         = 10 * time.Second
	DefaultStatusUpdateInterval = 1 * time.Minute
)

The default intervals used for lease and status updates.

Variables

View Source
var (
	// ErrConflictingLeaseControllerConfiguration is returned when the lease controller related options have been
	// specified multiple times
	ErrConflictingLeaseControllerConfiguration = pkgerrors.New("Multiple, conflicting lease configurations have been put into place")
)

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(context.Context, error) error

ErrorHandler is a type of function used to allow callbacks for handling errors. It is expected that if a nil error is returned that the error is handled and progress can continue (or a retry is possible).

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 (n NaiveNodeProvider) NotifyNodeStatus(_ context.Context, _ 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 NaiveNodeProviderV2

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

NaiveNodeProviderV2 is like NaiveNodeProvider except it supports accepting node status updates. It must be used with as a pointer and must be created with `NewNaiveNodeProvider`

func NewNaiveNodeProvider

func NewNaiveNodeProvider() *NaiveNodeProviderV2

NewNaiveNodeProvider creates a new NaiveNodeProviderV2 You must use this to create a NaiveNodeProviderV2 if you want to be able to send node status updates to the node controller.

func (*NaiveNodeProviderV2) NotifyNodeStatus

func (n *NaiveNodeProviderV2) NotifyNodeStatus(_ context.Context, f func(*corev1.Node))

NotifyNodeStatus implements the NodeProvider interface.

NaiveNodeProvider does not support updating node status unless created with `NewNaiveNodeProvider` Otherwise this is a no-op

func (*NaiveNodeProviderV2) Ping

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

func (*NaiveNodeProviderV2) UpdateStatus

func (n *NaiveNodeProviderV2) UpdateStatus(ctx context.Context, node *corev1.Node) error

UpdateStatus sends a node status update to the node controller

type NodeController

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

NodeController deals with creating and managing a node object in Kubernetes. It can register a node with Kubernetes and periodically update its status. NodeController manages a single node entity.

func NewNodeController

func NewNodeController(p NodeProvider, node *corev1.Node, nodes v1.NodeInterface, opts ...NodeControllerOpt) (*NodeController, error)

NewNodeController creates a new node controller. 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.

Note: When if there are multiple NodeControllerOpts which apply against the same underlying options, the last NodeControllerOpt will win.

func (*NodeController) Done

func (n *NodeController) Done() <-chan struct{}

Done signals to the caller when the controller is done and the control loop is exited.

Call n.Err() to find out if there was an error.

func (*NodeController) Err

func (n *NodeController) Err() error

Err returns any errors that have occurred that trigger the control loop to exit.

Err only returns a non-nil error after `<-n.Done()` returns.

func (*NodeController) Ready

func (n *NodeController) Ready() <-chan struct{}

Ready returns a channel that gets closed when the node is fully up and running. Note that if there is an error on startup this channel will never be closed.

func (*NodeController) Run

func (n *NodeController) Run(ctx context.Context) (retErr 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 Kubernetes 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 NodeControllerOpt

type NodeControllerOpt func(*NodeController) error //nolint:revive

NodeControllerOpt are the functional options used for configuring a node

func WithNodeEnableLeaseV1

func WithNodeEnableLeaseV1(client coordclientset.LeaseInterface, leaseDurationSeconds int32) NodeControllerOpt

WithNodeEnableLeaseV1 enables support for v1 leases. V1 Leases share all the same properties as v1beta1 leases, except they do not fallback like the v1beta1 lease controller does if the API server does not support it. If the lease duration is not specified (0) then DefaultLeaseDuration will be used

func WithNodeEnableLeaseV1WithRenewInterval

func WithNodeEnableLeaseV1WithRenewInterval(client coordclientset.LeaseInterface, leaseDurationSeconds int32, interval time.Duration) NodeControllerOpt

WithNodeEnableLeaseV1WithRenewInterval enables support for v1 leases, and sets a specific renew interval, as opposed to the standard multiplier specified by DefaultRenewIntervalFraction

func WithNodePingInterval

func WithNodePingInterval(d time.Duration) NodeControllerOpt

WithNodePingInterval sets the interval between checking for node statuses via Ping() If node leases are not supported (or not enabled), this is the frequency with which the node status will be updated in Kubernetes.

func WithNodePingTimeout

func WithNodePingTimeout(timeout time.Duration) NodeControllerOpt

WithNodePingTimeout limits the amount of time that the virtual kubelet will wait for the node provider to respond to the ping callback. If it does not return within this time, it will be considered an error condition

func WithNodeStatusUpdateErrorHandler

func WithNodeStatusUpdateErrorHandler(h ErrorHandler) NodeControllerOpt

WithNodeStatusUpdateErrorHandler adds an error handler for cases where there is an error when updating the node status. This allows the caller to have some control on how errors are dealt with when updating a node's status.

The error passed to the handler will be the error received from kubernetes when updating node status.

func WithNodeStatusUpdateInterval

func WithNodeStatusUpdateInterval(d time.Duration) NodeControllerOpt

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. When node leases are not enabled (or are not supported on the cluster) this has no affect and node status is updated on the "ping" interval.

type NodeProvider

type NodeProvider interface {
	// Ping checks if the node is still active.
	// This is intended to be lightweight as it will be called periodically as a
	// heartbeat to keep the node marked as ready in Kubernetes.
	Ping(context.Context) error

	// NotifyNodeStatus is used to asynchronously monitor the node.
	// The passed in callback should be called any time there is a change to the
	// node's status.
	// This will generally trigger a call to the Kubernetes API server to update
	// the status.
	//
	// NotifyNodeStatus should not block callers.
	NotifyNodeStatus(ctx context.Context, cb func(*corev1.Node))
}

NodeProvider is the interface used for registering a node and updating its status in Kubernetes.

Note: Implementers can choose to manage a node themselves, in which case it is not needed to provide an implementation for this interface.

type PodController

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

PodController is the controller implementation for Pod resources.

func NewPodController

func NewPodController(cfg PodControllerConfig) (*PodController, error)

NewPodController creates a new pod controller with the provided config.

func (*PodController) CheckAndUpdatePod

func (pc *PodController) CheckAndUpdatePod(ctx context.Context, key string, obj interface{}, newPod *corev1.Pod)

func (*PodController) DeletePod

func (pc *PodController) DeletePod(key string)

func (*PodController) DeletePodsFromKubernetesEnqueue

func (pc *PodController) DeletePodsFromKubernetesEnqueue(ctx context.Context, key string)

func (*PodController) DeletePodsFromKubernetesForget

func (pc *PodController) DeletePodsFromKubernetesForget(ctx context.Context, key string)

func (*PodController) Done

func (pc *PodController) Done() <-chan struct{}

Done returns a channel receiver which is closed when the pod controller has exited. Once the pod controller has exited you can call `pc.Err()` to see if any error occurred.

func (*PodController) Err

func (pc *PodController) Err() error

Err returns any error that has occurred and caused the pod controller to exit.

func (*PodController) LoadPod

func (pc *PodController) LoadPod(key string) (any, bool)

func (*PodController) Ready

func (pc *PodController) Ready() <-chan struct{}

Ready returns a channel which gets closed once the PodController is ready to handle scheduled pods. This channel will never close if there is an error on startup. The status of this channel after shutdown is indeterminate.

func (*PodController) Run

func (pc *PodController) Run(ctx context.Context, podSyncWorkers int) (retErr 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 the context is cancelled, at which point it will shutdown the work queue and wait for workers to finish processing their current work items prior to returning.

Once this returns, you should not re-use the controller.

func (*PodController) StorePod

func (pc *PodController) StorePod(key string, pod *corev1.Pod)

func (*PodController) SyncPodStatusFromProviderEnqueue

func (pc *PodController) SyncPodStatusFromProviderEnqueue(ctx context.Context, key string)

func (*PodController) SyncPodsFromKubernetesEnqueue

func (pc *PodController) SyncPodsFromKubernetesEnqueue(ctx context.Context, key string)

type PodControllerConfig

type PodControllerConfig struct {
	// PodClient is used to perform actions on the k8s API, such as updating pod status
	// This field is required
	PodClient corev1client.PodsGetter

	PodLister   lister.PodLister
	PodInformer v1.PodInformer

	EventRecorder record.EventRecorder

	Provider PodLifecycleHandler

	// SyncPodsFromKubernetesRateLimiter defines the rate limit for the SyncPodsFromKubernetes queue
	SyncPodsFromKubernetesRateLimiter workqueue.RateLimiter
	// SyncPodsFromKubernetesShouldRetryFunc allows for a custom retry policy for the SyncPodsFromKubernetes queue
	SyncPodsFromKubernetesShouldRetryFunc queue.ShouldRetryFunc

	// DeletePodsFromKubernetesRateLimiter defines the rate limit for the DeletePodsFromKubernetesRateLimiter queue
	DeletePodsFromKubernetesRateLimiter workqueue.RateLimiter
	// DeletePodsFromKubernetesShouldRetryFunc allows for a custom retry policy for the SyncPodsFromKubernetes queue
	DeletePodsFromKubernetesShouldRetryFunc queue.ShouldRetryFunc

	// SyncPodStatusFromProviderRateLimiter defines the rate limit for the SyncPodStatusFromProviderRateLimiter queue
	SyncPodStatusFromProviderRateLimiter workqueue.RateLimiter
	// SyncPodStatusFromProviderShouldRetryFunc allows for a custom retry policy for the SyncPodStatusFromProvider queue
	SyncPodStatusFromProviderShouldRetryFunc queue.ShouldRetryFunc

	// Add custom filtering for pod informer event handlers
	// Use this for cases where the pod informer handles more than pods assigned to this node
	//
	// For example, if the pod informer is not filtering based on pod.Spec.NodeName, you should
	// set that filter here so the pod controller does not handle events for pods assigned to other nodes.
	PodEventFilterFunc PodEventFilterFunc
}

PodControllerConfig is used to configure a new PodController.

type PodEventFilterFunc

type PodEventFilterFunc func(context.Context, *corev1.Pod) bool

PodEventFilterFunc is used to filter pod events received from Kubernetes.

Filters that return true means the event handler will be run Filters that return false means the filter will *not* be run.

type PodLifecycleHandler

type PodLifecycleHandler interface {
	// CreatePod takes a Kubernetes Pod and deploys it within the provider.
	CreatePod(ctx context.Context, pod *corev1.Pod) error

	// UpdatePod takes a Kubernetes Pod and updates it within the provider.
	UpdatePod(ctx context.Context, pod *corev1.Pod) error

	// DeletePod takes a Kubernetes Pod and deletes it from the provider. Once a pod is deleted, the provider is
	// expected to call the NotifyPods callback with a terminal pod status where all the containers are in a terminal
	// state, as well as the pod. DeletePod may be called multiple times for the same pod.
	DeletePod(ctx context.Context, pod *corev1.Pod) error

	// GetPod retrieves a pod by name from the provider (can be cached).
	// The Pod returned is expected to be immutable, and may be accessed
	// concurrently outside of the calling goroutine. Therefore it is recommended
	// to return a version after DeepCopy.
	GetPod(ctx context.Context, namespace, name string) (*corev1.Pod, error)

	// GetPodStatus retrieves the status of a pod by name from the provider.
	// The PodStatus returned is expected to be immutable, and may be accessed
	// concurrently outside of the calling goroutine. Therefore it is recommended
	// to return a version after DeepCopy.
	GetPodStatus(ctx context.Context, namespace, name string) (*corev1.PodStatus, error)

	// GetPods retrieves a list of all pods running on the provider (can be cached).
	// The Pods returned are expected to be immutable, and may be accessed
	// concurrently outside of the calling goroutine. Therefore it is recommended
	// to return a version after DeepCopy.
	GetPods(context.Context) ([]*corev1.Pod, error)
}

PodLifecycleHandler defines the interface used by the PodController to react to new and changed pods scheduled to the node that is being managed.

Errors produced by these methods should implement an interface from github.com/virtual-kubelet/virtual-kubelet/errdefs package in order for the core logic to be able to understand the type of failure.

type PodNotifier

type PodNotifier interface {
	// NotifyPods instructs the notifier to call the passed in function when
	// the pod status changes. It should be called when a pod's status changes.
	//
	// The provided pointer to a Pod is guaranteed to be used in a read-only
	// fashion. The provided pod's PodStatus should be up to date when
	// this function is called.
	//
	// NotifyPods must not block the caller since it is only used to register the callback.
	// The callback passed into `NotifyPods` may block when called.
	NotifyPods(context.Context, func(*corev1.Pod))
}

PodNotifier is used as an extension to PodLifecycleHandler to support async updates of pod statuses.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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