in controllers/policyendpoints_controller.go [279:329]
func (r *PolicyEndpointsReconciler) reconcilePolicyEndpoint(ctx context.Context,
policyEndpoint *policyk8sawsv1.PolicyEndpoint) error {
r.log.Info("Processing Policy Endpoint ", "Name: ", policyEndpoint.Name, "Namespace ", policyEndpoint.Namespace)
start := time.Now()
// Identify pods local to the node. PolicyEndpoint resource will include `HostIP` field and
// network policy agent relies on it to filter local pods
parentNP := policyEndpoint.Spec.PolicyRef.Name
resourceNamespace := policyEndpoint.Namespace
resourceName := policyEndpoint.Name
targetPods, podIdentifiers, podsToBeCleanedUp := r.deriveTargetPodsForParentNP(ctx, parentNP, resourceNamespace, resourceName)
// Check if we need to remove this policy against any existing pods against which this policy
// is currently active. podIdentifiers will have the pod identifiers of the targetPods from the derived PEs
err := r.updatePolicyEnforcementStatusForPods(ctx, policyEndpoint.Name, podsToBeCleanedUp, podIdentifiers, false)
if err != nil {
r.log.Error(err, "failed to update policy enforcement status for existing pods")
return err
}
for podIdentifier, _ := range podIdentifiers {
// Derive Ingress IPs from the PolicyEndpoint
ingressRules, egressRules, isIngressIsolated, isEgressIsolated, err := r.deriveIngressAndEgressFirewallRules(ctx, podIdentifier,
policyEndpoint.Namespace, policyEndpoint.Name, false)
if err != nil {
r.log.Error(err, "Error Parsing policy Endpoint resource", "name:", policyEndpoint.Name)
return err
}
if len(ingressRules) == 0 && !isIngressIsolated {
//Add allow-all entry to Ingress rule set
r.log.Info("No Ingress rules and no ingress isolation - Appending catch all entry")
r.addCatchAllEntry(ctx, &ingressRules)
}
if len(egressRules) == 0 && !isEgressIsolated {
//Add allow-all entry to Egress rule set
r.log.Info("No Egress rules and no egress isolation - Appending catch all entry")
r.addCatchAllEntry(ctx, &egressRules)
}
// Setup/configure eBPF probes/maps for local pods
err = r.configureeBPFProbes(ctx, podIdentifier, targetPods, ingressRules, egressRules)
if err != nil {
r.log.Info("Error configuring eBPF Probes ", "error: ", err)
}
duration := msSince(start)
policySetupLatency.WithLabelValues(policyEndpoint.Name, policyEndpoint.Namespace).Observe(duration)
}
return nil
}