mccontroller

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

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNamespaceScheduledToCluster

func IsNamespaceScheduledToCluster(obj client.Object, clusterID string) error

Types

type Cache

type Cache interface {
	Start() error
	WaitForCacheSync() bool
	Stop()
}

Cache is the interface used by Controller to start and wait for caches to sync.

type ClusterInterface

type ClusterInterface interface {
	GetClusterName() string
	GetOwnerInfo() (string, string, string)
	GetObject() (client.Object, error)
	AddEventHandler(client.Object, clientgocache.ResourceEventHandler) error
	GetInformer(objectType client.Object) (cache.Informer, error)
	GetClientSet() (clientset.Interface, error)
	GetDelegatingClient() (client.Client, error)
	GetRestConfig() *rest.Config
	Cache
}

ClusterInterface decouples the controller package from the cluster package.

type Getter

type Getter interface {
	GetObject(string, string) (client.Object, error)
}

Getter interface is used to get the CRD object that abstracts the cluster.

type MultiClusterController

type MultiClusterController struct {
	sync.Mutex

	MultiClusterInterface

	Options
	// contains filtered or unexported fields
}

MultiClusterController implements the multicluster controller pattern. A MultiClusterController owns a client-go workqueue. The WatchClusterResource methods set up the queue to receive reconcile requests, e.g., CRUD events from a tenant cluster. The Requests are processed by the user-provided Reconciler. MultiClusterController saves all watched tenant clusters in a set.

func NewMCController

func NewMCController(objectType client.Object, objectListType client.ObjectList, rc reconciler.DWReconciler, opts ...OptConfig) (*MultiClusterController, error)

NewMCController creates a new MultiClusterController.

func (*MultiClusterController) Eventf

func (c *MultiClusterController) Eventf(clusterName string, ref *corev1.ObjectReference, eventtype string, reason, messageFmt string, args ...interface{}) error

Eventf constructs an event from the given information and puts it in the queue for sending. 'ref' is the object this event is about. Event will make a reference or you may also pass a reference to the object directly. 'eventtype' of this event, and can be one of Normal, Warning. New types could be added in future 'reason' is the reason this event is generated. 'reason' should be short and unique; it should be in UpperCamelCase format (starting with a capital letter). "reason" will be used to automate handling of events, so imagine people writing switch statements to handle them. You want to make that easy. 'message' is intended to be human readable.

The resulting event will be created in the same namespace as the reference object.

func (*MultiClusterController) FilterObjectFromSchedulingResult

func (c *MultiClusterController) FilterObjectFromSchedulingResult(req reconciler.Request) bool

func (*MultiClusterController) Get

func (c *MultiClusterController) Get(clusterName, namespace, name string, obj client.Object) error

Get returns object with specific cluster, namespace and name.

func (*MultiClusterController) GetCluster

func (c *MultiClusterController) GetCluster(clusterName string) ClusterInterface

func (*MultiClusterController) GetClusterClient

func (c *MultiClusterController) GetClusterClient(clusterName string) (clientset.Interface, error)

GetClusterClient returns the cluster's clientset client for direct access to tenant apiserver

func (*MultiClusterController) GetClusterNames

func (c *MultiClusterController) GetClusterNames() []string

GetClusterNames returns the name list of all managed tenant clusters

func (*MultiClusterController) GetClusterObject

func (c *MultiClusterController) GetClusterObject(clusterName string) (client.Object, error)

func (*MultiClusterController) GetControllerName

func (c *MultiClusterController) GetControllerName() string

GetControllerName get the mccontroller name, is used to uniquely identify the Controller in tracing, logging and monitoring.

func (*MultiClusterController) GetObjectKind

func (c *MultiClusterController) GetObjectKind() string

GetObjectKind is the objectKind name this controller watch to.

func (*MultiClusterController) GetOwnerInfo

func (c *MultiClusterController) GetOwnerInfo(clusterName string) (string, string, string, error)

func (*MultiClusterController) List

func (c *MultiClusterController) List(clusterName string, instanceList client.ObjectList, opts ...client.ListOption) error

List returns a list of objects with specific cluster.

func (*MultiClusterController) RegisterClusterResource

func (c *MultiClusterController) RegisterClusterResource(cluster ClusterInterface, o WatchOptions) error

RegisterClusterResource get the informer *before* trying to wait for the caches to sync so that we have a chance to register their intended caches.

func (*MultiClusterController) RequeueObject

func (c *MultiClusterController) RequeueObject(clusterName string, obj interface{}) error

RequeueObject requeues the cluster object, thus reconcileHandler can reconcile it again.

func (*MultiClusterController) Start

func (c *MultiClusterController) Start(stop <-chan struct{}) error

Start starts the ClustersController's control loops (as many as MaxConcurrentReconciles) in separate channels and blocks until an empty struct is sent to the stop channel.

func (*MultiClusterController) TeardownClusterResource

func (c *MultiClusterController) TeardownClusterResource(cluster ClusterInterface)

TeardownClusterResource forget the cluster it watches. The cluster informer should stop together.

func (*MultiClusterController) WatchClusterResource

func (c *MultiClusterController) WatchClusterResource(cluster ClusterInterface, o WatchOptions) error

WatchClusterResource configures the Controller to watch resources of the same Kind as objectType, in the specified cluster, generating reconcile Requests from the ClusterInterface's context and the watched objects' namespaces and names.

type MultiClusterInterface

type MultiClusterInterface interface {
	WatchClusterResource(cluster ClusterInterface, o WatchOptions) error
	RegisterClusterResource(cluster ClusterInterface, o WatchOptions) error
	TeardownClusterResource(cluster ClusterInterface)
	GetControllerName() string
	GetObjectKind() string
	Get(clusterName, namespace, name string, obj client.Object) error
	List(clusterName string, instanceList client.ObjectList, opts ...client.ListOption) error
	GetCluster(clusterName string) ClusterInterface
	GetClusterClient(clusterName string) (clientset.Interface, error)
	GetClusterObject(clusterName string) (client.Object, error)
	GetOwnerInfo(clusterName string) (string, string, string, error)
	GetClusterNames() []string
}

type OptConfig

type OptConfig func(*Options)

func WithControllerName

func WithControllerName(name string) OptConfig

WithControllerName set the controller name.

func WithJitterPeriod

func WithJitterPeriod(t time.Duration) OptConfig

WithJitterPeriod set JitterPeriod.

func WithMaxConcurrentReconciles

func WithMaxConcurrentReconciles(n int) OptConfig

WithMaxConcurrentReconciles set MaxConcurrentReconciles if valid.

func WithOptions

func WithOptions(o *Options) OptConfig

WithOptions set options.

func WithReconciler

func WithReconciler(rc reconciler.DWReconciler) OptConfig

WithReconciler set the reconciler.

func WithWorkQueue

func WithWorkQueue(q workqueue.RateLimitingInterface) OptConfig

WithWorkQueue set the workqueue for mccontroller.

type Options

type Options struct {
	// JitterPeriod is the time to wait after an error to start working again.
	JitterPeriod time.Duration

	// MaxConcurrentReconciles is the number of concurrent control loops.
	MaxConcurrentReconciles int

	Reconciler reconciler.DWReconciler

	// Queue can be used to override the default queue.
	Queue workqueue.RateLimitingInterface
	// contains filtered or unexported fields
}

Options are the arguments for creating a new Controller.

type WatchOptions

type WatchOptions struct {
	AttachUID bool // the object UID will be added to the reconciler request if it is true
}

WatchOptions is used as an argument of WatchResource methods (just a placeholder for now). TODO: consider implementing predicates.

Jump to

Keyboard shortcuts

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