plugin

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default plugin manager configuration.
	DefaultConfig = &defaultConfig{}
)
View Source
var (
	// Handshake is the handshake configuration for plugins. Will
	// be used the dashboard and the plugin.
	Handshake = plugin.HandshakeConfig{
		ProtocolVersion:  1,
		MagicCookieKey:   "DASHBOARD_PLUGIN",
		MagicCookieValue: "dashboard",
	}
)
View Source
var (
	// PluginName is the name of the dashboard plugin.
	PluginName = "plugin"
)

Functions

func AvailablePlugins

func AvailablePlugins(config Config) ([]string, error)

AvailablePlugins returns a list of available plugins.

func Serve

func Serve(service Service)

Serve serves a plugin.

Types

type ActionRegistrar

type ActionRegistrar interface {
	// Register registers an action.
	Register(actionPath string, actionFunc action.DispatcherFunc) error
}

ActionRegistrar is an action registrar.

type Broker

type Broker interface {
	NextId() uint32
	AcceptAndServe(id uint32, s func([]grpc.ServerOption) *grpc.Server)
}

Broker is a Plugin Broker.

type Capabilities

type Capabilities struct {
	// SupportsPrinterConfig are the GVKs the plugin will print configuration for.
	SupportsPrinterConfig []schema.GroupVersionKind `json:",omitempty"`
	// SupportsPrinterStatus are the GVKs the plugin will print status for.
	SupportsPrinterStatus []schema.GroupVersionKind `json:",omitempty"`
	// SupportsPrinterItems are the GVKs the plugin will print additional items for.
	SupportsPrinterItems []schema.GroupVersionKind `json:",omitempty"`
	// SupportsObjectStatus are the GVKs the plugin will generate object status for.
	SupportsObjectStatus []schema.GroupVersionKind `json:",omitempty"`
	// SupportsTab are the GVKs the plugin will create an additional tab for.
	SupportsTab []schema.GroupVersionKind `json:",omitempty"`
	// IsModule is true this plugin is a module.
	IsModule bool `json:",omitempty"`
	// ActionNames is a list of action names this plugin handles
	ActionNames []string `json:",omitempty"`
}

Capabilities are plugin capabilities.

func (Capabilities) HasPrinterSupport

func (c Capabilities) HasPrinterSupport(gvk schema.GroupVersionKind) bool

HasPrinterSupport returns true if this plugin supports the supplied GVK.

func (Capabilities) HasTabSupport

func (c Capabilities) HasTabSupport(gvk schema.GroupVersionKind) bool

HasTabSupport returns true if this plugins supports creating a tab for the supplied GVK.

type Client

type Client interface {
	Client() (plugin.ClientProtocol, error)
	Kill()
}

Client is an interface that describes a plugin client.

type ClientFactory

type ClientFactory interface {
	// Init initializes a client.
	Init(ctx context.Context, cmd string) Client
}

ClientFactory is a factory for creating clients.

type Config

type Config interface {
	// PluginDirs returns the location of the plugin directories.
	PluginDirs() ([]string, error)
	// Home returns the user's home directory.
	Home() string
	// Fs is the afero filesystem
	Fs() afero.Fs
}

Config is configuration for the plugin manager.

type DefaultClientFactory

type DefaultClientFactory struct{}

DefaultClientFactory is the default client factory

func NewDefaultClientFactory

func NewDefaultClientFactory() *DefaultClientFactory

NewDefaultClientFactory creates an instance of DefaultClientFactory.

func (*DefaultClientFactory) Init

func (f *DefaultClientFactory) Init(ctx context.Context, cmd string) Client

Init creates a new client.

type DefaultRunner

type DefaultRunner struct {
	RunFunc func(name string, gvk schema.GroupVersionKind, object runtime.Object) error
}

DefaultRunner runs a function against all plugins

func ObjectStatusRunner

func ObjectStatusRunner(store ManagerStore, ch chan<- ObjectStatusResponse) DefaultRunner

ObjectStatusRunner is a runner for object status.

