plugin

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: Apache-2.0 Imports: 44 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default plugin manager configuration.
	DefaultConfig = &defaultConfig{os: runtime.GOOS}
)
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.
	Name = "plugin"
)

Functions

func AvailablePlugins

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

AvailablePlugins returns a list of available plugins.

func IsJavaScriptPlugin added in v0.14.0

func IsJavaScriptPlugin(pluginName string) bool

func NewJSPlugin added in v0.14.0

func NewJSPlugin(ctx context.Context, pluginPath string, dashboardClientFactory octant.DashboardClientFactory, options ...JSOption) (*jsPlugin, error)

NewJSPlugin creates a new instances of a JavaScript plugin.

func Serve

func Serve(service Service)

Serve serves a plugin.

func WithClassExtractor added in v0.15.0

func WithClassExtractor(pce JSClassExtractor) func(*jsPlugin)

WithClassExtractor option replaces the default JSClassExtractor function of a JSPlugin.

func WithMetadataExtractor added in v0.15.0

func WithMetadataExtractor(pme JSMetadataExtractor) func(*jsPlugin)

WithMetadataExtractor option replaces the default JSMetadataExtractor function of a JSPlugin.

func WithRuntimeFactory added in v0.15.0

func WithRuntimeFactory(prf JSRuntimeFactory) func(*jsPlugin)

WithRuntimeFactory option replaces the default JSRuntimeFactory function of a JSPlugin.

Types

type ActionRegistrar

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

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) HasObjectStatusSupport added in v0.14.0

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

HasObjectStatusSupport returns true if this plugins supports creating object status for the supplied GVK.

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 ClusterClient added in v0.15.0

type ClusterClient interface {
	Resource(gk schema.GroupKind) (schema.GroupVersionResource, bool, error)
	DynamicClient() (dynamic.Interface, error)
}

ClusterClient defines the cluster client plugin manager has access to.

type Config

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

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(ctx context.Context, 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(ctx context.Context, 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) GetJS added in v0.14.0

func (s *DefaultStore) GetJS(name string) (JSPlugin, bool)

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) NamesJS added in v0.14.0

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

func (*DefaultStore) RemoveJS added in v0.14.0

func (s *DefaultStore) RemoveJS(name string)

func (*DefaultStore) Store

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

Store stores information for a plugin.

func (*DefaultStore) StoreJS added in v0.14.0

func (s *DefaultStore) StoreJS(name string, plugin JSPlugin) error

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(ctx context.Context, contentPath string) (component.ContentResponse, error)

Content returns content from a plugin.

func (*GRPCClient) HandleAction

func (c *GRPCClient) HandleAction(ctx context.Context, actionName string, payload action.Payload) error

HandleAction runs an action on a plugin.

func (*GRPCClient) Navigation

func (c *GRPCClient) Navigation(ctx context.Context) (navigation.Navigation, error)

Navigation returns navigation entries from a plugin.

func (*GRPCClient) ObjectStatus

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

ObjectStatus gets an object status

func (*GRPCClient) Print

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

Print prints an object.

func (*GRPCClient) PrintTab

func (c *GRPCClient) PrintTab(ctx context.Context, object runtime.Object) (TabResponse, error)

PrintTab creates a tab for an object.

func (*GRPCClient) Register

func (c *GRPCClient) Register(ctx context.Context, 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 JSClassExtractor added in v0.15.0

type JSClassExtractor func(*goja.Runtime) (*goja.Object, error)

JSClassExtractor functions extract the default class from a runtime.

type JSMetadataExtractor added in v0.15.0

type JSMetadataExtractor func(*goja.Runtime, goja.Value) (*Metadata, error)

JSMetadataExtractor functions extract JavaScript plugin metadata from a runtime.

type JSOption added in v0.15.0

type JSOption func(*jsPlugin)

JSOption is an option that overrides a default value of a JSPlugin.

type JSPlugin added in v0.14.0

type JSPlugin interface {
	Close()
	PluginPath() string
	Metadata() *Metadata

	Navigation(ctx context.Context) (navigation.Navigation, error)
	Register(ctx context.Context, dashboardAPIAddress string) (Metadata, error)
	Print(ctx context.Context, object runtime.Object) (PrintResponse, error)
	PrintTab(ctx context.Context, object runtime.Object) (TabResponse, error)
	ObjectStatus(ctx context.Context, object runtime.Object) (ObjectStatusResponse, error)
	HandleAction(ctx context.Context, actionName string, payload action.Payload) error
	Content(ctx context.Context, contentPath string) (component.ContentResponse, error)
}

JSPlugin interface represents a JavaScript plugin.

type JSRuntimeFactory added in v0.15.0

type JSRuntimeFactory func(context.Context, string) (*eventloop.EventLoop, error)

JSRuntimeFactory functions creates a JavaScript runtime for a JavaScript plugin.

type Manager

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

	Runners Runners
	// contains filtered or unexported fields
}

Manager manages plugins

func NewManager

func NewManager(apiService api.API, moduleRegistrar ModuleRegistrar, actionRegistrar ActionRegistrar, ws event.WSClientGetter, 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(ctx context.Context, object runtime.Object) (*ObjectStatusResponse, error)

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

func (*Manager) Print

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

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

func (*Manager) SetOctantClient added in v0.15.0

func (m *Manager) SetOctantClient(client javascript.OctantClient)

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(ctx context.Context, object runtime.Object) ([]component.Tab, error)

Tabs queries plugins for tabs for an object.

type ManagerInterface

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

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

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

	// ObjectStatus returns the object status
	ObjectStatus(ctx context.Context, object runtime.Object) (*ObjectStatusResponse, error)

	// SetOctantClient sets the the Octant client.
	SetOctantClient(octantClient javascript.OctantClient)
}

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
	StoreJS(name string, jspc JSPlugin) error
	GetJS(name string) (JSPlugin, bool)
	RemoveJS(name string)
	NamesJS() []string
	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) ClientRequestHandlers

func (m *ModuleProxy) ClientRequestHandlers() []octant.ClientRequestHandler

func (*ModuleProxy) Content

func (m *ModuleProxy) Content(ctx context.Context, contentPath 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) 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) ResetCRDs

func (ModuleProxy) ResetCRDs(ctx context.Context) error

ResetCRDs 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
	// Unregister unregisters a module.
	Unregister(mod module.Module)
}

ModuleRegistrar is a module registrar.

type ModuleService

type ModuleService interface {
	Service

	Navigation(ctx context.Context) (navigation.Navigation, error)
	Content(ctx context.Context, 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(ctx context.Context, dashboardAPIAddress string) (Metadata, error)
	Print(ctx context.Context, object runtime.Object) (PrintResponse, error)
	PrintTab(ctx context.Context, object runtime.Object) (TabResponse, error)
	ObjectStatus(ctx context.Context, object runtime.Object) (ObjectStatusResponse, error)
	HandleAction(ctx context.Context, actionName string, 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.

type TabResponse

type TabResponse struct {
	Tab *component.Tab `json:"tab"`
}

TabResponse is a tab printer response from the plugin. The dashboard will use this to create an additional tab for an object.

Directories

Path Synopsis
api
fake
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.
fake
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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