crdreplicator

package
v0.3.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package crdreplicator implements the logic for the replication of CustomResourceDefinitions between the peered clusters.

Index

Constants

View Source
const (
	LocalLabelSelector     = "liqo.io/replication"
	RemoteLabelSelector    = "liqo.io/originID"
	DestinationLabel       = "liqo.io/remoteID"
	ReplicationStatuslabel = "liqo.io/replicated"
)

Variables

View Source
var ReplicatedResourcesLabelSelector = metav1.LabelSelector{
	MatchExpressions: []metav1.LabelSelectorRequirement{
		{
			Key:      RemoteLabelSelector,
			Operator: metav1.LabelSelectorOpExists,
		},
		{
			Key:      ReplicationStatuslabel,
			Operator: metav1.LabelSelectorOpExists,
		},
	},
}

ReplicatedResourcesLabelSelector is an helper label selector to list all the replicated resources.

View Source
var (
	ResyncPeriod = 30 * time.Second
)

Functions

func SetLabelsForLocalResources

func SetLabelsForLocalResources(options *metav1.ListOptions)

Types

type Controller

type Controller struct {
	Scheme *runtime.Scheme
	client.Client
	ClientSet                      *kubernetes.Clientset
	ClusterID                      string
	RemoteDynClients               map[string]dynamic.Interface                            // for each remote cluster we save dynamic client connected to its API server
	RemoteDynSharedInformerFactory map[string]dynamicinformer.DynamicSharedInformerFactory // for each remote cluster we save the dynamic shared informer factory
	LocalDynClient                 dynamic.Interface                                       // dynamic client pointing to the local API server
	LocalDynSharedInformerFactory  dynamicinformer.DynamicSharedInformerFactory            // local dynamic shared informer factory
	// RegisteredResources is a list of GVRs of resources to be replicated, with the associated peering phase when the replication has to occur.
	RegisteredResources []configv1alpha1.Resource
	// UnregisteredResources, each time a resource is removed from the configuration it is saved in this list,
	// it stays here until the associated watcher, if running, is stopped.
	UnregisteredResources []metav1.GroupVersionResource
	// LocalWatchers, we save all the running watchers monitoring the local resources:(registeredResource, chan)).
	LocalWatchers map[string]chan struct{}
	// RemoteWatchers, for each peering cluster we save all the running watchers monitoring the replicated resources:
	// (clusterID, (registeredResource, chan)).
	RemoteWatchers map[string]map[string]chan struct{}

	// NamespaceManager is an interface to manage the tenant namespaces.
	NamespaceManager tenantnamespace.Manager
	// IdentityReader is an interface to manage remote identities, and to get the rest config.
	IdentityReader identitymanager.IdentityReader
	// LocalToRemoteNamespaceMapper maps local namespaces to remote ones.
	LocalToRemoteNamespaceMapper map[string]string
	// RemoteToLocalNamespaceMapper maps remote namespaces to local ones.
	RemoteToLocalNamespaceMapper map[string]string
	// ClusterIDToLocalNamespaceMapper maps clusterIDs to local namespaces.
	ClusterIDToLocalNamespaceMapper map[string]string
	// ClusterIDToRemoteNamespaceMapper maps clusterIDs to remote namespaces.
	ClusterIDToRemoteNamespaceMapper map[string]string
	// contains filtered or unexported fields
}

func (*Controller) AddFunc

func (c *Controller) AddFunc(newObj interface{})

func (*Controller) AddedHandler

func (c *Controller) AddedHandler(obj *unstructured.Unstructured, gvr schema.GroupVersionResource)

func (*Controller) CreateResource

func (c *Controller) CreateResource(dynClient dynamic.Interface,
	gvr schema.GroupVersionResource,
	obj *unstructured.Unstructured,
	clusterID string,
	ownership consts.OwnershipType) error

CreateResource creates the object with the provided dynamicClient.

func (*Controller) DeleteFunc

func (c *Controller) DeleteFunc(newObj interface{})

func (*Controller) DeleteResource

func (c *Controller) DeleteResource(client dynamic.Interface, gvr schema.GroupVersionResource, obj *unstructured.Unstructured, clusterID string) error

func (*Controller) DeletedHandler

func (c *Controller) DeletedHandler(obj *unstructured.Unstructured, gvr schema.GroupVersionResource)

func (*Controller) GetResource

func (c *Controller) GetResource(client dynamic.Interface, gvr schema.GroupVersionResource, name, namespace, clusterID string) (*unstructured.Unstructured, bool, error)

func (*Controller) ModifiedHandler

func (c *Controller) ModifiedHandler(obj *unstructured.Unstructured, gvr schema.GroupVersionResource)

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile handles requests for subscribed types of object.

func (*Controller) RemoteResourceModifiedHandler

func (c *Controller) RemoteResourceModifiedHandler(obj *unstructured.Unstructured,
	gvr schema.GroupVersionResource,
	remoteClusterID string,
	ownership consts.OwnershipType)

RemoteResourceModifiedHandler handles updates on a remote resource, updating the local status if it is in a shared ownership or forcing the remote status if the resource is only owned by the local cluster.

func (*Controller) SetLabelsForRemoteResources

func (c *Controller) SetLabelsForRemoteResources(options *metav1.ListOptions)

func (*Controller) SetupWithManager

func (c *Controller) SetupWithManager(mgr ctrl.Manager) error

func (*Controller) StartWatchers

func (c *Controller) StartWatchers()

func (*Controller) StopWatchers

func (c *Controller) StopWatchers()

Stops all the watchers for the resources that have been unregistered.

func (*Controller) UpdateConfig

func (c *Controller) UpdateConfig(cfg *configv1alpha1.ClusterConfig)

func (*Controller) UpdateFunc

func (c *Controller) UpdateFunc(oldObj, newObj interface{})

func (*Controller) UpdateLabels

func (c *Controller) UpdateLabels(labels map[string]string) map[string]string

func (*Controller) UpdateResource

func (c *Controller) UpdateResource(dynClient dynamic.Interface,
	gvr schema.GroupVersionResource,
	obj *unstructured.Unstructured,
	clusterID string,
	ownership consts.OwnershipType) error

UpdateResource updates the object with the provided client. If the ownership is shared the status is ignored, if the owner is the local cluster is the owner, the local status is forced on the remote resource.

func (*Controller) UpdateSpec

func (c *Controller) UpdateSpec(client dynamic.Interface, gvr schema.GroupVersionResource, obj *unstructured.Unstructured, clusterID string, spec map[string]interface{}) error

updates the spec field of a resource.

func (*Controller) UpdateStatus

func (c *Controller) UpdateStatus(client dynamic.Interface, gvr schema.GroupVersionResource, obj *unstructured.Unstructured, clusterID string, status map[string]interface{}) error

updates the status field of a resource.

func (*Controller) WatchConfiguration

func (c *Controller) WatchConfiguration(config *rest.Config, gv *schema.GroupVersion) error

func (*Controller) Watcher

func (c *Controller) Watcher(dynFac dynamicinformer.DynamicSharedInformerFactory, gvr schema.GroupVersionResource, handlerFuncs cache.ResourceEventHandlerFuncs, stopCh chan struct{})

Jump to

Keyboard shortcuts

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