services

package
v0.0.0-...-6819fcb Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartingGroupMapCapacity    = 10
	StartingResourceMapCapacity = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionManager

type ConnectionManager[ClientT any] interface {
	rt.ResourceConnectionProvider

	// InjectConnection injects the connection by id into the plugin context
	InjectConnection(ctx *types.PluginContext, id string) error

	// CheckConnection checks the status of a connection
	CheckConnection(
		ctx *types.PluginContext,
		conn *types.Connection,
		client *ClientT,
	) (types.ConnectionStatus, error)

	// GetConnectionClient returns the necessary client for the given auth
	// This method should be used by resourcers to get the client for the given
	// auth.
	GetConnectionClient(ctx *types.PluginContext, id string) (*ClientT, error)

	// RefreshConnectionClient performs any actions necessary to refresh a client for the given auth.
	// This may include refreshing credentials, or re-initializing the client if it has been
	// invalidated.
	RefreshConnectionClient(ctx *types.PluginContext, id string) error

	// GetCurrentConnectionClient returns the current client for the given auth
	GetCurrentConnectionClient(ctx *types.PluginContext) (*ClientT, error)

	// RefreshCurrentConnectionClient performs any actions necessary to refresh the current client for the given auth.
	RefreshCurrentConnectionClient(ctx *types.PluginContext) error

	// GetConnectionNamespaces returns the namespaces for the given connection, if any. If the connection does not support
	// namespaces, it will return an empty slice.
	GetConnectionNamespaces(ctx *types.PluginContext, id string) ([]string, error)
}

ConnectionManager is an interface that resource managers must implement in order to manage the various authenticated targets that a resource plugin can talk to.

For example, a user may have multiple AWS accounts and roles they would like to incorporate into the IDE. However, each account (and role) has it's own authorizations, and must used different credentials to access. As such, the user would like to separate these backends into different connections, so that they can easily switch between them. For this example, a connection would consist of the account and role, and the resource auth manager would be responsible for setting up, switching between, and managing these authd clients.

func NewConnectionManager

func NewConnectionManager[ClientT any](
	factory factories.ResourceClientFactory[ClientT],
	loader func(*types.PluginContext) ([]types.Connection, error),
	checker func(*types.PluginContext, *types.Connection, *ClientT) (types.ConnectionStatus, error),
	namespaceLoader func(*types.PluginContext, *ClientT) ([]string, error),
) ConnectionManager[ClientT]

NewConnectionManager creates a new service to manage the various auth contexts for a plugin with an authenticated backend.

type DynamicResourceTypeManager

type DynamicResourceTypeManager[DiscoveryClientT any] struct {
	*StaticResourceTypeManager // embed this last for pointer receiver semantics
	// contains filtered or unexported fields
}

DynamicResourceTypeManager is an resource type manager that provides a dynamic set of resource types that can change with each connection. This is useful for resource backends that have a dynamic set of resource types that can change with each connection, for example, different Kubernetes Clusters running different versions.

The discovery manager requires defining the the type of the discovery client, as well as the options type for the discovery client. The discovery client is responsible for discovering the available resource types within a connection, e.g. a Kubernetes cluster, AWS account, etc.

This discovery manager is optional, and if none is provided, the resource manager will use all resource types provided by the resource type manager.

func (*DynamicResourceTypeManager[DiscoveryClientT]) GetConnectionResourceTypes

func (r *DynamicResourceTypeManager[DiscoveryClientT]) GetConnectionResourceTypes(
	connectionID string,
) ([]types.ResourceMeta, error)

func (*DynamicResourceTypeManager[DiscoveryClientT]) GetGroups

func (r *DynamicResourceTypeManager[DiscoveryClientT]) GetGroups(
	connID string,
) map[string]types.ResourceGroup

func (*DynamicResourceTypeManager[DiscoveryClientT]) RemoveConnection

