synccontext

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithMapping

func WithMapping(ctx context.Context, nameMapping NameMapping) context.Context

WithMapping adds the mapping to the context

func WithMappingFromObjects

func WithMappingFromObjects(ctx context.Context, pObj, vObj client.Object) (context.Context, error)

WithMappingFromObjects adds the mapping to the context

Types

type AddQueueFunc

type AddQueueFunc func(nameMapping NameMapping, queue workqueue.TypedRateLimitingInterface[ctrl.Request])

type BidirectionalObjectCache

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

func NewBidirectionalObjectCache

func NewBidirectionalObjectCache(obj client.Object) *BidirectionalObjectCache

func (*BidirectionalObjectCache) Host

func (*BidirectionalObjectCache) Start

func (*BidirectionalObjectCache) Virtual

func (o *BidirectionalObjectCache) Virtual() *ObjectCache

type ControllerContext

type ControllerContext struct {
	context.Context

	LocalManager          ctrl.Manager
	VirtualManager        ctrl.Manager
	VirtualRawConfig      *clientcmdapi.Config
	VirtualClusterVersion *version.Info

	WorkloadNamespaceClient client.Client

	Config   *config.VirtualClusterConfig
	StopChan <-chan struct{}

	// PreServerHooks are extra filters to inject into the server before everything else
	PreServerHooks []Filter

	// PostServerHooks are extra filters to inject into the server after everything else
	PostServerHooks []Filter

	// AcquiredLeaderHooks are hooks to start after vCluster acquired leader
	AcquiredLeaderHooks []Hook

	// Mappings hold the objects mappings store
	Mappings MappingsRegistry
}

func (*ControllerContext) ToRegisterContext

func (c *ControllerContext) ToRegisterContext() *RegisterContext

type Filter

type Filter func(http.Handler, *ControllerContext) http.Handler

type Hook

type Hook func(ctx *ControllerContext) error

type Mapper

type Mapper interface {
	// Migrate is called right before the controllers are started and should be used for
	// validating the mappings are initialized in the store correctly. Mapper is passed here
	// as an argument because we want underling structs to retrieve the name from the topmost
	// struct that implements the mapping as overriding methods within embedded structs is not possible in golang.
	Migrate(ctx *RegisterContext, mapper Mapper) error

	// GroupVersionKind retrieves the group version kind
	GroupVersionKind() schema.GroupVersionKind

	// VirtualToHost translates a virtual name to a physical name
	VirtualToHost(ctx *SyncContext, req types.NamespacedName, vObj client.Object) types.NamespacedName

	// HostToVirtual translates a physical name to a virtual name
	HostToVirtual(ctx *SyncContext, req types.NamespacedName, pObj client.Object) types.NamespacedName

	// IsManaged determines if a physical object is managed by the vCluster
	IsManaged(ctx *SyncContext, pObj client.Object) (bool, error)
}

Mapper holds the mapping logic for an object

type MappingsRegistry

type MappingsRegistry interface {
	// ByGVK retrieves a mapper by GroupVersionKind.
	ByGVK(gvk schema.GroupVersionKind) (Mapper, error)

	// List retrieves all mappers as a map
	List() map[schema.GroupVersionKind]Mapper

	// Has checks if the store contains a mapper with the given GroupVersionKind.
	Has(gvk schema.GroupVersionKind) bool

	// AddMapper adds the given mapper to the store.
	AddMapper(mapper Mapper) error

	// Store returns the mapping store of the registry
	Store() MappingsStore
}

MappingsRegistry holds different mappings

type MappingsStore

type MappingsStore interface {
	// Watch builds a source that can be used in a controller to watch on changes within the store for a given
	// GroupVersionKind.
	Watch(gvk schema.GroupVersionKind, addQueueFn AddQueueFunc) source.Source

	// StartGarbageCollection starts the mapping store garbage collection
	StartGarbageCollection(ctx context.Context)

	// HasHostObject checks if the store has a mapping for the host object
	HasHostObject(ctx context.Context, pObj Object) bool

	// HasVirtualObject checks if the store has a mapping for the virtual object
	HasVirtualObject(ctx context.Context, pObj Object) bool

	// AddReferenceAndSave adds a reference mapping and directly saves the mapping
	AddReferenceAndSave(ctx context.Context, nameMapping, belongsTo NameMapping) error

	// DeleteReferenceAndSave deletes a reference mapping and directly saves the mapping
	DeleteReferenceAndSave(ctx context.Context, nameMapping, belongsTo NameMapping) error

	// AddReference adds a reference mapping
	AddReference(ctx context.Context, nameMapping, belongsTo NameMapping) error

	// DeleteReference deletes a reference mapping
	DeleteReference(ctx context.Context, nameMapping, belongsTo NameMapping) error

	// SaveMapping saves the mapping in the backing store
	SaveMapping(ctx context.Context, mapping NameMapping) error

	// DeleteMapping deletes the mapping in the backing store
	DeleteMapping(ctx context.Context, mapping NameMapping) error

	// ReferencesTo retrieves all known references to this object
	ReferencesTo(ctx context.Context, vObj Object) []NameMapping

	// HostToVirtualName maps the given host object to the virtual name if found within the store
	HostToVirtualName(ctx context.Context, pObj Object) (types.NamespacedName, bool)

	// VirtualToHostName maps the given virtual object to the host name if found within the store
	VirtualToHostName(ctx context.Context, vObj Object) (types.NamespacedName, bool)
}

