common

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

PluginKindsAdaptableTo if there are plugin kinds that are adaptable to newer API versions, list them here. The older (adaptable) version is the key, and the value is the full list of newer plugin kinds that are capable of adapting it.

Functions

func AllPluginKinds

func AllPluginKinds() map[string]PluginKind

AllPluginKinds contains all the valid plugin kinds that Velero supports, excluding PluginLister because that is not a kind that a developer would ever need to implement (it's handled by Velero and the Velero plugin library code).

func ErrorStack

func ErrorStack(err error) *proto.Stack

ErrorStack gets a stack trace, if it exists, from the provided error, and returns it as a *proto.Stack.

func FromGRPCError

func FromGRPCError(err error) error

FromGRPCError takes a gRPC status error, extracts a stack trace from the details if it exists, and returns an error that can provide information about where it was created.

This function should be used in the internal plugin client code to convert all errors returned from the plugin server before they're passed back to the rest of the Velero codebase. This will enable them to display location information when they're logged.

func GetPluginConfig added in v1.12.0

func GetPluginConfig(kind PluginKind, name string, client corev1client.ConfigMapInterface) (*corev1.ConfigMap, error)

func HandlePanic

func HandlePanic(p interface{}) error

HandlePanic is a panic handler for the server half of velero plugins.

func NewClientDispenser

func NewClientDispenser(logger logrus.FieldLogger, clientConn *grpc.ClientConn, initFunc clientInitFunc) *clientDispenser

newClientDispenser creates a new clientDispenser.

func NewGRPCError

func NewGRPCError(err error, details ...goproto.Message) error

NewGRPCError is a convenience function for creating a new gRPC error with code = codes.Unknown

func NewGRPCErrorWithCode

func NewGRPCErrorWithCode(err error, code codes.Code, details ...goproto.Message) error

NewGRPCErrorWithCode wraps err in a gRPC status error with the error's stack trace included in the details if it exists. This provides an easy way to send stack traces from plugin servers across the wire to the plugin client.

This function should be used in the internal plugin server code to wrap all errors before they're returned.

func PluginConfigLabelSelector added in v1.12.0

func PluginConfigLabelSelector(kind PluginKind, name string) string

func ValidatePluginName

func ValidatePluginName(name string, existingNames []string) error

ValidatePluginName checks if the given name: - the plugin name has two parts separated by '/' - non of the above parts is empty - the prefix is a valid DNS subdomain name - a plugin with the same name does not already exist (if list of existing names is passed in)

Types

type ClientBase

type ClientBase struct {
	Plugin string
	Logger logrus.FieldLogger
}

ClientBase implements client and contains shared fields common to all clients.

type ClientDispenser

type ClientDispenser interface {
	ClientFor(name string) interface{}
}

type HandlerInitializer

type HandlerInitializer func(logger logrus.FieldLogger) (interface{}, error)

HandlerInitializer is a function that initializes and returns a new instance of one of Velero's plugin interfaces (ObjectStore, VolumeSnapshotter, BackupItemAction, RestoreItemAction).

type PluginBase

type PluginBase struct {
	ClientLogger logrus.FieldLogger
	*ServerMux
}

func NewPluginBase

func NewPluginBase(options ...PluginOption) *PluginBase

type PluginKind

type PluginKind string

PluginKind is a type alias for a string that describes the kind of a Velero-supported plugin.

const (
	// PluginKindObjectStore represents an object store plugin.
	PluginKindObjectStore PluginKind = "ObjectStore"

	// PluginKindVolumeSnapshotter represents a volume snapshotter plugin.
	PluginKindVolumeSnapshotter PluginKind = "VolumeSnapshotter"

	// PluginKindBackupItemAction represents a backup item action plugin.
	PluginKindBackupItemAction PluginKind = "BackupItemAction"

	// PluginKindBackupItemActionV2 represents a v2 backup item action plugin.
	PluginKindBackupItemActionV2 PluginKind = "BackupItemActionV2"

	// PluginKindRestoreItemAction represents a restore item action plugin.
	PluginKindRestoreItemAction PluginKind = "RestoreItemAction"

	// PluginKindRestoreItemActionV2 represents a v2 restore item action plugin.
	PluginKindRestoreItemActionV2 PluginKind = "RestoreItemActionV2"

	// PluginKindDeleteItemAction represents a delete item action plugin.
	PluginKindDeleteItemAction PluginKind = "DeleteItemAction"

	// PluginKindPluginLister represents a plugin lister plugin.
	PluginKindPluginLister PluginKind = "PluginLister"
)

func (PluginKind) String

func (k PluginKind) String() string

String returns the string for k.

type PluginOption

type PluginOption func(base *PluginBase)

func ClientLogger

func ClientLogger(logger logrus.FieldLogger) PluginOption

func ServerLogger

func ServerLogger(logger logrus.FieldLogger) PluginOption

type ProtoStackError

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

func (*ProtoStackError) File

func (e *ProtoStackError) File() string

func (*ProtoStackError) Function

func (e *ProtoStackError) Function() string

func (*ProtoStackError) Line

func (e *ProtoStackError) Line() int32

type ServerMux

type ServerMux struct {
	Handlers  map[string]interface{}
	ServerLog logrus.FieldLogger
	// contains filtered or unexported fields
}

ServerMux manages multiple implementations of a single plugin kind, such as pod and pvc BackupItemActions.

func NewServerMux

func NewServerMux(logger logrus.FieldLogger) *ServerMux

NewServerMux returns a new ServerMux.

func (*ServerMux) GetHandler

func (m *ServerMux) GetHandler(name string) (interface{}, error)

GetHandler returns the instance for a plugin with the given name. If an instance has already been initialized, that is returned. Otherwise, the instance is initialized by calling its initialization function.

func (*ServerMux) Names

func (m *ServerMux) Names() []string

names returns a list of all registered implementations.

func (*ServerMux) Register

func (m *ServerMux) Register(name string, f HandlerInitializer)

register validates the plugin name and registers the initializer for the given name.

type StackTracer

type StackTracer interface {
	StackTrace() errors.StackTrace
}

Jump to

Keyboard shortcuts

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