func (r *DynamicResourceTypeManager[DiscoveryClientT]) RemoveConnection(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

func (*DynamicResourceTypeManager[DiscoveryClientT]) SyncConnection

func (r *DynamicResourceTypeManager[DiscoveryClientT]) SyncConnection(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

type InformerManager

type InformerManager[ClientT, InformerT any] struct {
	// contains filtered or unexported fields
}

InformerManager is an interface for managing informers for the various resource services. An informer watches for changes to resources and broadcasts those changes to the IDE event subsystem.

The Informer system is heavily inspired and built around the concept pioneered by the Kubernetes API Server, and as such, the informer system is a generalized manager for informer implementation similar to that of the Kubernetes API Server and the corresponding client-go library.

More information on the Kubernetes informer design can be found here: https://www.cncf.io/blog/2019/10/15/extend-kubernetes-via-a-shared-informer/

An important note here is that due to the desired behavior of the resourcer clients being able to use the informer local cache for their operations, the informer manager will be provided the same client that the resourcer clients use for their operations. If multiple clients are used to set up informers, they should be injected as a dependency into the Client setup in the ResourceClientFactory.

func NewInformerManager

func NewInformerManager[ClientT, InformerT any](
	opts *types.InformerOptions[ClientT, InformerT],
	addChan chan types.InformerAddPayload,
	updateChan chan types.InformerUpdatePayload,
	deleteChan chan types.InformerDeletePayload,
) *InformerManager[ClientT, InformerT]

func (*InformerManager[CT, IT]) CreateConnectionInformer

func (i *InformerManager[CT, IT]) CreateConnectionInformer(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
	client *CT,
) error

func (*InformerManager[CT, IT]) HasInformer

func (i *InformerManager[CT, IT]) HasInformer(
	_ *pkgtypes.PluginContext,
	connectionID string,
) bool

HasInformer checks to see if the informer manager has an informer for the given connection.

func (*InformerManager[CT, IT]) RegisterResource

func (i *InformerManager[CT, IT]) RegisterResource(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
	resource types.ResourceMeta,
) error

RegisterResource registers a resource with the informer manager for a given client. This is called when a new context has been started for the first time.

func (*InformerManager[CT, IT]) Run

func (i *InformerManager[CT, IT]) Run(
	stopCh <-chan struct{},
	controllerAddChan chan types.InformerAddPayload,
	controllerUpdateChan chan types.InformerUpdatePayload,
	controllerDeleteChan chan types.InformerDeletePayload,
) error

Run starts the informer manager, and blocks until the stop channel is closed. Acts as a fan-in aggregator for the various informer channels.

func (*InformerManager[CT, IT]) StartConnection

func (i *InformerManager[CT, IT]) StartConnection(
	_ *pkgtypes.PluginContext,
	connectionID string,
) error

StartConnection starts the informer for a given resource connection, and sends events to the given event channels.

func (*InformerManager[CT, IT]) StopConnection

func (i *InformerManager[CT, IT]) StopConnection(
	_ *pkgtypes.PluginContext,
	connectionID string,
) error

StopConnection stops the informer for a given resource connection.

type LayoutManager

type LayoutManager interface {
	GetLayout(layoutID string) ([]types.LayoutItem, error)
	SetLayout(layoutID string, layout []types.LayoutItem) error
	GetDefaultLayout() ([]types.LayoutItem, error)
	GenerateLayoutFromMetas(metas []types.ResourceMeta)
}

func NewLayoutManager

func NewLayoutManager(opts *types.LayoutOpts) LayoutManager

type ResourceTypeManager

type ResourceTypeManager interface {
	// GetGroups returns the grouped tree of resources available.
	GetGroups(connectionID string) map[string]types.ResourceGroup

	// GetGroup returns the group information by it's string representation
	GetGroup(string) (types.ResourceGroup, error)

	// GetResourceTypes returns the all of the available resource types for the resource manager
	GetResourceTypes(connectionID string) map[string]types.ResourceMeta

	// GetResourceType returns the resource type information by it's string representation
	// For example, "core::v1::Pod" or "ec2::2012-12-01::EC2Instance"
	GetResourceType(string) (*types.ResourceMeta, error)

	// GetTableDefinition returns the resource table definition for the resource type
	GetResourceDefinition(string) (types.ResourceDefinition, error)

	// HasResourceType checks to see if the resource type exists
	HasResourceType(string) bool

	// GetAvailableResourceTypes returns the available resource types for the given namespace
	GetConnectionResourceTypes(string) ([]types.ResourceMeta, error)

	// SyncResourceNamespace sets up a given connection with the manager, and syncs the available resource types
	// given a set of options
	SyncConnection(*pkgtypes.PluginContext, *pkgtypes.Connection) error

	// and stops the client for the namespace
	RemoveConnection(*pkgtypes.PluginContext, *pkgtypes.Connection) error
}

ResourceTypeManager is the interface for which resource type managers must implement.

If a resource backend has a dynamic set of resource types that can change with each connection (for example, different Kubernetes Clusters running different versions), it should instantiate a DynamicResourceTypeManager.

If a resource backend has a static set of resource types that does not change with each connection (for example, AWS, GCP, Azure, etc.), it should instantiate the StaticResourceTypeManager.

func NewDynamicResourceTypeManager

func NewDynamicResourceTypeManager[DiscoveryClientT any](
	resourceTypes []types.ResourceMeta,
	resourceGroups []types.ResourceGroup,
	resourceDefinitions map[string]types.ResourceDefinition,
	defaultResourceDefinition types.ResourceDefinition,
	factory factories.ResourceDiscoveryClientFactory[DiscoveryClientT],
	syncer func(ctx *pkgtypes.PluginContext, client *DiscoveryClientT) ([]types.ResourceMeta, error),
) ResourceTypeManager

NewDynamicResourceTypeManager creates a new resource type discovery manager to be used with the the resource backend, given a client factory and a sync function.

func NewStaticResourceTypeManager

func NewStaticResourceTypeManager(
	resourceTypes []types.ResourceMeta,
	resourceGroups []types.ResourceGroup,
	resourceDefinitions map[string]types.ResourceDefinition,
	defaultResourceDefinition types.ResourceDefinition,
) ResourceTypeManager

NewStaticResourceTypeManager creates a new resource type manager with a static set of resource types that does not change with each connection For example, AWS, GCP, Azure, etc.

type ResourcerManager

type ResourcerManager[ClientT any] interface {
	// RegisterResourcer registers a new resourcer for the given resource type
	RegisterResourcer(resourceType string, resourcer types.Resourcer[ClientT]) error
	// RegisterDynamicResourcer registers a new dynamic resourcer for the given resource type
	RegisterDynamicResourcer(resourceType string, resourcer types.DynamicResourcer[ClientT]) error
	// RegisterResourcersFromMap registers a new resourcer for the given resource type given
	// a map of meta objects
	RegisterResourcersFromMap(resourcerMap map[types.ResourceMeta]types.Resourcer[ClientT]) error
	// RegisterDunamicResourcersFromMap registers a new dynamic resourcer for the given resource type given
	// a map of patterns
	RegisterDynamicResourcersFromMap(resourcerMap map[string]types.DynamicResourcer[ClientT]) error
	// DeregisterResourcer deregisters the resourcer for the given resource type
	DeregisterResourcer(resourceType string) error
	// GetResourcer returns the resourcer for the given resource type
	GetResourcer(resourceType string) (types.Resourcer[ClientT], error)
	// GetDynamicResourcer attempts to find a dynamic resourcer for the given resource type
	GetDynamicResourcer(resourceType string) (types.DynamicResourcer[ClientT], error)
	// HasDynamicResourcers returns true if there are dynamic resourcers associated with the manager
	HasDynamicResourcers() bool
}

ResourcerManager manages all of the resourcers for a given resource type. It is responsible for registering, retreiving, and managing resourcers for a given resource type.

func NewResourcerManager

func NewResourcerManager[ClientT any]() ResourcerManager[ClientT]

type StaticResourceTypeManager

type StaticResourceTypeManager struct {
	sync.RWMutex // embed this last for pointer receiver semantics
	// contains filtered or unexported fields
}

StaticResourceTypeManager is a resource type manager that provides a static set of resource types that does not change with each connection. This is useful for resource backends that have a static set of resource types that does not change with each connection, for example, AWS, GCP, Azure, etc.

func (*StaticResourceTypeManager) GetAvailableResourceTypes

func (r *StaticResourceTypeManager) GetAvailableResourceTypes(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) ([]types.ResourceMeta, error)

func (*StaticResourceTypeManager) GetConnectionResourceTypes

func (r *StaticResourceTypeManager) GetConnectionResourceTypes(
	connectionID string,
) ([]types.ResourceMeta, error)

func (*StaticResourceTypeManager) GetGroup

func (*StaticResourceTypeManager) GetGroups

func (*StaticResourceTypeManager) GetResourceDefinition

func (r *StaticResourceTypeManager) GetResourceDefinition(
	s string,
) (types.ResourceDefinition, error)

func (*StaticResourceTypeManager) GetResourceType

func (r *StaticResourceTypeManager) GetResourceType(
	s string,
) (*types.ResourceMeta, error)

func (*StaticResourceTypeManager) GetResourceTypes

func (r *StaticResourceTypeManager) GetResourceTypes(_ string) map[string]types.ResourceMeta

func (*StaticResourceTypeManager) HasResourceType

func (r *StaticResourceTypeManager) HasResourceType(s string) bool

func (*StaticResourceTypeManager) RemoveConnection

func (r *StaticResourceTypeManager) RemoveConnection(
	pluginCtx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

func (*StaticResourceTypeManager) SyncConnection

func (r *StaticResourceTypeManager) SyncConnection(
	_ *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

Jump to

Keyboard shortcuts

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