diff --git a/npm/nwpolicy.go b/npm/nwpolicy.go index e9dd200dc..e03ef7904 100644 --- a/npm/nwpolicy.go +++ b/npm/nwpolicy.go @@ -80,8 +80,6 @@ func (npMgr *NetworkPolicyManager) policyExists(npObj *networkingv1.NetworkPolic func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkPolicy) error { var ( err error - ns *Namespace - exists bool npNs = util.GetNSNameWithPrefix(npObj.ObjectMeta.Namespace) npName = npObj.ObjectMeta.Name allNs = npMgr.NsMap[util.KubeAllNamespacesFlag] @@ -99,15 +97,6 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP return err } - if ns, exists = npMgr.NsMap[npNs]; !exists { - ns, err = newNs(npNs) - if err != nil { - metrics.SendErrorLogAndMetric(util.NetpolID, "[AddNetworkPolicy] Error: creating namespace %s with err: %v", npNs, err) - return err - } - npMgr.NsMap[npNs] = ns - } - if npMgr.policyExists(npObj) { return nil } @@ -177,10 +166,7 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP return err } } - if err = npMgr.InitAllNsList(); err != nil { - metrics.SendErrorLogAndMetric(util.NetpolID, "[AddNetworkPolicy] Error: initializing all-namespace ipset list with err: %v", err) - return err - } + createCidrsRule("in", npObj.ObjectMeta.Name, npObj.ObjectMeta.Namespace, ingressIPCidrs, ipsMgr) createCidrsRule("out", npObj.ObjectMeta.Name, npObj.ObjectMeta.Namespace, egressIPCidrs, ipsMgr) iptMgr := allNs.iptMgr