detector

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: Apache-2.0 Imports: 38 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 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              informermanager.SingleClusterInformerManager
	EventHandler                 cache.ResourceEventHandler
	Processor                    util.AsyncWorker
	SkippedResourceConfig        *util.SkippedResourceConfig
	SkippedPropagatingNamespaces map[string]struct{}
	// ResourceInterpreter knows the details of resource structure.
	ResourceInterpreter resourceinterpreter.ResourceInterpreter

	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 keys.ClusterWideKey)

AddWaiting adds object's key to waiting list.

func (*ResourceDetector) AggregateDeploymentStatus

func (d *ResourceDetector) AggregateDeploymentStatus(objRef workv1alpha2.ObjectReference, status []workv1alpha2.AggregatedStatusItem) error

AggregateDeploymentStatus summarize deployment status and update to original objects.

func (*ResourceDetector) AggregateIngressStatus

func (d *ResourceDetector) AggregateIngressStatus(objRef workv1alpha2.ObjectReference, status []workv1alpha2.AggregatedStatusItem) error

AggregateIngressStatus summarize ingress status and update to original objects.

func (*ResourceDetector) AggregateJobStatus

AggregateJobStatus summarize job status and update to original objects.

func (*ResourceDetector) AggregateServiceStatus

func (d *ResourceDetector) AggregateServiceStatus(objRef workv1alpha2.ObjectReference, status []workv1alpha2.AggregatedStatusItem) error

AggregateServiceStatus summarize service status and update to original objects.

func (*ResourceDetector) ApplyClusterPolicy

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

func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, labels map[string]string) (*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) (*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) CleanupLabels

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

CleanupLabels removes labels from object referencing by objRef.

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

The api objects listed above will be ignored by default, as we don't want users to manually input the things they don't care when trying to skip something else.

If '--skipped-propagating-apis' which used to specific the APIs should be ignored in addition to the defaults, is set, the specified apis will be ignored as well.

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) GetObject

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

GetObject retrieves object from local cache.

func (*ResourceDetector) GetUnstructuredObject

func (d *ResourceDetector) GetUnstructuredObject(objectKey keys.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. 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) 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. 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(oldObj, newObj interface{})

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

func (*ResourceDetector) OnClusterResourceBindingAdd

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

OnClusterResourceBindingAdd handles object add event.

func (*ResourceDetector) OnClusterResourceBindingUpdate

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

OnClusterResourceBindingUpdate 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) OnResourceBindingAdd

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

OnResourceBindingAdd handles object add event.

func (*ResourceDetector) OnResourceBindingUpdate

func (d *ResourceDetector) OnResourceBindingUpdate(_, newObj interface{})

OnResourceBindingUpdate 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) ReconcileResourceBinding

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

ReconcileResourceBinding handles ResourceBinding object changes. For each ResourceBinding changes, we will try to calculate the summary status and update to original object that the ResourceBinding refer to.

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