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
- func AttachMetricsRoutes(p providers.Provider, mux ServeMux)
- func AttachPodRoutes(p providers.Provider, mux ServeMux)
- func InstrumentHandler(h http.Handler) http.Handler
- func MetricsSummaryHandler(p providers.Provider) http.Handler
- func NotFound(w http.ResponseWriter, r *http.Request)
- func NotImplemented(w http.ResponseWriter, r *http.Request)
- func PodHandler(p providers.Provider) http.Handler
- type Config
- type PodController
- type ServeMux
- type Server
Constants ¶
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" )
Variables ¶
This section is empty.
Functions ¶
func AttachMetricsRoutes ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.6.2
InstrumentHandler wraps an http.Handler and injects instrumentation into the request context.
func MetricsSummaryHandler ¶ added in v0.6.2
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 ¶ added in v0.6.2
func NotImplemented(w http.ResponseWriter, r *http.Request)
NotImplemented provides a handler for cases where a provider does not implement a given API
Types ¶
type Config ¶ added in v0.6.2
type Config struct { Client *kubernetes.Clientset Namespace string NodeName string Provider providers.Provider ResourceManager *manager.ResourceManager Taint *corev1.Taint PodSyncWorkers int PodInformer corev1informers.PodInformer }
Config is used to configure a new server.
type PodController ¶ added in v0.7.3
type PodController struct {
// contains filtered or unexported fields
}
PodController is the controller implementation for Pod resources.
func NewPodController ¶ added in v0.7.3
func NewPodController(server *Server) *PodController
NewPodController returns a new instance of PodController.
func (*PodController) Run ¶ added in v0.7.3
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 ¶ added in v0.8.0
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 ¶
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) Run ¶
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.