Skip to content
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

Merged
merged 2 commits into from
Jul 20, 2019
Merged

Conversation

mccv1r0
Copy link
Member

@mccv1r0 mccv1r0 commented Jun 4, 2019

Continuation of #661 that fixes up conflicts in the existing PR.

@dcbw dcbw changed the title Fix conflict in PR 661 libcni: add config caching [v2] Jun 5, 2019
@dcbw dcbw mentioned this pull request Jun 5, 2019
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))
Copy link
Member

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.

Copy link
Member Author

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

@dcbw
Copy link
Member

dcbw commented Jun 6, 2019

@mccv1r0 also Casey pointed out in the other review that maybe we should have some versioning in the cache file. See #661 (comment)

@mccv1r0
Copy link
Member Author

mccv1r0 commented Jun 11, 2019

I agree that variables should be sanitized on plugins level. For this version, I escaped the path. Versioning added as well.

@jellonek
Copy link
Member

The name C:\Users\appveyor\AppData\Local\Temp\1\cni_cachedir523654598\config\"apitest-some-container-id-some-eth0" does not look to be healthy.

Btw. please remove the merge master branch commit from history and use instead git rebase -i origin/master on your branch.

@dcbw
Copy link
Member

dcbw commented Jun 12, 2019

RE escaping see #679 (comment)

@jellonek
Copy link
Member

@mccv1r0 so there is still a question why you are calling sprintf on sum of strings.

@mccv1r0
Copy link
Member Author

mccv1r0 commented Jun 13, 2019

@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.

@jellonek
Copy link
Member

@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.

@squeed
Copy link
Member

squeed commented Jul 3, 2019

It would be good to see a test case that covered reading an "old" result-only file.

@dcbw
Copy link
Member

dcbw commented Jul 17, 2019

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.

@mccv1r0
Copy link
Member Author

mccv1r0 commented Jul 18, 2019

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

				Context("no cached config just result", func() {
					It("passes a prevResult to the plugin", func() {
						err := ioutil.WriteFile(cacheFile, []byte(`{
							"cniVersion": "0.3.1",
							"ips": [{"version": "4", "address": "10.1.2.3/24"}],
							"dns": {}
						}`), 0600)
						Expect(err).NotTo(HaveOccurred())

						err = cniConfig.CheckNetwork(ctx, netConfig, runtimeConfig)
						Expect(err).NotTo(HaveOccurred())
						debug, err := noop_debug.ReadDebug(debugFilePath)
						Expect(err).NotTo(HaveOccurred())
						Expect(string(debug.CmdArgs.StdinData)).To(ContainSubstring("\"prevResult\":"))
						Expect(string(debug.CmdArgs.StdinData)).NotTo(ContainSubstring("\"config\":"))
						Expect(string(debug.CmdArgs.StdinData)).NotTo(ContainSubstring("\"kind\":"))
					})
				})

Notice the tests to ensure kind and config are not in the file.

@dcbw
Copy link
Member

dcbw commented Jul 19, 2019

@mccv1r0 since all our cache stuff is combined now, I suggest:

setCachedResult -> cacheAdd
getResultCacheFilePath -> getCacheFilePath
delCachedResult -> cacheDel

otherwise LGTM

@mccv1r0
Copy link
Member Author

mccv1r0 commented Jul 19, 2019

changed

@mccv1r0 mccv1r0 force-pushed the pr661 branch 2 times, most recently from ceb74b2 to e3bb9c9 Compare July 19, 2019 21:28
@dcbw
Copy link
Member

dcbw commented Jul 19, 2019

@mccv1r0 one last thing: cachedDel -> cacheDel

    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]>
@dcbw
Copy link
Member

dcbw commented Jul 19, 2019

/lgtm

Copy link
Member

@mars1024 mars1024 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! @mccv1r0

Copy link
Member

@jellonek jellonek left a comment

Choose a reason for hiding this comment

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

LGTM

@jellonek jellonek merged commit df124b2 into containernetworking:master Jul 20, 2019
dcbw added a commit to dcbw/ocicni that referenced this pull request Jul 22, 2019
We want containernetworking/cni#678 to
enable correct updates to the default network while pods are
running.

Signed-off-by: Dan Williams <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants