commons

package
v0.0.0-...-4df37e3 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCPproto  protocol = "tcp"
	HTTPproto protocol = "http"
)

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "KUBERLOGIC_SERVICE_PLUGIN",
	MagicCookieValue: "com.kuberlogic.service.plugin",
}

HandshakeConfig are used to just do a basic handshake between a plugin and host. If the handshake fails, a user friendly error is shown. This prevents users from executing bad plugins or executing a plugin directory. It is a UX feature, not a security feature.

Functions

func FromUnstructured

func FromUnstructured(u map[string]interface{}, obj interface{}) error

func ServePlugin

func ServePlugin(name string, pl PluginService)

func ToUnstructured

func ToUnstructured(obj interface{}, gvk schema.GroupVersionKind) (*unstructured.Unstructured, error)

Types

type CredentialsMethodExec

type CredentialsMethodExec struct {
	PodSelector v12.LabelSelector

	Container string
	Command   []string
}

type Plugin

type Plugin struct {
	// Impl Injection
	Impl PluginService
}

This is the implementation of plugin.Plugin so we can serve/consume this

This has two methods: Server must return an RPC server for this plugin type. We construct a PluginServer for this.

Client must return an implementation of our interface that communicates over an RPC client. We return PluginClient for this.

Ignore MuxBroker. That is used to create more multiplexed streams on our plugin connection and is a more advanced use case.

func (Plugin) Client

