in pkg/rpc/rpc_handler.go [135:170]
func (s *server) DeletePodNp(ctx context.Context, in *rpc.DeleteNpRequest) (*rpc.DeleteNpReply, error) {
if s.policyReconciler == nil || s.policyReconciler.GeteBPFClient() == nil {
s.log.Info("Network policy is disabled, returning success")
success := rpc.DeleteNpReply{
Success: true,
}
return &success, nil
}
s.log.Info("Received Delete Network Policy Request for Pod", "Name", in.K8S_POD_NAME, "Namespace", in.K8S_POD_NAMESPACE)
var err error
podIdentifier := utils.GetPodIdentifier(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE, s.log)
value, _ := s.policyReconciler.GeteBPFClient().GetDeletePodIdentifierLockMap().LoadOrStore(podIdentifier, &sync.Mutex{})
deletePodIdentifierLock := value.(*sync.Mutex)
deletePodIdentifierLock.Lock()
s.log.Info("Got the deletePodIdentifierLock for", "Pod: ", in.K8S_POD_NAME, " Namespace: ", in.K8S_POD_NAMESPACE, " PodIdentifier: ", podIdentifier)
isProgFdShared, err := s.policyReconciler.IsProgFdShared(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE)
s.policyReconciler.GeteBPFClient().DeletePodFromIngressProgPodCaches(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE)
s.policyReconciler.GeteBPFClient().DeletePodFromEgressProgPodCaches(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE)
if err == nil && !isProgFdShared {
err = s.policyReconciler.GeteBPFClient().DeleteBPFProgramAndMaps(podIdentifier)
if err != nil {
s.log.Error(err, "BPF programs and Maps delete failed for ", "podIdentifier ", podIdentifier)
}
deletePodIdentifierLock.Unlock()
s.policyReconciler.GeteBPFClient().GetDeletePodIdentifierLockMap().Delete(podIdentifier)
} else {
deletePodIdentifierLock.Unlock()
}
resp := rpc.DeleteNpReply{
Success: true,
}
return &resp, nil
}