detector

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClusterWideKeyFunc

func ClusterWideKeyFunc(obj interface{}) (util.QueueKey, error)

ClusterWideKeyFunc generates a ClusterWideKey for object.

func GetDeletableResources

func GetDeletableResources(discoveryClient discovery.ServerResourcesInterface) map[schema.GroupVersionResource]struct{}

GetDeletableResources returns all resources from discoveryClient. More specifically, all preferred resources which support the 'delete', 'list', and 'watch' verbs.

All discovery errors are considered temporary. Upon encountering any error, GetDeletableResources will log and return any discovered resources it was able to process (which may be none).

This code is directly lifted from the Kubernetes codebase. For reference: https://github.com/kubernetes/kubernetes/blob/1e11e4a2108024935ecfcb2912226cedeafd99df/pkg/controller/garbagecollector/garbagecollector.go#L638-L667

Types

type ClusterWideKey

type ClusterWideKey struct {
	GVK       schema.GroupVersionKind
	Namespace string
	Name      string
}

ClusterWideKey is the object key which is a unique identifier under a cluster, across all resources.

func (*ClusterWideKey) NamespaceKey

func (k *ClusterWideKey) NamespaceKey() string

NamespaceKey returns the traditional key of a object.

func (*ClusterWideKey) String

func (k *ClusterWideKey) String() string

String returns the key's printable info.

type ResourceDetector

type ResourceDetector struct {
	// ClientSet is used to resource discovery.
	ClientSet kubernetes.Interface
	// Client is used to retrieve objects, it is often more convenient than lister.
	Client          client.Client
	InformerManager informermanager.SingleClusterInformerManager
	EventHandler    cache.ResourceEventHandler
	Processor       util.AsyncWorker

	RESTMapper meta.RESTMapper
	// contains filtered or unexported fields
}

ResourceDetector is a resource watcher which watches all resources and reconcile the events.

func (*ResourceDetector) AddWaiting

func (d *ResourceDetector) AddWaiting(objectKey ClusterWideKey)

AddWaiting adds object's key to waiting list.

func (*ResourceDetector) ApplyClusterPolicy

func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, objectKey ClusterWideKey, policy *policyv1alpha1.ClusterPropagationPolicy) error

ApplyClusterPolicy starts propagate the object referenced by object key according to ClusterPropagationPolicy.

func (*ResourceDetector) ApplyPolicy

ApplyPolicy starts propagate the object referenced by object key according to PropagationPolicy.

func (*ResourceDetector) BuildClusterResourceBinding

BuildClusterResourceBinding builds a desired ClusterResourceBinding for object.

func (*ResourceDetector) BuildResourceBinding

BuildResourceBinding builds a desired ResourceBinding for object.

func (*ResourceDetector) ClaimClusterPolicyForObject

func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unstructured, policyName string) error

ClaimClusterPolicyForObject set cluster identifier which the object associated with.

func (*ResourceDetector) ClaimPolicyForObject

func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructured, policyNamespace string, policyName string) error

ClaimPolicyForObject set policy identifier which the object associated with.

func (*ResourceDetector) EventFilter

func (d *ResourceDetector) EventFilter(obj interface{}) bool

EventFilter tells if an object should be take care of.

All objects under Kubernetes reserved namespace should be ignored: - kube-system - kube-public - kube-node-lease All objects under Karmada reserved namespace should be ignored: - karmada-system - karmada-cluster - karmada-es-* All objects which API group defined by Karmada should be ignored: - cluster.karmada.io - policy.karmada.io

func (*ResourceDetector) GetMatching

func (d *ResourceDetector) GetMatching(resourceSelectors []policyv1alpha1.ResourceSelector) []ClusterWideKey

GetMatching gets objects keys in waiting list that matches one of resource selectors.

func (*ResourceDetector) GetObject

func (d *ResourceDetector) GetObject(objectKey ClusterWideKey) (runtime.Object, error)

GetObject retrieves object from local cache.

func (*ResourceDetector) GetUnstructuredObject

func (d *ResourceDetector) GetUnstructuredObject(objectKey ClusterWideKey) (*unstructured.Unstructured, error)

GetUnstructuredObject retrieves object by key and returned its unstructured.

func (*ResourceDetector) HandleClusterPropagationPolicyCreation

func (d *ResourceDetector) HandleClusterPropagationPolicyCreation(policy *policyv1alpha1.ClusterPropagationPolicy) error

HandleClusterPropagationPolicyCreation handles ClusterPropagationPolicy add event. When a new policy arrives, should check if object in waiting list matches the policy, if yes remove the object from waiting list and throw the object to it's reconcile queue. If not, do nothing.

func (*ResourceDetector) HandleClusterPropagationPolicyDeletion

func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyName string) error

HandleClusterPropagationPolicyDeletion handles ClusterPropagationPolicy delete event. When policy removing, the associated ClusterResourceBinding objects should be cleaned up. In addition, the label added to original resource also need to be cleaned up, this gives a chance for original resource to match another policy.

func (*ResourceDetector) HandlePropagationPolicyCreation