func PrintRunner

func PrintRunner(store ManagerStore, ch chan<- PrintResponse) DefaultRunner

PrintRunner is a runner for printing.

func TabRunner

func TabRunner(store ManagerStore, ch chan<- component.Tab) DefaultRunner

TabRunner is a runner for tabs.

func (*DefaultRunner) Run

func (pr *DefaultRunner) Run(object runtime.Object, clientNames []string) error

Run runs the runner for an object with the provided clients.

type DefaultStore

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

DefaultStore is the default implement of ManagerStore.

func NewDefaultStore

func NewDefaultStore() *DefaultStore

NewDefaultStore creates an instance of DefaultStore.

func (*DefaultStore) ClientNames

func (s *DefaultStore) ClientNames() []string

ClientNames returns the client names in the store.

func (*DefaultStore) Clients

func (s *DefaultStore) Clients() map[string]Client

Clients returns all the clients in the store.

func (*DefaultStore) GetCommand

func (s *DefaultStore) GetCommand(name string) (string, error)

GetCommand gets the command for a plugin.

func (*DefaultStore) GetMetadata

func (s *DefaultStore) GetMetadata(name string) (*Metadata, error)

GetMetadata gets the metadata for a plugin.

func (*DefaultStore) GetService

func (s *DefaultStore) GetService(name string) (Service, error)

GetService gets the service for a plugin.

func (*DefaultStore) Store

func (s *DefaultStore) Store(name string, client Client, metadata *Metadata, cmd string) error

Store stores information for a plugin.

type GRPCClient

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

GRPCClient is the dashboard GRPC client.

func NewGRPCClient

func NewGRPCClient(broker Broker, client dashboard.PluginClient) *GRPCClient

NewGRPCClient creates an instance of GRPCClient.

func (*GRPCClient) Content

func (c *GRPCClient) Content(contentPath string) (component.ContentResponse, error)

Content returns content from a plugin.

func (*GRPCClient) HandleAction

func (c *GRPCClient) HandleAction(payload action.Payload) error

HandleAction runs an action on a plugin.

func (*GRPCClient) Navigation

func (c *GRPCClient) Navigation() (navigation.Navigation, error)

Navigation returns navigation entries from a plugin.

func (*GRPCClient) ObjectStatus

func (c *GRPCClient) ObjectStatus(object runtime.Object) (ObjectStatusResponse, error)

ObjectStatus gets an object status

func (*GRPCClient) Print

func (c *GRPCClient) Print(object runtime.Object) (PrintResponse, error)

Print prints an object.

func (*GRPCClient) PrintTab

func (c *GRPCClient) PrintTab(object runtime.Object) (*component.Tab, error)

PrintTab creates a tab for an object.

func (*GRPCClient) Register

func (c *GRPCClient) Register(dashboardAPIAddress string) (Metadata, error)

Register register a plugin.

type GRPCServer

type GRPCServer struct {
	Impl Service
	// contains filtered or unexported fields
}

GRPCServer is the grpc server the dashboard will use to communicate with the the plugin.

func (*GRPCServer) Content

Content returns content from a plugin.

func (*GRPCServer) HandleAction

func (s *GRPCServer) HandleAction(ctx context.Context, handleActionRequest *dashboard.HandleActionRequest) (*dashboard.HandleActionResponse, error)

HandleAction runs an action in a plugin.

func (*GRPCServer) Navigation

Navigation returns navigation entries from a plugin.

func (*GRPCServer) ObjectStatus

func (s *GRPCServer) ObjectStatus(ctx context.Context, objectRequest *dashboard.ObjectRequest) (*dashboard.ObjectStatusResponse, error)

ObjectStatus generates status for an object.

func (*GRPCServer) Print

func (s *GRPCServer) Print(ctx context.Context, objectRequest *dashboard.ObjectRequest) (*dashboard.PrintResponse, error)

Print prints an object.

func (*GRPCServer) PrintTab

func (s *GRPCServer) PrintTab(ctx context.Context, objectRequest *dashboard.ObjectRequest) (*dashboard.PrintTabResponse, error)

