Skip to content

Commit

Permalink
fix: [NPM] check if policy exists in case of nil pointer (#1974)
Browse files Browse the repository at this point in the history
fix: check for nil first
  • Loading branch information
huntergregory authored Jun 2, 2023
1 parent ba18fc7 commit aaf639c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions npm/pkg/dataplane/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,17 @@ func (dp *DataPlane) RemovePolicy(policyKey string) error {
// because policy Manager will remove from policy from cache
// keep a local copy to remove references for ipsets
policy, ok := dp.policyMgr.GetPolicy(policyKey)
if !ok {
klog.Infof("[DataPlane] Policy %s is not found. Might been deleted already", policyKey)
return nil
}

endpoints := make(map[string]string, len(policy.PodEndpoints))

for podIP, endpointID := range policy.PodEndpoints {
endpoints[podIP] = endpointID
}

if !ok {
klog.Infof("[DataPlane] Policy %s is not found. Might been deleted already", policyKey)
return nil
}

// Use the endpoint list saved in cache for this network policy to remove
err := dp.policyMgr.RemovePolicy(policy.PolicyKey)
if err != nil {
Expand Down

0 comments on commit aaf639c

Please sign in to comment.