Documentation
¶
Index ¶
- func ClusterWideKeyFunc(obj interface{}) (util.QueueKey, error)
- func GetDeletableResources(discoveryClient discovery.ServerResourcesInterface) map[schema.GroupVersionResource]struct{}
- type ResourceDetector
- func (d *ResourceDetector) AddWaiting(objectKey keys.ClusterWideKey)
- func (d *ResourceDetector) AggregateDeploymentStatus(objRef workv1alpha1.ObjectReference, ...) error
- func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, ...) error
- func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, ...) error
- func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, ...) *workv1alpha1.ClusterResourceBinding
- func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, ...) *workv1alpha1.ResourceBinding
- func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unstructured, policyName string) error
- func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructured, policyNamespace string, policyName string) error
- func (d *ResourceDetector) CleanupDeploymentStatus(objRef workv1alpha1.ObjectReference) error
- func (d *ResourceDetector) CleanupLabels(objRef workv1alpha1.ObjectReference, labels ...string) error
- func (d *ResourceDetector) CleanupResourceTemplateStatus(objRef workv1alpha1.ObjectReference) error
- func (d *ResourceDetector) EventFilter(obj interface{}) bool
- func (d *ResourceDetector) GetMatching(resourceSelectors []policyv1alpha1.ResourceSelector) []keys.ClusterWideKey
- func (d *ResourceDetector) GetObject(objectKey keys.ClusterWideKey) (runtime.Object, error)
- func (d *ResourceDetector) GetUnstructuredObject(objectKey keys.ClusterWideKey) (*unstructured.Unstructured, error)
- func (d *ResourceDetector) HandleClusterPropagationPolicyCreation(policy *policyv1alpha1.ClusterPropagationPolicy) error
- func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyName string) error
- func (d *ResourceDetector) HandlePropagationPolicyCreation(policy *policyv1alpha1.PropagationPolicy) error
- func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyNS string, policyName string) error
- func (d *ResourceDetector) LookForMatchedClusterPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey) (*policyv1alpha1.ClusterPropagationPolicy, error)
- func (d *ResourceDetector) LookForMatchedPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey) (*policyv1alpha1.PropagationPolicy, error)
- func (d *ResourceDetector) NeedLeaderElection() bool
- func (d *ResourceDetector) OnAdd(obj interface{})
- func (d *ResourceDetector) OnClusterPropagationPolicyAdd(obj interface{})
- func (d *ResourceDetector) OnClusterPropagationPolicyDelete(obj interface{})
- func (d *ResourceDetector) OnClusterPropagationPolicyUpdate(oldObj, newObj interface{})
- func (d *ResourceDetector) OnClusterResourceBindingAdd(obj interface{})
- func (d *ResourceDetector) OnClusterResourceBindingDelete(obj interface{})
- func (d *ResourceDetector) OnClusterResourceBindingUpdate(oldObj, newObj interface{})
- func (d *ResourceDetector) OnDelete(obj interface{})
- func (d *ResourceDetector) OnPropagationPolicyAdd(obj interface{})
- func (d *ResourceDetector) OnPropagationPolicyDelete(obj interface{})
- func (d *ResourceDetector) OnPropagationPolicyUpdate(oldObj, newObj interface{})
- func (d *ResourceDetector) OnResourceBindingAdd(obj interface{})
- func (d *ResourceDetector) OnResourceBindingDelete(obj interface{})
- func (d *ResourceDetector) OnResourceBindingUpdate(_, newObj interface{})
- func (d *ResourceDetector) OnUpdate(oldObj, newObj interface{})
- func (d *ResourceDetector) Reconcile(key util.QueueKey) error
- func (d *ResourceDetector) ReconcileClusterPropagationPolicy(key util.QueueKey) error
- func (d *ResourceDetector) ReconcileClusterResourceBinding(key util.QueueKey) error
- func (d *ResourceDetector) ReconcilePropagationPolicy(key util.QueueKey) error
- func (d *ResourceDetector) ReconcileResourceBinding(key util.QueueKey) error
- func (d *ResourceDetector) RemoveWaiting(objectKey keys.ClusterWideKey)
- func (d *ResourceDetector) Start(stopCh <-chan struct{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClusterWideKeyFunc ¶
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
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 ¶ added in v0.5.0
func (d *ResourceDetector) AggregateDeploymentStatus(objRef workv1alpha1.ObjectReference, status []workv1alpha1.AggregatedStatusItem) error
AggregateDeploymentStatus summarize deployment status and update to original objects.
func (*ResourceDetector) ApplyClusterPolicy ¶
func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, policy *policyv1alpha1.ClusterPropagationPolicy) error
ApplyClusterPolicy starts propagate the object referenced by object key according to ClusterPropagationPolicy.
func (*ResourceDetector) ApplyPolicy ¶
func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, policy *policyv1alpha1.PropagationPolicy) 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, policy *policyv1alpha1.ClusterPropagationPolicy) *workv1alpha1.ClusterResourceBinding
BuildClusterResourceBinding builds a desired ClusterResourceBinding for object.
func (*ResourceDetector) BuildResourceBinding ¶
func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructured, objectKey keys.ClusterWideKey, policy *policyv1alpha1.PropagationPolicy) *workv1alpha1.ResourceBinding
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) CleanupDeploymentStatus ¶ added in v0.5.0
func (d *ResourceDetector) CleanupDeploymentStatus(objRef workv1alpha1.ObjectReference) error
CleanupDeploymentStatus reinitialize Deployment status.
func (*ResourceDetector) CleanupLabels ¶ added in v0.5.0
func (d *ResourceDetector) CleanupLabels(objRef workv1alpha1.ObjectReference, labels ...string) error
CleanupLabels removes labels from object referencing by objRef.
func (*ResourceDetector) CleanupResourceTemplateStatus ¶ added in v0.5.0
func (d *ResourceDetector) CleanupResourceTemplateStatus(objRef workv1alpha1.ObjectReference) error
CleanupResourceTemplateStatus cleanup the status from resource template. Note: Only limited resource type supported.
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) []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. 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 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 ¶ added in v0.5.0
func (d *ResourceDetector) OnClusterResourceBindingAdd(obj interface{})
OnClusterResourceBindingAdd handles object add event.
func (*ResourceDetector) OnClusterResourceBindingDelete ¶ added in v0.5.0
func (d *ResourceDetector) OnClusterResourceBindingDelete(obj interface{})
OnClusterResourceBindingDelete handles object delete event.
func (*ResourceDetector) OnClusterResourceBindingUpdate ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (d *ResourceDetector) OnResourceBindingAdd(obj interface{})
OnResourceBindingAdd handles object add event.
func (*ResourceDetector) OnResourceBindingDelete ¶ added in v0.5.0
func (d *ResourceDetector) OnResourceBindingDelete(obj interface{})
OnResourceBindingDelete handles object delete event.
func (*ResourceDetector) OnResourceBindingUpdate ¶ added in v0.5.0
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) ReconcileClusterResourceBinding ¶ added in v0.5.0
func (d *ResourceDetector) ReconcileClusterResourceBinding(key util.QueueKey) error
ReconcileClusterResourceBinding handles ResourceBinding object changes. For each ClusterResourceBinding changes, we will try to calculate the summary status and update to original object that the ClusterResourceBinding refer to.
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 ¶ added in v0.5.0
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(stopCh <-chan struct{}) error
Start runs the detector, never stop until stopCh closed.