func (d *ResourceDetector) HandlePropagationPolicyCreation(policy *policyv1alpha1.PropagationPolicy) error

HandlePropagationPolicyCreation handles PropagationPolicy add event. When a new policy arrives, should check if object in waiting list matches the policy, if yes remove the object from waiting list and throw the object to it's reconcile queue. If not, do nothing.

func (*ResourceDetector) HandlePropagationPolicyDeletion

func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyNS string, policyName string) error

HandlePropagationPolicyDeletion handles PropagationPolicy delete event. When policy removing, the associated ResourceBinding objects should be cleaned up. In addition, the label added to original resource also need to be cleaned up, this gives a chance for original resource to match another policy.

func (*ResourceDetector) LookForMatchedClusterPolicy

func (d *ResourceDetector) LookForMatchedClusterPolicy(object *unstructured.Unstructured, objectKey ClusterWideKey) (*policyv1alpha1.ClusterPropagationPolicy, error)

LookForMatchedClusterPolicy tries to find a ClusterPropagationPolicy for object referenced by object key.

func (*ResourceDetector) LookForMatchedPolicy

func (d *ResourceDetector) LookForMatchedPolicy(object *unstructured.Unstructured, objectKey ClusterWideKey) (*policyv1alpha1.PropagationPolicy, error)

LookForMatchedPolicy tries to find a policy for object referenced by object key.

func (*ResourceDetector) NeedLeaderElection

func (d *ResourceDetector) NeedLeaderElection() bool

NeedLeaderElection implements LeaderElectionRunnable interface. So that the detector could run in the leader election mode.

func (*ResourceDetector) OnAdd

func (d *ResourceDetector) OnAdd(obj interface{})

OnAdd handles object add event and push the object to queue.

func (*ResourceDetector) OnClusterPropagationPolicyAdd

func (d *ResourceDetector) OnClusterPropagationPolicyAdd(obj interface{})

OnClusterPropagationPolicyAdd handles object add event and push the object to queue.

func (*ResourceDetector) OnClusterPropagationPolicyDelete

func (d *ResourceDetector) OnClusterPropagationPolicyDelete(obj interface{})

OnClusterPropagationPolicyDelete handles object delete event and push the object to queue.

func (*ResourceDetector) OnClusterPropagationPolicyUpdate

func (d *ResourceDetector) OnClusterPropagationPolicyUpdate(oldObj, newObj interface{})

OnClusterPropagationPolicyUpdate handles object update event and push the object to queue.

func (*ResourceDetector) OnDelete

func (d *ResourceDetector) OnDelete(obj interface{})

OnDelete handles object delete event and push the object to queue.

func (*ResourceDetector) OnPropagationPolicyAdd

func (d *ResourceDetector) OnPropagationPolicyAdd(obj interface{})

OnPropagationPolicyAdd handles object add event and push the object to queue.

func (*ResourceDetector) OnPropagationPolicyDelete

func (d *ResourceDetector) OnPropagationPolicyDelete(obj interface{})

OnPropagationPolicyDelete handles object delete event and push the object to queue.

func (*ResourceDetector) OnPropagationPolicyUpdate

func (d *ResourceDetector) OnPropagationPolicyUpdate(oldObj, newObj interface{})

OnPropagationPolicyUpdate handles object update event and push the object to queue.

func (*ResourceDetector) OnUpdate

func (d *ResourceDetector) OnUpdate(oldObj, newObj interface{})

OnUpdate handles object update event and push the object to queue.

func (*ResourceDetector) Reconcile

func (d *ResourceDetector) Reconcile(key util.QueueKey) error

Reconcile performs a full reconciliation for the object referred to by the key. The key will be re-queued if an error is non-nil.

func (*ResourceDetector) ReconcileClusterPropagationPolicy

func (d *ResourceDetector) ReconcileClusterPropagationPolicy(key util.QueueKey) error

ReconcileClusterPropagationPolicy handles ClusterPropagationPolicy resource changes. When adding a ClusterPropagationPolicy, the detector will pick the objects in waitingObjects list that matches the policy and put the object to queue. When removing a ClusterPropagationPolicy, the relevant ClusterResourceBinding will be removed and the relevant objects will be put into queue again to try another policy.

func (*ResourceDetector) ReconcilePropagationPolicy

func (d *ResourceDetector) ReconcilePropagationPolicy(key util.QueueKey) error

ReconcilePropagationPolicy handles PropagationPolicy resource changes. When adding a PropagationPolicy, the detector will pick the objects in waitingObjects list that matches the policy and put the object to queue. When removing a PropagationPolicy, the relevant ResourceBinding will be removed and the relevant objects will be put into queue again to try another policy.

func (*ResourceDetector) RemoveWaiting

func (d *ResourceDetector) RemoveWaiting(objectKey ClusterWideKey)

RemoveWaiting removes object's key from waiting list.

func (*ResourceDetector) Start

func (d *ResourceDetector) Start(stopCh <-chan struct{}) error

Start runs the detector, never stop until stopCh closed.

Jump to

Keyboard shortcuts

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