Documentation ¶
Index ¶
- Constants
- type EventInfo
- type EventWatcher
- type PluginManager
- func (e PluginManager) Abort(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) error
- func (e *PluginManager) Finalize(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) (err error)
- func (e *PluginManager) GetID() string
- func (e *PluginManager) GetProperties() pluginsCore.PluginProperties
- func (e PluginManager) Handle(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) (pluginsCore.Transition, error)
- type PluginMetrics
- type PluginPhase
- type PluginState
- type ResourceLevelMonitor
- type ResourceMonitorIndex
- type TaskExecutionContext
- type TaskExecutionMetadata
Examples ¶
Constants ¶
const KindKey contextutils.Key = "kind"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventInfo ¶ added in v1.9.6
EventInfo stores detail about the event and the timestamp of the first occurrence. All other fields are thrown away to conserve space.
type EventWatcher ¶ added in v1.9.6
type EventWatcher interface {
List(objectNsName types.NamespacedName, createdAfter time.Time) []*EventInfo
}
func NewEventWatcher ¶ added in v1.9.6
func NewEventWatcher(ctx context.Context, gvk schema.GroupVersionKind, kubeClientset kubernetes.Interface) (EventWatcher, error)
type PluginManager ¶
type PluginManager struct {
// contains filtered or unexported fields
}
A generic Plugin for managing k8s-resources. Plugin writers wishing to use K8s resource can use the simplified api specified in pluginmachinery.core
func NewPluginManager ¶
func NewPluginManager(ctx context.Context, iCtx pluginsCore.SetupContext, entry k8s.PluginEntry, monitorIndex *ResourceMonitorIndex, kubeClientset kubernetes.Interface) (*PluginManager, error)
Creates a K8s generic task executor. This provides an easier way to build task executors that create K8s resources.
Example ¶
sCtx := &pluginsCoreMock.SetupContext{} fakeKubeClient := mocks.NewFakeKubeClient() mockClientset := k8sfake.NewSimpleClientset() sCtx.On("KubeClient").Return(fakeKubeClient) sCtx.On("OwnerKind").Return("test") sCtx.On("EnqueueOwner").Return(pluginsCore.EnqueueOwner(func(name k8stypes.NamespacedName) error { return nil })) sCtx.On("MetricsScope").Return(promutils.NewTestScope()) ctx := context.TODO() exec, err := NewPluginManager(ctx, sCtx, k8s.PluginEntry{ ID: "SampleHandler", RegisteredTaskTypes: []pluginsCore.TaskType{"container"}, ResourceToWatch: &v1.Pod{}, Plugin: k8sSampleHandler{}, }, NewResourceMonitorIndex(), mockClientset) if err == nil { fmt.Printf("Created executor: %v\n", exec.GetID()) } else { fmt.Printf("Error in creating executor: %s\n", err.Error()) }
Output: Created executor: SampleHandler
func NewPluginManagerWithBackOff ¶
func NewPluginManagerWithBackOff(ctx context.Context, iCtx pluginsCore.SetupContext, entry k8s.PluginEntry, backOffController *backoff.Controller, monitorIndex *ResourceMonitorIndex, kubeClientset kubernetes.Interface) (*PluginManager, error)
func (PluginManager) Abort ¶
func (e PluginManager) Abort(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) error
func (*PluginManager) Finalize ¶
func (e *PluginManager) Finalize(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) (err error)
func (*PluginManager) GetID ¶
func (e *PluginManager) GetID() string
func (*PluginManager) GetProperties ¶
func (e *PluginManager) GetProperties() pluginsCore.PluginProperties
func (PluginManager) Handle ¶
func (e PluginManager) Handle(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) (pluginsCore.Transition, error)
type PluginMetrics ¶
type PluginPhase ¶
type PluginPhase uint8
const ( PluginPhaseNotStarted PluginPhase = iota PluginPhaseAllocationTokenAcquired PluginPhaseStarted )
type PluginState ¶
type PluginState struct { Phase PluginPhase K8sPluginState k8s.PluginState LastEventUpdate time.Time }
type ResourceLevelMonitor ¶
type ResourceLevelMonitor struct { Scope promutils.Scope // Meta timer - this times each collection cycle to measure how long it takes to collect the levels GaugeVec below CollectorTimer *labeled.StopWatch // System Observability: This is a labeled gauge that emits the current number of objects in the informer. It is used // to monitor current levels. Levels *labeled.Gauge // contains filtered or unexported fields }
This object is responsible for emitting metrics that show the current number of a given K8s resource kind, cut by namespace. It needs to be kicked off. The periodicity is not currently configurable because it seems unnecessary. It will also a timer measuring how long it takes to run each measurement cycle.
func (*ResourceLevelMonitor) RunCollector ¶
func (r *ResourceLevelMonitor) RunCollector(ctx context.Context)
func (*ResourceLevelMonitor) RunCollectorOnce ¶
func (r *ResourceLevelMonitor) RunCollectorOnce(ctx context.Context)
type ResourceMonitorIndex ¶
type ResourceMonitorIndex struct {
// contains filtered or unexported fields
}
This struct is here to ensure that we do not create more than one of these monitors for a given GVK. It wouldn't necessarily break anything, but it's a waste of compute cycles to compute counts multiple times. This can happen if multiple plugins create the same underlying K8s resource type. If two plugins both created Pods (ie sidecar and container), without this we would launch two ResourceLevelMonitor's, have two goroutines spinning, etc.
func NewResourceMonitorIndex ¶
func NewResourceMonitorIndex() *ResourceMonitorIndex
func (*ResourceMonitorIndex) GetOrCreateResourceLevelMonitor ¶
func (r *ResourceMonitorIndex) GetOrCreateResourceLevelMonitor(ctx context.Context, scope promutils.Scope, si cache.SharedIndexInformer, gvk schema.GroupVersionKind) *ResourceLevelMonitor
type TaskExecutionContext ¶
type TaskExecutionContext struct { pluginsCore.TaskExecutionContext // contains filtered or unexported fields }
TaskExecutionContext provides a layer on top of core TaskExecutionContext with a custom TaskExecutionMetadata.
func (TaskExecutionContext) TaskExecutionMetadata ¶
func (t TaskExecutionContext) TaskExecutionMetadata() pluginsCore.TaskExecutionMetadata
type TaskExecutionMetadata ¶
type TaskExecutionMetadata struct { pluginsCore.TaskExecutionMetadata // contains filtered or unexported fields }
TaskExecutionMetadata provides a layer on top of the core TaskExecutionMetadata with customized annotations and labels for k8s plugins.
func (TaskExecutionMetadata) GetAnnotations ¶
func (t TaskExecutionMetadata) GetAnnotations() map[string]string
func (TaskExecutionMetadata) GetLabels ¶
func (t TaskExecutionMetadata) GetLabels() map[string]string