Skip to content

Commit

Permalink
Limit overlap detection to the same cluster
Browse files Browse the repository at this point in the history
Otherwise, hosted mode runs into problems where it believes there will
be an overlap, but actually the policies are for different clusters.

Refs:
 - https://issues.redhat.com/browse/ACM-12032

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
  • Loading branch information
JustinKuli committed Jun 10, 2024
1 parent 4f7cda6 commit bc3c8be
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 1 deletion.
11 changes: 10 additions & 1 deletion controllers/operatorpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (
olmGracePeriod = 30 * time.Second
ManagedByLabel string = "operatorpolicy.policy.open-cluster-management.io/managed"
ManagedByAnnotation string = ManagedByLabel
ClusterNameLabel string = "policy.open-cluster-management.io/cluster-name"
ClusterNamespaceLabel string = "policy.open-cluster-management.io/cluster-namespace"
)

var (
Expand Down Expand Up @@ -476,8 +478,15 @@ func (r *OperatorPolicyReconciler) checkSubOverlap(
return statusChanged, nil, nil
}

// limit to OperatorPolicies for the same cluster as the policy
// (this cluster might be hosting OperatorPolicies for other clusters)
sel := labels.SelectorFromSet(map[string]string{
ClusterNameLabel: policy.GetLabels()[ClusterNameLabel],
ClusterNamespaceLabel: policy.GetLabels()[ClusterNamespaceLabel],
})

opList := &policyv1beta1.OperatorPolicyList{}
if err := r.List(ctx, opList); err != nil {
if err := r.List(ctx, opList, &client.ListOptions{LabelSelector: sel}); err != nil {
return statusChanged, nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
policy.open-cluster-management.io/parent-policy-compliance-db-id: "124"
policy.open-cluster-management.io/policy-compliance-db-id: "64"
labels:
policy.open-cluster-management.io/cluster-name: "managed"
policy.open-cluster-management.io/cluster-namespace: "managed"
ownerReferences:
- apiVersion: policy.open-cluster-management.io/v1
kind: Policy
Expand Down

0 comments on commit bc3c8be

Please sign in to comment.