PrintTab prints a tab for an object.

func (*GRPCServer) Register

func (s *GRPCServer) Register(ctx context.Context, registerRequest *dashboard.RegisterRequest) (*dashboard.RegisterResponse, error)

Register register a plugin.

func (*GRPCServer) WatchAdd

WatchAdd is called when a watched GVK has a new object added.

func (*GRPCServer) WatchDelete

WatchDelete is called when a watched GVK has an object deleted.

func (*GRPCServer) WatchUpdate

WatchUpdate is called when a watched GVK has an object updated.

type Manager

type Manager struct {
	PortForwarder   portforward.PortForwarder
	API             api.API
	ClientFactory   ClientFactory
	ModuleRegistrar ModuleRegistrar
	ActionRegistrar ActionRegistrar

	Runners Runners
	// contains filtered or unexported fields
}

Manager manages plugins

func NewManager

func NewManager(apiService api.API, moduleRegistrar ModuleRegistrar, actionRegistrar ActionRegistrar, options ...ManagerOption) *Manager

NewManager creates an instance of Manager.

func (*Manager) Load

func (m *Manager) Load(cmd string) error

Load loads a plugin.

func (*Manager) ObjectStatus

func (m *Manager) ObjectStatus(object runtime.Object) (*ObjectStatusResponse, error)

ObjectStatus updates the object status of an object configured from a plugin

func (*Manager) Print

func (m *Manager) Print(object runtime.Object) (*PrintResponse, error)

Print prints an object with plugins which are configured to print the objects's GVK.

func (*Manager) SetStore

func (m *Manager) SetStore(store ManagerStore)

SetStore sets the store for the manager.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts all plugins.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context)

Stop stops all plugins.

func (*Manager) Store

func (m *Manager) Store() ManagerStore

Store returns the store for the manager.

func (*Manager) Tabs

func (m *Manager) Tabs(object runtime.Object) ([]component.Tab, error)

Tabs queries plugins for tabs for an object.

type ManagerInterface

type ManagerInterface interface {
	// Print prints an object.
	Print(object runtime.Object) (*PrintResponse, error)

	// Tabs retrieves tabs for an object.
	Tabs(object runtime.Object) ([]component.Tab, error)

	// Store returns the manager's storage.
	Store() ManagerStore

	// ObjectStatus returns the object status
	ObjectStatus(object runtime.Object) (*ObjectStatusResponse, error)
}

ManagerInterface is an interface which represent a plugin manager.

type ManagerOption

type ManagerOption func(*Manager)

ManagerOption is an option for configuring Manager.

type ManagerStore

type ManagerStore interface {
	Store(name string, client Client, metadata *Metadata, cmd string) error
	GetMetadata(name string) (*Metadata, error)
	GetService(name string) (Service, error)
	GetCommand(name string) (string, error)
	Clients() map[string]Client
	ClientNames() []string
}

ManagerStore is the data store for Manager.

type Metadata

type Metadata struct {
	Name         string
	Description  string
	Capabilities Capabilities
}

Metadata is plugin metadata.

type ModuleProxy

type ModuleProxy struct {
	Metadata   *Metadata
	PluginName string
	Service    ModuleService
}

ModuleProxy is a proxy that satisfies Octant module requirements. It allows plugins to behave as if they are internal modules.

func NewModuleProxy

func NewModuleProxy(pluginName string, metadata *Metadata, service ModuleService) (*ModuleProxy, error)

NewModuleProxy creates a ModuleProxy instance.

func (ModuleProxy) AddCRD

AddCRD is a no-op

func (*ModuleProxy) Content

func (m *ModuleProxy) Content(ctx context.Context, contentPath, prefix, namespace string, opts module.ContentOptions) (component.ContentResponse, error)

Content returns content from the plugin. Plugins are expected to handle paths appropriately.

func (*ModuleProxy) ContentPath

func (m *ModuleProxy) ContentPath() string

func (ModuleProxy) Generators

