Documentation
¶
Index ¶
Constants ¶
const ( // ProgramName is the name of the program. ProgramName = "minkapi" // DefaultWatchQueueSize is the default maximum number of events to queue per watcher. DefaultWatchQueueSize = 100 // DefaultWatchTimeout is the default timeout for watches after which MinKAPI service closes the connection. DefaultWatchTimeout = 5 * time.Minute // DefaultKubeConfigPath is the default kubeconfig path if none is specified. DefaultKubeConfigPath = "/tmp/minkapi.yaml" // DefaultBasePrefix is the default path prefix for the base minkapi server DefaultBasePrefix = "base" )
Variables ¶
var ( // ErrInitFailed is a sentinel error indicating that the minkapi program failed to initialize. ErrInitFailed = fmt.Errorf(commonerrors.FmtInitFailed, ProgramName) // ErrStartFailed is a sentinel error indicating that the service failed to start. ErrStartFailed = fmt.Errorf(commonerrors.FmtStartFailed, ProgramName) // ErrClientFacadesFailed is a sentinel error indicating that client facades creation failed. ErrClientFacadesFailed = errors.New("failed to create client facades") // ErrServiceFailed is a sentinel error indicating that the service failed. ErrServiceFailed = fmt.Errorf("%s service failed", ProgramName) // ErrLoadConfigTemplate is a sentinel error indicating that config template loading failed. ErrLoadConfigTemplate = errors.New("cannot load config template") // ErrExecuteConfigTemplate is a sentinel error indicating that config template execution failed. ErrExecuteConfigTemplate = errors.New("cannot execute config template") // ErrStoreNotFound is a sentinel error indicating that a resource store was not found. ErrStoreNotFound = errors.New("store not found") // ErrCreateWatcher is a sentinel error indicating that watcher creation failed. ErrCreateWatcher = errors.New("cannot create watcher") // ErrCreateObject is a sentinel error indicating that object creation failed. ErrCreateObject = errors.New("cannot create object") // ErrDeleteObject is a sentinel error indicating that object deletion failed. ErrDeleteObject = errors.New("cannot delete object") // ErrListObjects is a sentinel error indicating that object listing failed. ErrListObjects = errors.New("cannot list objects") // ErrUpdateObject is a sentinel error indicating that object update failed. ErrUpdateObject = errors.New("cannot update object") // ErrCreateView is a sentinel error indicating that view creation failed. ErrCreateView = errors.New("cannot create view") )
var MatchAllCriteria = MatchCriteria{}
MatchAllCriteria is a predefined criteria that matches all objects.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// Server is the MinKAPI server instance.
Server Server
// Ctx is the application context.
Ctx context.Context
// Cancel is the context cancellation function.
Cancel context.CancelFunc
}
App represents an application process that wraps a minkapi Server, an application context and application cancel func. Main entry-point functions that embed minkapi are expected to construct a new App instance via cli.LaunchApp and shutdown applications via cli.ShutdownApp
type Config ¶
type Config struct {
// BasePrefix is the path prefix at which the base View of the minkapi service is served. ie KAPI-Service at http://<MinKAPIHost>:<MinKAPIPort>/BasePrefix
// Defaults to [DefaultBasePrefix]
BasePrefix string
commontypes.ServerConfig
// WatchConfig holds config parameters relevant for watchers.
WatchConfig WatchConfig
}
Config holds the configuration for MinKAPI.
type CreateSandboxViewFunc ¶
CreateSandboxViewFunc represents a creator function for constructing sandbox views from the delegate view and given args
type EventSink ¶
type EventSink interface {
Resettable
events.EventSink
// List returns all events in the sink.
List() []eventsv1.Event
}
EventSink defines an interface for storing and retrieving Kubernetes events.
type MatchCriteria ¶
type MatchCriteria struct {
// LabelSelector specifies the label selector for matching objects.
LabelSelector labels.Selector
// Names specifies the set of object names to match. Empty means all names.
Names sets.Set[string]
// Namespace specifies the namespace to match. Empty means all namespaces.
Namespace string
}
MatchCriteria defines criteria for matching Kubernetes objects.
type Resettable ¶
type Resettable interface {
// Reset resets the state of the implementing type.
Reset()
}
Resettable defines types that can reset their state to a default or initial configuration.
type ResourceStore ¶
type ResourceStore interface {
Resettable
io.Closer
// GetObjAndListGVK gets the object GVK and object list GVK associated with this resource store.
GetObjAndListGVK() (objKind schema.GroupVersionKind, objListKind schema.GroupVersionKind)
// Add adds a new object to the store.
Add(ctx context.Context, mo metav1.Object) error
// GetByKey retrieves an object from the store by its key.
GetByKey(ctx context.Context, key string) (o runtime.Object, err error)
// Get retrieves an object from the store by its name.
Get(ctx context.Context, objName cache.ObjectName) (o runtime.Object, err error)
// Update updates an existing object in the store.
Update(ctx context.Context, mo metav1.Object) error
// DeleteByKey deletes an object from the store by its key.
DeleteByKey(ctx context.Context, key string) error
// Delete deletes an object from the store by its name.
Delete(ctx context.Context, objName cache.ObjectName) error
// DeleteObjects deletes objects matching the given criteria and returns the count of deleted objects.
DeleteObjects(ctx context.Context, c MatchCriteria) (delCount int, err error)
// List lists objects matching the given criteria.
List(ctx context.Context, c MatchCriteria) (listObj runtime.Object, err error)
// ListMetaObjects lists metadata objects matching the given criteria.
ListMetaObjects(ctx context.Context, c MatchCriteria) (metaObjs []metav1.Object, maxVersion int64, err error)
// Watch watches object changes in this store starting from the given startVersion, belonging to the given namespace and matching the given labelSelector and then constructs a watch.Event followed by invoking eventCallback.
Watch(ctx context.Context, startVersion int64, namespace string, labelSelector labels.Selector, eventCallback WatchEventCallback) error
// GetWatcher returns a watcher - an implementation of watch.Interface to watch changes in objects beginning from options.ResourceVersion and belonging to the given namespace, then use the options.labelSelector to filter, and supply watch events via the watch.Interface.ResultChan.
// options.FieldSelector is currently not supported.
GetWatcher(ctx context.Context, namespace string, options metav1.ListOptions) (watch.Interface, error)
// GetVersionCounter returns the atomic counter for generating monotonically increasing resource versions
GetVersionCounter() *atomic.Int64
}
ResourceStore defines an interface for storing and managing Kubernetes resources with watch capabilities.
type ResourceStoreArgs ¶
type ResourceStoreArgs struct {
// Scheme is the runtime Scheme used by the KAPI objects storable in this store.
Scheme *runtime.Scheme
// VersionCounter is the atomic counter for generating monotonically increasing resource versions
VersionCounter *atomic.Int64 //optional
// ObjectGVK is the GroupVersionKind for objects stored in this store.
ObjectGVK schema.GroupVersionKind
// ObjectListGVK is the GroupVersionKind for object lists from this store.
ObjectListGVK schema.GroupVersionKind
// Log is the logger instance for this store.
Log logr.Logger
// Name is the name of the resource store.
Name string
// WatchConfig contains configuration for watch operations.
WatchConfig WatchConfig
}
ResourceStoreArgs contains arguments for creating a ResourceStore.
type Server ¶
type Server interface {
commontypes.Service
ViewAccess
}
Server represents a MinKAPI server that provides access to a KAPI (kubernetes API) service accessible at http://<MinKAPIHost>:<MinKAPIPort>/base It also supports methods to create "sandbox" (private) views accessible at http://<MinKAPIHost>:<MinKAPIPort>/sandboxName
type View ¶
type View interface {
Resettable
io.Closer
// GetName returns the name of this view.
GetName() string
// GetType returns the type of this view (base or sandbox).
GetType() ViewType
// SetKubeConfigPath sets the path to the kubeconfig file for this view used to create network client facades.
SetKubeConfigPath(path string)
// GetClientFacades gets a ClientFacades populated according to the given accessMode that can be used by code to interact with this view
// via standard k8s client and informer interfaces
GetClientFacades(ctx context.Context, accessMode commontypes.ClientAccessMode) (commontypes.ClientFacades, error)
// GetResourceStore returns the resource store for the specified GroupVersionKind.
GetResourceStore(gvk schema.GroupVersionKind) (ResourceStore, error)
// GetEventSink returns the event sink for this view.
GetEventSink() EventSink
// CreateObject creates a new object of the specified GVK in this view.
CreateObject(ctx context.Context, gvk schema.GroupVersionKind, obj metav1.Object) (metav1.Object, error)
// GetObject retrieves an object of the specified GVK by name.
GetObject(ctx context.Context, gvk schema.GroupVersionKind, objName cache.ObjectName) (runtime.Object, error)
// UpdateObject updates an existing object of the specified GVK.
UpdateObject(ctx context.Context, gvk schema.GroupVersionKind, obj metav1.Object) error
// UpdatePodNodeBinding updates a pod's node binding and returns the updated pod.
UpdatePodNodeBinding(ctx context.Context, podName cache.ObjectName, binding corev1.Binding) (*corev1.Pod, error)
// PatchObject applies a patch to an object of the specified GVK.
PatchObject(ctx context.Context, gvk schema.GroupVersionKind, objName cache.ObjectName, patchType types.PatchType, patchData []byte) (patchedObj runtime.Object, err error)
// PatchObjectStatus applies a patch to an object's status subresource.
PatchObjectStatus(ctx context.Context, gvk schema.GroupVersionKind, objName cache.ObjectName, patchData []byte) (patchedObj runtime.Object, err error)
// ListMetaObjects lists metadata objects matching the given criteria.
ListMetaObjects(ctx context.Context, gvk schema.GroupVersionKind, criteria MatchCriteria) (metaObjs []metav1.Object, maxVersion int64, err error)
// ListObjects lists objects in the store while matching the criteria and returns the matching objects as a runtime.Object which is actually a *<Kind>List. Ex: *PodList
// TODO: consider better name for this method.
ListObjects(ctx context.Context, gvk schema.GroupVersionKind, criteria MatchCriteria) (runtime.Object, error)
// WatchObjects watches for changes to objects of the specified GVK.
WatchObjects(ctx context.Context, gvk schema.GroupVersionKind, startVersion int64, namespace string, labelSelector labels.Selector, eventCallback WatchEventCallback) error
// GetWatcher returns a watcher for objects of the specified GVK.
GetWatcher(ctx context.Context, gvk schema.GroupVersionKind, namespace string, opts metav1.ListOptions) (watch.Interface, error)
// DeleteObject deletes an object of the specified GVK by name.
DeleteObject(ctx context.Context, gvk schema.GroupVersionKind, objName cache.ObjectName) error
// DeleteObjects deletes objects of the specified GVK matching the criteria.
DeleteObjects(ctx context.Context, gvk schema.GroupVersionKind, criteria MatchCriteria) error
// ListNodes returns nodes matching the specified node names, or all nodes if none specified.
ListNodes(ctx context.Context, matchingNodeNames ...string) ([]corev1.Node, error)
// ListPods returns pods matching the specified criteria.
ListPods(ctx context.Context, criteria MatchCriteria) ([]corev1.Pod, error)
// ListEvents returns events in the specified namespace.
ListEvents(ctx context.Context, namespace string) ([]eventsv1.Event, error)
// GetObjectChangeCount returns the current change count made to objects through this view.
GetObjectChangeCount() int64
// GetKubeConfigPath returns the path to the kubeconfig file for this view.
GetKubeConfigPath() string
}
View is the high-level facade to a repository of objects of different types (GVK). TODO: Think of a better name. Rename this to ObjectRepository or something else, also add godoc ?
type ViewAccess ¶
type ViewAccess interface {
io.Closer
// GetBaseView returns the foundational View of the KAPI Server which is exposed at http://<MinKAPIHost>:<MinKAPIPort>/basePrefix
GetBaseView() View
// GetOrCreateSandboxView creates or returns a sandboxed KAPI View with the given name that is also served as a KAPI Service
// at http://<MinKAPIHost>:<MinKAPIPort>/sandboxName. A kubeconfig named `minkapi-<name>.yaml` is also generated
// in the same directory as the base `minkapi.yaml`. The sandbox name should be a valid path-prefix, ie no-spaces.
// TODO: discuss whether the above is OK.
GetOrCreateSandboxView(ctx context.Context, name string) (View, error)
}
ViewAccess is a facade to get or create KAPI Views.
type ViewArgs ¶
type ViewArgs struct {
// Scheme is the runtime Scheme used by KAPI objects exposed by this view
Scheme *runtime.Scheme
// Name represents name of View
Name string
// KubeConfigPath is the path of the kubeconfig file corresponding to this view
KubeConfigPath string
// WatchConfig contains configuration for watch operations.
WatchConfig WatchConfig
}
ViewArgs contains arguments for creating a View.
type WatchConfig ¶
type WatchConfig struct {
// QueueSize is the maximum number of events to queue per watcher
QueueSize int
// Timeout represents the timeout for watches following which MinKAPI service will close the connection and ends the watch.
Timeout time.Duration
}
WatchConfig holds config parameters relevant for watchers.
type WatchEventCallback ¶
WatchEventCallback is a function type for handling watch events from a ResourceStore.