Skip to content

Commit

Permalink
Ignore synced policies for hosted clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kulikauskas <[email protected]>
  • Loading branch information
JustinKuli authored and openshift-ci[bot] committed Oct 11, 2023
1 parent 6ce0d62 commit d180162
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion controllers/propagator/replicatedpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ func (r *ReplicatedPolicyReconciler) Reconcile(ctx context.Context, request ctrl
return reconcile.Result{}, nil
}

// do not handle a replicated policy which does not belong to the current cluster
inClusterNS, err := common.IsInClusterNamespace(r.Client, request.Namespace)
if err != nil {
return reconcile.Result{}, err
}

if !inClusterNS {
// "Hub of hubs" scenario: this cluster is managed by another cluster,
// which has the root policy for the policy being reconciled.
log.V(1).Info("Found a replicated policy in non-cluster namespace, skipping it")

return reconcile.Result{}, nil
Expand Down Expand Up @@ -160,6 +161,19 @@ func (r *ReplicatedPolicyReconciler) Reconcile(ctx context.Context, request ctrl
// an empty decision means the policy should not be replicated
if decision.Cluster.ClusterName == "" {
if replicatedExists {
inClusterNS, err := common.IsInClusterNamespace(r.Client, request.Namespace)
if err != nil {
return reconcile.Result{}, err
}

if !inClusterNS {
// "Hosted mode" scenario: this cluster is hosting another cluster, which is syncing
// this policy to a cluster namespace that this propagator doesn't know about.
log.V(1).Info("Found a possible replicated policy for a hosted cluster, skipping it")

return reconcile.Result{}, nil
}

if err := r.cleanUpReplicated(ctx, replicatedPolicy); err != nil {
if !k8serrors.IsNotFound(err) {
log.Error(err, "Failed to remove the replicated policy for this managed cluster, requeueing")
Expand Down

0 comments on commit d180162

Please sign in to comment.