-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libcni: add config caching [v2] #678
Conversation
libcni/api.go
Outdated
cacheDir := rt.CacheDir | ||
if cacheDir == "" { | ||
cacheDir = CacheDir | ||
} | ||
return filepath.Join(cacheDir, "results", fmt.Sprintf("%s-%s-%s", netName, rt.ContainerID, rt.IfName)) | ||
return filepath.Join(cacheDir, string(fileType), fmt.Sprintf("%s-%s-%s", netName, rt.ContainerID, rt.IfName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to escape all these variables - there's no guarantee that they are filename-safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensuring these variables will be finename-safe will be address via #679
@mccv1r0 also Casey pointed out in the other review that maybe we should have some versioning in the cache file. See #661 (comment) |
I agree that variables should be sanitized on plugins level. For this version, I escaped the path. Versioning added as well. |
The name Btw. please remove the merge master branch commit from history and use instead |
RE escaping see #679 (comment) |
@mccv1r0 so there is still a question why you are calling sprintf on sum of strings. |
As it stands now, each of the strings, ContainerID, networkName and ifName might need escaping. Would you prefer just ContainerID? ifName won't need it, networkName "probably" won't need it but I don't want to chance it. |
Ok, maybe my question was not fully clear - you are taking the sum of strings, which is a string, then you are passing that to sprintf as a format string, but without any format arguments. So the question is not about what should be inside constructed string (IMO this set of fields is fine), but why fully built string is used as a lone parameter for sprintf. As @dcwb noted - you should use sum, or sprintf. |
Signed-off-by: Michael Cambria <[email protected]>
It would be good to see a test case that covered reading an "old" result-only file. |
@mccv1r0 I didn't see a testcase for this yet, but may have missed it. |
See line 517
Notice the tests to ensure kind and config are not in the file. |
@mccv1r0 since all our cache stuff is combined now, I suggest: setCachedResult -> cacheAdd otherwise LGTM |
changed |
ceb74b2
to
e3bb9c9
Compare
@mccv1r0 one last thing: |
Cache the config JSON, CNI_ARGs, and CapabilityArgs on ADD operations, and remove them on DEL. This allows runtimes to retrieve the cached information to ensure that the pod is given the same config and options on DEL as it was given on ADD. Add versioning to beginning of cache file Combine cached configuration and results into one file Signed-off-by: Michael Cambria <[email protected]>
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! @mccv1r0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
We want containernetworking/cni#678 to enable correct updates to the default network while pods are running. Signed-off-by: Dan Williams <[email protected]>
Continuation of #661 that fixes up conflicts in the existing PR.