mirror of
https://github.com/rancher/k3k.git
synced 2026-04-22 10:36:46 +00:00
Fix Network Policy reconciliation (#388)
* logs * fix delete cleanup * update spec * added policyName to status, skip netpol for policy managed clusters
This commit is contained in:
@@ -50,9 +50,10 @@ func (c *VirtualClusterPolicyReconciler) cleanupNamespaces(ctx context.Context)
|
||||
}
|
||||
|
||||
for _, ns := range namespaces.Items {
|
||||
deleteOpts := []client.DeleteAllOfOption{
|
||||
client.InNamespace(ns.Name),
|
||||
client.MatchingLabels{ManagedByLabelKey: VirtualPolicyControllerName},
|
||||
selector := labels.NewSelector()
|
||||
|
||||
if req, err := labels.NewRequirement(ManagedByLabelKey, selection.Equals, []string{VirtualPolicyControllerName}); err == nil {
|
||||
selector = selector.Add(*req)
|
||||
}
|
||||
|
||||
// if the namespace is bound to a policy -> cleanup resources of other policies
|
||||
@@ -63,11 +64,15 @@ func (c *VirtualClusterPolicyReconciler) cleanupNamespaces(ctx context.Context)
|
||||
if err != nil {
|
||||
log.Error(err, "error creating requirement", "policy", ns.Labels[PolicyNameLabelKey])
|
||||
} else {
|
||||
sel := labels.NewSelector().Add(*requirement)
|
||||
deleteOpts = append(deleteOpts, client.MatchingLabelsSelector{Selector: sel})
|
||||
selector = selector.Add(*requirement)
|
||||
}
|
||||
}
|
||||
|
||||
deleteOpts := []client.DeleteAllOfOption{
|
||||
client.InNamespace(ns.Name),
|
||||
client.MatchingLabelsSelector{Selector: selector},
|
||||
}
|
||||
|
||||
if err := c.Client.DeleteAllOf(ctx, &networkingv1.NetworkPolicy{}, deleteOpts...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ func namespaceEventHandler() handler.Funcs {
|
||||
if ns.Labels[PolicyNameLabelKey] != "" {
|
||||
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{Name: ns.Labels[PolicyNameLabelKey]}})
|
||||
}
|
||||
|
||||
},
|
||||
// When a Namespace is updated, if it has the "policy.k3k.io/policy-name" label
|
||||
UpdateFunc: func(ctx context.Context, e event.UpdateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
|
||||
|
||||
Reference in New Issue
Block a user