-
Notifications
You must be signed in to change notification settings - Fork 885
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
Disable a single resource multi dependency distribution #5743
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"context" | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
|
@@ -31,6 +32,7 @@ import ( | |
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/errors" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/client-go/discovery" | ||
|
@@ -62,6 +64,8 @@ import ( | |
"github.com/karmada-io/karmada/pkg/util/restmapper" | ||
) | ||
|
||
var dependedByLabelKeyPrefix = "resourcebinding.karmada.io/depended-by-" | ||
|
||
// ResourceDetector is a resource watcher which watches all resources and reconcile the events. | ||
type ResourceDetector struct { | ||
// DiscoveryClientSet is used to resource discovery. | ||
|
@@ -106,6 +110,10 @@ type ResourceDetector struct { | |
// the controller. | ||
RateLimiterOptions ratelimiterflag.Options | ||
|
||
// DisableMultiDependencyDistribution indicates disable the ability to a resource from being depended on by multiple | ||
// resources or being distributed by PropagationPolicy/ClusterPropagationPolicy while being depended on. | ||
DisableMultiDependencyDistribution bool | ||
|
||
stopCh <-chan struct{} | ||
} | ||
|
||
|
@@ -245,10 +253,22 @@ func (d *ResourceDetector) Reconcile(key util.QueueKey) error { | |
// currently we do that by setting owner reference to derived objects. | ||
return nil | ||
} | ||
klog.Errorf("Failed to get unstructured object(%s), error: %v", clusterWideKeyWithConfig, err) | ||
klog.Errorf("Failed to get unstructured object(%s), error: %v", clusterWideKeyWithConfig.ClusterWideKey, err) | ||
return err | ||
} | ||
|
||
if d.DisableMultiDependencyDistribution { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remind me what situation this logic is handling? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A parameter is added to determine whether the Karmada system allows the same resource to be dependent on different resources. By default, the value is true, indicating that multiple dependencies will be prohibited in future evolution, including that a resource is processed by the PropagationPolicy and distributed along with the resource. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the purpose of your Looking at the e2e scenario, this code seems to be breaking compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The logic of this code is incorrect. I will correct it later.
When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rebase and fix the failing tests. |
||
skip, err := skipForPropagatedByDependent(d.Client, object) | ||
if err != nil { | ||
klog.Errorf("Failed to calc skipForPropagatedByDependent with object(%s), error: %v", clusterWideKeyWithConfig.ClusterWideKey, err) | ||
return err | ||
} | ||
if skip { | ||
klog.Warningf("Skip to propagate resource(%s) for it has been propagated by the dependency", clusterWideKeyWithConfig.ClusterWideKey) | ||
return nil | ||
} | ||
} | ||
|
||
resourceTemplateClaimedBy := util.GetLabelValue(object.GetLabels(), util.ResourceTemplateClaimedByLabel) | ||
// If the resource lacks this label, it implies that the resource template can be propagated by Policy. | ||
// For instance, once MultiClusterService takes over the Service, Policy cannot reclaim it. | ||
|
@@ -260,6 +280,30 @@ func (d *ResourceDetector) Reconcile(key util.QueueKey) error { | |
return d.propagateResource(object, clusterWideKey, resourceChangeByKarmada) | ||
} | ||
|
||
func skipForPropagatedByDependent(c client.Client, object *unstructured.Unstructured) (bool, error) { | ||
// cluster scope resource can not be propagated by dependent | ||
if object.GetNamespace() == "" { | ||
return false, nil | ||
} | ||
|
||
bindingName := names.GenerateBindingName(object.GetKind(), object.GetName()) | ||
binding := &workv1alpha2.ResourceBinding{} | ||
err := c.Get(context.TODO(), types.NamespacedName{Namespace: object.GetNamespace(), Name: bindingName}, binding) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
|
||
for k := range binding.Labels { | ||
if strings.HasPrefix(k, dependedByLabelKeyPrefix) { | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
// EventFilter tells if an object should be taken care of. | ||
// | ||
// All objects under Karmada reserved namespace should be ignored: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to have a feature gate than a command flag? Something like:
DisableDependencySharing
.For example:
@XiShanYongYe-Chang @chaunceyjiang What do you think?