Skip to content

Commit

Permalink
Drop clusterNs internally to prep for placement
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Haiducek <[email protected]>
  • Loading branch information
dhaiducek authored and openshift-merge-bot[bot] committed Dec 19, 2023
1 parent 5250b1c commit 543715f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
20 changes: 10 additions & 10 deletions controllers/common/common_status_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func GetPolicyPlacementDecisions(ctx context.Context, c client.Client,
return decisions, placements, err
}

type DecisionSet map[appsv1.PlacementDecision]bool
type DecisionSet map[string]bool

// GetClusterDecisions identifies all managed clusters which should have a replicated policy using the root policy
// This returns unique decisions and placements that are NOT under Restricted subset.
Expand All @@ -166,7 +166,7 @@ func GetClusterDecisions(
[]*policiesv1.Placement, DecisionSet, error,
) {
log := log.WithValues("policyName", rootPolicy.GetName(), "policyNamespace", rootPolicy.GetNamespace())
decisions := make(map[appsv1.PlacementDecision]bool)
decisions := make(map[string]bool)

pbList := &policiesv1.PlacementBindingList{}

Expand Down Expand Up @@ -197,7 +197,7 @@ func GetClusterDecisions(

// Decisions are all unique
for _, plcDecision := range plcDecisions {
decisions[plcDecision] = true
decisions[plcDecision.ClusterName] = true
}

placements = append(placements, plcPlacements...)
Expand All @@ -223,11 +223,11 @@ func GetClusterDecisions(

// Decisions are all unique
for _, plcDecision := range plcDecisions {
if _, ok := decisions[plcDecision]; ok {
if _, ok := decisions[plcDecision.ClusterName]; ok {
foundInDecisions = true
}

decisions[plcDecision] = true
decisions[plcDecision.ClusterName] = true
}

if foundInDecisions {
Expand Down Expand Up @@ -268,15 +268,15 @@ func CalculatePerClusterStatus(
for dec := range decisions {
replicatedPolicy := &policiesv1.Policy{}
key := types.NamespacedName{
Namespace: dec.ClusterNamespace, Name: rootPolicy.Namespace + "." + rootPolicy.Name,
Namespace: dec, Name: rootPolicy.Namespace + "." + rootPolicy.Name,
}

err := c.Get(ctx, key, replicatedPolicy)
if err != nil {
if k8serrors.IsNotFound(err) {
status = append(status, &policiesv1.CompliancePerClusterStatus{
ClusterName: dec.ClusterName,
ClusterNamespace: dec.ClusterNamespace,
ClusterName: dec,
ClusterNamespace: dec,
})

continue
Expand All @@ -287,8 +287,8 @@ func CalculatePerClusterStatus(

status = append(status, &policiesv1.CompliancePerClusterStatus{
ComplianceState: replicatedPolicy.Status.ComplianceState,
ClusterName: dec.ClusterName,
ClusterNamespace: dec.ClusterNamespace,
ClusterName: dec,
ClusterNamespace: dec,
})
}

Expand Down
10 changes: 3 additions & 7 deletions controllers/propagator/propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ func (r *RootPolicyReconciler) cleanUpOrphanedRplPolicies(
log := log.WithValues("policyName", instance.GetName(), "policyNamespace", instance.GetNamespace())

for _, cluster := range originalCPCS {
key := appsv1.PlacementDecision{
ClusterName: cluster.ClusterNamespace,
ClusterNamespace: cluster.ClusterNamespace,
}
if allDecisions[key] {
if allDecisions[cluster.ClusterName] {
continue
}

Expand All @@ -78,7 +74,7 @@ func (r *RootPolicyReconciler) cleanUpOrphanedRplPolicies(
},
ObjectMeta: metav1.ObjectMeta{
Name: common.FullNameForPolicy(instance),
Namespace: cluster.ClusterNamespace,
Namespace: cluster.ClusterName,
},
}

Expand Down Expand Up @@ -138,7 +134,7 @@ func (r *RootPolicyReconciler) handleRootPolicy(ctx context.Context, instance *p
},
ObjectMeta: metav1.ObjectMeta{
Name: common.FullNameForPolicy(instance),
Namespace: decision.ClusterNamespace,
Namespace: decision,
},
}

Expand Down

0 comments on commit 543715f

Please sign in to comment.