detector

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 41 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 SpecificationChanged added in v1.3.0

func SpecificationChanged(oldObj, newObj *unstructured.Unstructured) bool

SpecificationChanged check if the specification of the given object change or not

Types

type ResourceDetector

type ResourceDetector struct {
	// DiscoveryClientSet is used to resource discovery.
	DiscoveryClientSet *discovery.DiscoveryClient
	// Client is used to retrieve objects, it is often more convenient than lister.
	Client client.Client
	// DynamicClient used to fetch arbitrary resources.
	DynamicClient                dynamic.Interface
	InformerManager              genericmanager.SingleClusterInformerManager
	EventHandler                 cache.ResourceEventHandler
	Processor                    util.AsyncWorker
	SkippedResourceConfig        *util.SkippedResourceConfig
	SkippedPropagatingNamespaces []*regexp.Regexp
	// ResourceInterpreter knows the details of resource structure.
	ResourceInterpreter resourceinterpreter.ResourceInterpreter
	EventRecorder       record.EventRecorder

	RESTMapper meta.RESTMapper

	// ConcurrentPropagationPolicySyncs is the number of PropagationPolicy that are allowed to sync concurrently.
	ConcurrentPropagationPolicySyncs int
	// ConcurrentClusterPropagationPolicySyncs is the number of ClusterPropagationPolicy that are allowed to sync concurrently.
	ConcurrentClusterPropagationPolicySyncs int
	// ConcurrentResourceTemplateSyncs is the number of resource templates that are allowed to sync concurrently.
	// Larger number means responsive resource template syncing but more CPU(and network) load.
	ConcurrentResourceTemplateSyncs int

	// RateLimiterOptions is the configuration for rate limiter which may significantly influence the performance of
	// the controller.
	RateLimiterOptions ratelimiterflag.Options
	// 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 keys.ClusterWideKey)

AddWaiting adds object's key to waiting list.

func (*ResourceDetector) ApplyClusterPolicy

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

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

func (*ResourceDetector) ApplyPolicy

func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, policy *policyv1alpha1.PropagationPolicy) (err error)

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

func (*ResourceDetector) BuildClusterResourceBinding

func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, labels map[string]string, policySpec *policyv1alpha1.PropagationSpec) (*workv1alpha2.ClusterResourceBinding, error)

BuildClusterResourceBinding builds a desired ClusterResourceBinding for object.

func (*ResourceDetector) BuildResourceBinding

func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, labels map[string]string, policySpec *policyv1alpha1.PropagationSpec) (*workv1alpha2.ResourceBinding, error)

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) CleanupClusterResourceBindingLabels added in v1.2.0

func (d *ResourceDetector) CleanupClusterResourceBindingLabels(crb *workv1alpha2.ClusterResourceBinding, labels ...string) error

CleanupClusterResourceBindingLabels removes labels from cluster resource binding.

func (*ResourceDetector) CleanupLabels

func (d *ResourceDetector) CleanupLabels(objRef workv1alpha2.ObjectReference, labelKeys ...string) error

CleanupLabels removes labels from object referencing by objRef.

func (*ResourceDetector) CleanupResourceBindingLabels added in v1.2.0

func (d *ResourceDetector) CleanupResourceBindingLabels(rb *workv1alpha2.ResourceBinding, labels ...string) error

CleanupResourceBindingLabels removes labels from resource binding.

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-* All objects under Karmada reserved namespace should be ignored: - karmada-system - karmada-cluster - karmada-es-*

If '--skipped-propagating-namespaces' is specified, all APIs in the skipped-propagating-namespaces will be ignored.

func (*ResourceDetector) GetMatching

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

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

func (*ResourceDetector) GetUnstructuredObject

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

GetUnstructuredObject retrieves object by key and returned its unstructured. Any updates to this resource template are not recommended as it may come from the informer cache. We should abide by the principle of making a deep copy first and then modifying it. See issue: https://github.com/karmada-io/karmada/issues/3878.

func (*ResourceDetector) HandleClusterPropagationPolicyCreationOrUpdate added in v1.4.0

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

HandleClusterPropagationPolicyCreationOrUpdate handles ClusterPropagationPolicy add and update event. When a new policy arrives, should first check whether existing objects are no longer matched by the current policy, if yes, clean the labels on the object. And then 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. After a policy is removed, the label marked on relevant resource template will be removed(which gives the resource template a change to match another policy).

Note: The relevant ClusterResourceBinding or ResourceBinding will continue to exist until the resource template is gone.

func (*ResourceDetector) HandlePropagationPolicyCreationOrUpdate added in v1.4.0

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

HandlePropagationPolicyCreationOrUpdate handles PropagationPolicy add and update event. When a new policy arrives, should first check whether existing objects are no longer matched by the current policy, if yes, clean the labels on the object. And then 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. After a policy is removed, the label marked on relevant resource template will be removed(which gives the resource template a change to match another policy).

Note: The relevant ResourceBinding will continue to exist until the resource template is gone.

func (*ResourceDetector) LookForMatchedClusterPolicy

func (d *ResourceDetector) LookForMatchedClusterPolicy(object *unstructured.Unstructured, objectKey keys.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 keys.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(_, 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(_, 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 keys.ClusterWideKey)

RemoveWaiting removes object's key from waiting list.

func (*ResourceDetector) Start

func (d *ResourceDetector) Start(ctx context.Context) 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