func (ModuleProxy) Generators() []octant.Generator

Generators is a no-op

func (ModuleProxy) GroupVersionKindPath

func (ModuleProxy) GroupVersionKindPath(namespace, apiVersion, kind, name string) (string, error)

GroupVersionKindPath is currently a no-op. In the future this will allow plugins to handle paths for GVKs.

func (ModuleProxy) Handlers

func (ModuleProxy) Handlers(ctx context.Context) map[string]http.Handler

func (*ModuleProxy) Name

func (m *ModuleProxy) Name() string

Name returns the module's name. It is the same as the plugin's metadata name.

func (*ModuleProxy) Navigation

func (m *ModuleProxy) Navigation(ctx context.Context, namespace, root string) ([]navigation.Navigation, error)

Navigation returns navigation from the plugin.

func (ModuleProxy) RemoveCRD

RemoveCRD is a no-op

func (ModuleProxy) SetContext

func (ModuleProxy) SetContext(ctx context.Context, contextName string) error

SetContext is a no-op

func (ModuleProxy) SetNamespace

func (ModuleProxy) SetNamespace(namespace string) error

SetNamespace is a no-op

func (ModuleProxy) Start

func (ModuleProxy) Start() error

Start is a no-op

func (ModuleProxy) Stop

func (ModuleProxy) Stop()

Stop is a no-op

func (ModuleProxy) SupportedGroupVersionKind

func (ModuleProxy) SupportedGroupVersionKind() []schema.GroupVersionKind

SupportedGroupVersionKind is currently a no-op. In the future this will allow plugins to handle paths for GVKs.

type ModuleRegistrar

type ModuleRegistrar interface {
	// Register registers a module.
	Register(mod module.Module) error
}

ModuleRegistrar is a module registrar.

type ModuleService

type ModuleService interface {
	Service

	Navigation() (navigation.Navigation, error)
	Content(contentPath string) (component.ContentResponse, error)
}

ModuleService is the interface that is exposed as a plugin as a module. The plugin is required to implement this interface.

type ObjectStatusResponse

type ObjectStatusResponse struct {
	// ObjectStatus is status of an object.
	ObjectStatus component.PodSummary
}

ObjectStatusResponse is an object status response from plugin.

type PrintResponse

type PrintResponse struct {
	// Config is additional summary sections for configuration.
	Config []component.SummarySection
	// Status is additional summary sections for status.
	Status []component.SummarySection
	// Items are additional view components.
	Items []component.FlexLayoutItem
}

PrintResponse is a printer response from the plugin. The dashboard will use this to the add the plugin's output to a summary view.

type Runners

type Runners interface {
	// Print returns a runner for printing. The caller should close
	// the channel when they are done with it.
	Print(ManagerStore) (DefaultRunner, chan PrintResponse)
	// Tab returns a runner for tabs. The caller should close
	// the channel when they are done with it.
	Tab(ManagerStore) (DefaultRunner, chan component.Tab)
	// ObjectStatus returns a runner for object status. The caller should
	// close the channel when they are done with it.
	ObjectStatus(ManagerStore) (DefaultRunner, chan ObjectStatusResponse)
}

Runners is an interface that manager can call to get runners for a particular action.

type Service

type Service interface {
	Register(dashboardAPIAddress string) (Metadata, error)
	Print(object runtime.Object) (PrintResponse, error)
	PrintTab(object runtime.Object) (*component.Tab, error)
	ObjectStatus(object runtime.Object) (ObjectStatusResponse, error)
	HandleAction(payload action.Payload) error
}

Service is the interface that is exposed as a plugin. The plugin is required to implement this interface.

type ServicePlugin

type ServicePlugin struct {
	plugin.NetRPCUnsupportedPlugin

	Impl Service
}

ServicePlugin is the GRPC plugin for Service.

func (*ServicePlugin) GRPCClient

func (p *ServicePlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient is the plugin's GRPC client.

func (*ServicePlugin) GRPCServer

func (p *ServicePlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer is the plugin's GRPC server.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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