diff --git a/pkg/detector/policy.go b/pkg/detector/policy.go index 4e7ffa58a..bc1c041d1 100644 --- a/pkg/detector/policy.go +++ b/pkg/detector/policy.go @@ -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)