Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfixs of dependencies distributor #1499

Merged
merged 2 commits into from Mar 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/dependenciesdistributor/dependencies_distributor.go
Expand Up @@ -163,7 +163,7 @@ func (d *DependenciesDistributor) Reconcile(key util.QueueKey) error {
klog.Error("invalid key")
return fmt.Errorf("invalid key")
}
klog.Infof("DependenciesDistributor start to reconcile object: %s", clusterWideKey)
klog.V(4).Infof("DependenciesDistributor start to reconcile object: %s", clusterWideKey)

bindingObjectList, err := d.resourceBindingLister.ByNamespace(clusterWideKey.Namespace).List(labels.Everything())
if err != nil {
Expand Down Expand Up @@ -191,6 +191,7 @@ func (d *DependenciesDistributor) Reconcile(key util.QueueKey) error {
continue
}

klog.V(4).Infof("resource binding(%s/%s) is matched for resource(%s/%s)", binding.Namespace, binding.Name, clusterWideKey.Namespace, clusterWideKey.Name)
bindingKey, err := detector.ClusterWideKeyFunc(binding)
if err != nil {
klog.Errorf("failed to generate cluster wide key for binding %s/%s: %v", binding.Namespace, binding.Name, err)
Expand Down Expand Up @@ -256,11 +257,13 @@ func (d *DependenciesDistributor) OnResourceBindingUpdate(oldObj, newObj interfa
}

if oldBindingObject.Generation == newBindingObject.Generation {
klog.V(4).Infof("Dropping resource binding(%s/%s) as the Generation is not changed.", newBindingObject.Namespace, newBindingObject.Name)
return
}

// prevent newBindingObject from the queue if it's not in Scheduled condition
if !helper.IsBindingScheduled(&newBindingObject.Status) {
// prevent newBindingObject from the queue if it's not scheduled yet.
if len(oldBindingObject.Spec.Clusters) == 0 && len(newBindingObject.Spec.Clusters) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When len(oldBindingObject.Spec.Clusters) == 0 and len(newBindingObject.Spec.Clusters) != 0, does it also need to be added to the queue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When len(oldBindingObject.Spec.Clusters) == 0 and len(newBindingObject.Spec.Clusters) != 0, does it also need to be added to the queue?

When len(oldBindingObject.Spec.Clusters) == 0 and len(newBindingObject.Spec.Clusters) != 0, it means the resource will be scheduled to some clusters, and it need to be enqueued so that dependencies distributor will propagate its dependencies to the same clusters.
When len(oldBindingObject.Spec.Clusters) != 0 and len(newBindingObject.Spec.Clusters) == 0, it means the resource has been scheduled to some clusters and now be deleted, and it need to be enqueued so that dependencies distributor will remove its dependencies from the clusters.

klog.V(4).Infof("Dropping resource binding(%s/%s) as it is not scheduled yet.", newBindingObject.Namespace, newBindingObject.Name)
return
}

Expand Down Expand Up @@ -308,6 +311,7 @@ func (d *DependenciesDistributor) ReconcileResourceBinding(key util.QueueKey) er
return fmt.Errorf("invalid key")
}

klog.V(4).Infof("Start to reconcile ResourceBinding(%s)", ckey.NamespaceKey())
unstructuredObj, err := d.resourceBindingLister.Get(ckey.NamespaceKey())
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -599,6 +603,7 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
updatedBindingSnapshot := mergeBindingSnapshot(existBinding.Spec.RequiredBy, attachedBinding.Spec.RequiredBy)
existBinding.Spec.RequiredBy = updatedBindingSnapshot
existBinding.Labels = util.DedupeAndMergeLabels(existBinding.Labels, attachedBinding.Labels)
existBinding.Spec.Resource = attachedBinding.Spec.Resource

if err := d.Client.Update(context.TODO(), existBinding); err != nil {
klog.Errorf("failed to update resource binding(%s/%s): %v", existBinding.Namespace, existBinding.Name, err)
Expand Down