Skip to content

Conversation

@ck319
Copy link
Contributor

@ck319 ck319 commented Feb 14, 2023

Reason for Change:

Issue Fixed:

Requirements:

Notes:

@ck319 ck319 requested a review from a team as a code owner February 14, 2023 19:15
@ck319 ck319 requested review from vakalapa and removed request for a team February 14, 2023 19:15
@ck319 ck319 added the npm Related to NPM. label Feb 14, 2023
Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noting changes from other day's discussion offline

// because policy Manager will remove from policy from cache
// keep a local copy to remove references for ipsets
policy, ok := dp.policyMgr.GetPolicy(policyKey)
endpoints := policy.PodEndpoints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to make a deep copy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

for npmEndpoint := range endpoints {
// if the endpoint is not in the policy's endpoint list, delete from cache
if _, ok := policy.PodEndpoints[npmEndpoint]; !ok {
delete(dp.endpointCache.cache, npmEndpoint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general structure is good, but we're looking to delete the policy reference from the given endpoint the endpoint cache is also indexed by IP

The endpoint cache is also indexed by IP. If Policy.Endpoints doesn't have an IP, then the lookup may not be efficient but that's ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

// if the endpoint is not in the policy's endpoint list, delete policy reference from cache
if _, ok := policy.PodEndpoints[podIP]; !ok {
endpoint := dp.endpointCache.cache[podIP]
delete(endpoint.netPolReference, policyKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endpoint may not exist (chance of nil pointer exception)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm after locking endpointCache instead of updatePodCache

klog.Infof("[DataPlane] Policy %s is not found. Might been deleted already", policyKey)
return nil
}
dp.updatePodCache.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock the endpoint cache instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

huntergregory
huntergregory previously approved these changes Feb 22, 2023
@ck319 ck319 enabled auto-merge (squash) February 22, 2023 23:16
klog.Infof("[DataPlane] Policy %s is not found. Might been deleted already", policyKey)
return nil
}
dp.endpointCache.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cant we take endpointCache after the RemovePolicy ? if a new ep is created or existing one is deleted we will be fine right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline:
The goal of this was to not block NetPol controller on making SetPolicy SysCalls while UpdatePod() is running.

New Proposal:

  1. Put endpoint lock below removePolicy()
  2. Address the blocking in another PR that makes an endpoint-level lock (instead of locking the whole cache)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated 1

if err != nil {
return fmt.Errorf("[DataPlane] error while removing policy: %w", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check dp.ShouldUpdatePod() or something which is always true for windows and then execute this section, this is unnecessary for linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@vakalapa vakalapa disabled auto-merge February 24, 2023 21:06
@vakalapa vakalapa merged commit 0d4c65f into master Feb 24, 2023
@vakalapa vakalapa deleted the ckovacs_cache branch February 24, 2023 21:06
rjdenney pushed a commit that referenced this pull request Mar 13, 2023
* update endpointcache

* update delete logic

* fix lint issue

* added check for endpoint in cache

* add unit test

* fix type lint issue

* fix naming lint error

* updated endpoint cache lock

* moved cache lock down and added check for windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants