Merge pull request #2786 from XiShanYongYe-Chang/fix-2779

[bugfix] ignore resource that do not match with policy before apply policy
This commit is contained in:
karmada-bot 2022-11-16 16:16:05 +08:00 committed by GitHub
commit 8ed80ad4ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -94,6 +94,17 @@ func (d *ResourceDetector) getAndApplyPolicy(object *unstructured.Unstructured,
return err
}
// Some resources are available in more than one group in the same kubernetes version.
// Therefore, the following scenarios occurs:
// In v1.21 kubernetes cluster, Ingress are available in both networking.k8s.io and extensions groups.
// When user creates an Ingress(networking.k8s.io/v1) and specifies a PropagationPolicy to propagate it
// to the member clusters, the detector will listen two resource creation events:
// Ingress(networking.k8s.io/v1) and Ingress(extensions/v1beta1). In order to prevent
// Ingress(extensions/v1beta1) from being propagated, we need to ignore it.
if !util.ResourceMatchSelectors(object, matchedPropagationPolicy.Spec.ResourceSelectors...) {
return nil
}
// return err when dependents not present, that we can retry at next reconcile.
if present, err := helper.IsDependentOverridesPresent(d.Client, matchedPropagationPolicy); err != nil || !present {
klog.Infof("Waiting for dependent overrides present for policy(%s/%s)", policyNamespace, policyName)
@ -116,6 +127,17 @@ func (d *ResourceDetector) getAndApplyClusterPolicy(object *unstructured.Unstruc
return err
}
// Some resources are available in more than one group in the same kubernetes version.
// Therefore, the following scenarios occurs:
// In v1.21 kubernetes cluster, Ingress are available in both networking.k8s.io and extensions groups.
// When user creates an Ingress(networking.k8s.io/v1) and specifies a ClusterPropagationPolicy to
// propagate it to the member clusters, the detector will listen two resource creation events:
// Ingress(networking.k8s.io/v1) and Ingress(extensions/v1beta1). In order to prevent
// Ingress(extensions/v1beta1) from being propagated, we need to ignore it.
if !util.ResourceMatchSelectors(object, matchedClusterPropagationPolicy.Spec.ResourceSelectors...) {
return nil
}
// return err when dependents not present, that we can retry at next reconcile.
if present, err := helper.IsDependentClusterOverridesPresent(d.Client, matchedClusterPropagationPolicy); err != nil || !present {
klog.Infof("Waiting for dependent overrides present for policy(%s)", policyName)