func (Plugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

func (*Plugin) Server

func (p *Plugin) Server(*plugin.MuxBroker) (interface{}, error)

type PluginClient

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

Here is an implementation that talks over RPC

func (*PluginClient) Convert

func (g *PluginClient) Convert(req PluginRequest) *PluginResponse

func (*PluginClient) Default

func (g *PluginClient) Default() *PluginResponseDefault

func (*PluginClient) GetCredentialsMethod

func (*PluginClient) Status

func (*PluginClient) Types

func (g *PluginClient) Types() *PluginResponse

func (*PluginClient) ValidateCreate

func (g *PluginClient) ValidateCreate(req PluginRequest) *PluginResponseValidation

func (*PluginClient) ValidateDelete

func (g *PluginClient) ValidateDelete(req PluginRequest) *PluginResponseValidation

func (*PluginClient) ValidateUpdate

func (g *PluginClient) ValidateUpdate(req PluginRequest) *PluginResponseValidation

type PluginRequest

type PluginRequest struct {
	// Requested service Name
	Name string
	// Namespace where the service object must be located
	Namespace string
	// Optional. Host is address by which service should be available.
	Host string

	// Service Replicas
	Replicas int32

	// Requested service Version
	Version string

	// If a service should be exposed via TLS
	Insecure bool

	// TLSSecretName is a Kubernetes secret that contains tls.key / tls.crt fields. Must reside in the same namespace
	TLSSecretName string

	// Service resource Limits. Manipulated via SetLimits / GetLimits methods.
	Limits []byte

	// Service will use StorageClass / IngressClass for volume / ingress or default if empty
	StorageClass string
	IngressClass string

	// Additional Parameters
	Parameters map[string]interface{}

	// Credentials
	Credentials map[string]string

	// Objects contains a list of service related objects
	Objects []*unstructured.Unstructured
}

func (*PluginRequest) AddObject

func (pl *PluginRequest) AddObject(o *unstructured.Unstructured)

func (*PluginRequest) GetLimits

func (pl *PluginRequest) GetLimits() (*v1.ResourceList, error)

func (*PluginRequest) GetObjects

func (pl *PluginRequest) GetObjects() []*unstructured.Unstructured

func (*PluginRequest) RenderTemplate

func (pl *PluginRequest) RenderTemplate(tpl string) (*TemplatedValue, error)

func (*PluginRequest) SetLimits

func (pl *PluginRequest) SetLimits(limits *v1.ResourceList) error

func (*PluginRequest) SetObjects

func (pl *PluginRequest) SetObjects(objs []*unstructured.Unstructured)

type PluginRequestCredentialsMethod

type PluginRequestCredentialsMethod struct {
	// service Name
	Name string

	// Credentials Data
	Data map[string]string
}

func (*PluginRequestCredentialsMethod) RenderTemplate

func (m *PluginRequestCredentialsMethod) RenderTemplate(tpl string) (*TemplatedValue, error)

type PluginRequestEmpty

type PluginRequestEmpty struct{}

type PluginResponse

type PluginResponse struct {
	Objects  []*unstructured.Unstructured
	Protocol protocol
	Service  string
	Err      string
}

func ResponseFromObject

func ResponseFromObject(object client.Object, gvk schema.GroupVersionKind, service string, protocol protocol) *PluginResponse

func (*PluginResponse) AddUnstructuredObject

func (pl *PluginResponse) AddUnstructuredObject(object client.Object, gvk schema.GroupVersionKind) error

func (*PluginResponse) Error

func (pl *PluginResponse) Error() error

type PluginResponseCredentialsMethod

type PluginResponseCredentialsMethod struct {
	Method string // exec, etc
	Exec   CredentialsMethodExec

	Err string
}

type PluginResponseDefault

type PluginResponseDefault struct {
	Replicas int32
	Version  string
	Host     string
	// *v1.ResourceList
	Limits     []byte
	Parameters map[string]interface{}
	Err        string
}

func (*PluginResponseDefault) Error

func (pl *PluginResponseDefault) Error() error

func (*PluginResponseDefault) GetLimits

func (pl *PluginResponseDefault) GetLimits() *v1.ResourceList

func (*PluginResponseDefault) SetLimits

func (pl *PluginResponseDefault) SetLimits(limits *v1.ResourceList) error

type PluginResponseStatus

type PluginResponseStatus struct {
	IsReady bool
	Err     string
}

func (*PluginResponseStatus) Error

func (pl *PluginResponseStatus) Error() error

type PluginResponseValidation

type PluginResponseValidation struct {
	Err string
}

func (*PluginResponseValidation) Error

func (pl *PluginResponseValidation) Error() error

type PluginServer

type PluginServer struct {
	// This is the real implementation
	Impl PluginService
}

Here is the RPC server that PluginClient talks to, conforming to the requirements of net/rpc

func (*PluginServer) Convert

func (s *PluginServer) Convert(req PluginRequest, resp *PluginResponse) error

func (*PluginServer) Default

func (*PluginServer) GetCredentialsMethod

func (*PluginServer) Status

func (s *PluginServer) Status(req PluginRequest, resp *PluginResponseStatus) error

func (*PluginServer) Types

func (*PluginServer) ValidateCreate

func (s *PluginServer) ValidateCreate(req PluginRequest, resp *PluginResponseValidation) error

func (*PluginServer) ValidateDelete

func (s *PluginServer) ValidateDelete(req PluginRequest, resp *PluginResponseValidation) error

func (*PluginServer) ValidateUpdate

func (s *PluginServer) ValidateUpdate(req PluginRequest, resp *PluginResponseValidation) error

type PluginService

type PluginService interface {
	Convert(req PluginRequest) *PluginResponse
	Status(req PluginRequest) *PluginResponseStatus
	Types() *PluginResponse

	Default() *PluginResponseDefault
	ValidateCreate(req PluginRequest) *PluginResponseValidation
	ValidateUpdate(req PluginRequest) *PluginResponseValidation
	ValidateDelete(req PluginRequest) *PluginResponseValidation

	GetCredentialsMethod(req PluginRequestCredentialsMethod) *PluginResponseCredentialsMethod
}

PluginService is the interface that we're exposing as a plugin.

type TemplatedValue

type TemplatedValue struct {
	Raw      string
	Secret   bool
	SecretID string
}

Jump to

Keyboard shortcuts

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