@@ -130,13 +130,18 @@ func (pMgr *PolicyManager) AddPolicy(policy *NPMNetworkPolicy, endpointList map[
130130 metrics .RecordACLRuleExecTime (timer ) // record execution time regardless of failure
131131 if err != nil {
132132 // NOTE: in Linux, Prometheus metrics may be off at this point since some ACL rules may have been applied successfully
133+ // In Windows, Prometheus metrics may be off at this point since we don't know how many endpoints had rules applied successfully.
133134 msg := fmt .Sprintf ("failed to add policy: %s" , err .Error ())
134135 metrics .SendErrorLogAndMetric (util .IptmID , "error: %s" , msg )
135136 return npmerrors .Errorf (npmerrors .AddPolicy , false , msg )
136137 }
137138
138139 // update Prometheus metrics on success
139- metrics .IncNumACLRulesBy (policy .numACLRulesProducedInKernel ())
140+ numEndpoints := 1
141+ if util .IsWindowsDP () {
142+ numEndpoints = len (endpointList )
143+ }
144+ metrics .IncNumACLRulesBy (policy .numACLRulesProducedInKernel () * numEndpoints )
140145
141146 pMgr .policyMap .cache [policy .PolicyKey ] = policy
142147 return nil
@@ -146,7 +151,7 @@ func (pMgr *PolicyManager) isFirstPolicy() bool {
146151 return len (pMgr .policyMap .cache ) == 0
147152}
148153
149- func (pMgr * PolicyManager ) RemovePolicy (policyKey string , endpointList map [ string ] string ) error {
154+ func (pMgr * PolicyManager ) RemovePolicy (policyKey string ) error {
150155 policy , ok := pMgr .GetPolicy (policyKey )
151156
152157 if ! ok {
@@ -162,22 +167,57 @@ func (pMgr *PolicyManager) RemovePolicy(policyKey string, endpointList map[strin
162167 defer pMgr .policyMap .Unlock ()
163168
164169 // Call actual dataplane function to apply changes
165- err := pMgr .removePolicy (policy , endpointList )
170+ err := pMgr .removePolicy (policy , nil )
166171 // currently we only have acl rule exec time for "adding" rules, so we skip recording here
167172 if err != nil {
168- // NOTE: in Linux, Prometheus metrics may be off at this point since some ACL rules may have been applied successfully
173+ // NOTE: in Linux, Prometheus metrics may be off at this point since some ACL rules may have been applied successfully.
174+ // In Windows, Prometheus metrics may be off at this point since we don't know how many endpoints had rules applied successfully.
169175 msg := fmt .Sprintf ("failed to remove policy: %s" , err .Error ())
170176 metrics .SendErrorLogAndMetric (util .IptmID , "error: %s" , msg )
171177 return npmerrors .Errorf (npmerrors .RemovePolicy , false , msg )
172178 }
173179
174180 // update Prometheus metrics on success
175- metrics .DecNumACLRulesBy (policy .numACLRulesProducedInKernel ())
181+ numEndpoints := 1
182+ if util .IsWindowsDP () {
183+ numEndpoints = len (policy .PodEndpoints )
184+ }
185+ metrics .DecNumACLRulesBy (policy .numACLRulesProducedInKernel () * numEndpoints )
176186
187+ // remove policy from cache
177188 delete (pMgr .policyMap .cache , policyKey )
178189 return nil
179190}
180191
192+ // RemovePolicyForEndpoints is identical to RemovePolicy except it will not remove the policy from the cache.
193+ // This function is intended for Windows only.
194+ func (pMgr * PolicyManager ) RemovePolicyForEndpoints (policyKey string , endpointList map [string ]string ) error {
195+ policy , ok := pMgr .GetPolicy (policyKey )
196+
197+ if ! ok {
198+ return nil
199+ }
200+
201+ if len (policy .ACLs ) == 0 {
202+ klog .Infof ("[DataPlane] No ACLs in policy %s to remove for endpoints" , policyKey )
203+ return nil
204+ }
205+ // Call actual dataplane function to apply changes
206+ err := pMgr .removePolicy (policy , endpointList )
207+ // currently we only have acl rule exec time for "adding" rules, so we skip recording here
208+ if err != nil {
209+ // NOTE: Prometheus metrics may be off at this point since we don't know how many endpoints had rules applied successfully.
210+ msg := fmt .Sprintf ("failed to remove policy. endpoints: [%+v]. err: [%s]" , endpointList , err .Error ())
211+ metrics .SendErrorLogAndMetric (util .IptmID , "error: %s" , msg )
212+ return npmerrors .Errorf (npmerrors .RemovePolicy , false , msg )
213+ }
214+
215+ // update Prometheus metrics on success
216+ metrics .DecNumACLRulesBy (policy .numACLRulesProducedInKernel () * len (endpointList ))
217+
218+ return nil
219+ }
220+
181221func (pMgr * PolicyManager ) isLastPolicy () bool {
182222 // if we change our code to delete more than one policy at once, we can specify numPoliciesToDelete as an argument
183223 numPoliciesToDelete := 1
0 commit comments