MappingsStore holds logic to store and retrieve mappings

type NameMapping

type NameMapping struct {
	schema.GroupVersionKind

	VirtualName types.NamespacedName
	HostName    types.NamespacedName
}

func MappingFrom

func MappingFrom(ctx context.Context) (NameMapping, bool)

MappingFrom returns the value of the original request path key on the ctx

func NewNameMappingFrom

func NewNameMappingFrom(pObj, vObj client.Object) (NameMapping, error)

func (NameMapping) Empty

func (n NameMapping) Empty() bool

func (NameMapping) Equals

func (n NameMapping) Equals(other NameMapping) bool

func (NameMapping) Host

func (n NameMapping) Host() Object

func (NameMapping) String

func (n NameMapping) String() string

func (NameMapping) Virtual

func (n NameMapping) Virtual() Object

type Object

type Object struct {
	schema.GroupVersionKind
	types.NamespacedName
}

func (Object) Empty

func (o Object) Empty() bool

func (Object) Equals

func (o Object) Equals(other Object) bool

func (Object) String

func (o Object) String() string

func (Object) WithHostName

func (o Object) WithHostName(pName types.NamespacedName) NameMapping

func (Object) WithVirtualName

func (o Object) WithVirtualName(vName types.NamespacedName) NameMapping

type ObjectCache

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

func (*ObjectCache) Delete

func (o *ObjectCache) Delete(obj client.Object)

func (*ObjectCache) Get

func (*ObjectCache) Put

func (o *ObjectCache) Put(obj client.Object)

type RegisterContext

type RegisterContext struct {
	context.Context

	Config *config.VirtualClusterConfig

	CurrentNamespace       string
	CurrentNamespaceClient client.Client

	Mappings MappingsRegistry

	VirtualManager  ctrl.Manager
	PhysicalManager ctrl.Manager
}

func (*RegisterContext) ToSyncContext

func (r *RegisterContext) ToSyncContext(logName string) *SyncContext

type SyncContext

type SyncContext struct {
	context.Context

	Log loghelper.Logger

	Config *config.VirtualClusterConfig

	PhysicalClient client.Client
	VirtualClient  client.Client

	ObjectCache *BidirectionalObjectCache

	Mappings MappingsRegistry

	CurrentNamespace       string
	CurrentNamespaceClient client.Client
}

func (*SyncContext) Close

func (s *SyncContext) Close() error

type SyncDirection

type SyncDirection string
const (
	SyncVirtualToHost SyncDirection = "VirtualToHost"
	SyncHostToVirtual SyncDirection = "HostToVirtual"
)

type SyncEvent

type SyncEvent[T client.Object] struct {
	HostOld T
	Host    T

	VirtualOld T
	Virtual    T
}

func NewSyncEvent

func NewSyncEvent[T client.Object](pObj, vObj T) *SyncEvent[T]

func NewSyncEventWithOld

func NewSyncEventWithOld[T client.Object](pObjOld, pObj, vObjOld, vObj T) *SyncEvent[T]

type SyncToHostEvent

type SyncToHostEvent[T client.Object] struct {
	HostOld T

	Virtual T
}

func NewSyncToHostEvent

func NewSyncToHostEvent[T client.Object](vObj T) *SyncToHostEvent[T]

type SyncToVirtualEvent

type SyncToVirtualEvent[T client.Object] struct {
	VirtualOld T

	Host T
}

func NewSyncToVirtualEvent

func NewSyncToVirtualEvent[T client.Object](pObj T) *SyncToVirtualEvent[T]

Jump to

Keyboard shortcuts

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