Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Support volume annotations #40

Merged
merged 2 commits into from
Oct 9, 2019

Conversation

Random-Liu
Copy link
Member

This is to support volume annotations introduced in google/gvisor#308.

// volumeName gets volume name from volume annotation key, example:
// gvisor.dev/spec/mount/NAME/share
func volumeName(k string) string {
return strings.Split(strings.TrimPrefix(k, volumeKeyPrefix), "/")[0]
Copy link
Member

Choose a reason for hiding this comment

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

nit: SplitN(..., 2)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}
}
}
done[volume] = struct{}{}
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to worry about duplicate volume annotations?

Copy link
Member Author

Choose a reason for hiding this comment

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

Initially I didn't only handle the type key, so we need to skip other annotations once one is handled. But now we only handle the type key now, but still need to track whether the spec is updated or not, so I left done there.

I could change it to a single boolean if you prefer. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to an updated boolean.

// volumePath searches the volume path in the kubelet pod directory.
func volumePath(volume, uid string) (string, error) {
// TODO: Support subpath when gvisor supports pod volume bind mount.
volumeSearchPath := fmt.Sprintf("/var/lib/kubelet/pods/%s/volumes/*/%s", uid, volume)
Copy link
Member

Choose a reason for hiding this comment

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

You could make this a global variable or preferably a flag. Then you can change it to /tmp/... in the test.

Copy link
Member Author

@Random-Liu Random-Liu Oct 8, 2019

Choose a reason for hiding this comment

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

SG. I don't think we want to expose a flag for this, but a global variable seems better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

} else {
// This is a container
for i := range s.Mounts {
if yes, _ := isVolumePath(volume, s.Mounts[i].Source); yes {
Copy link
Member

Choose a reason for hiding this comment

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

It's safer to match s.Mounts[i].Source, with the current annotation's source. Otherwise, it may upgrade to tmpfs a mount which doesn't have annotations associated with it (e.g. a mount with mismatching mount options).

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have the source in shim for container, because there is no way to get pod UID right now.

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this incorrectly mark an EmptyDir mount with mismatching rw/ro options as gVisor internal tmpfs, instead of a shared volume mounted externally? The former would cause a distinct tmpfs to be mounted inside each containers.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's why I return an error for sandbox if an tmpfs annotation exists, but source is not successfully applied. That guaranteed that as long there is an tmpfs annotation, source should be applied on sandbox.

And the volume name is unique for each pod, so this should work. But of course, this is not the best way this should work, we need to find a way to pass down more information to get rid of this hack.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Please leave a comment in the code explaining it and maybe a TODO to fix it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@Random-Liu
Copy link
Member Author

@fvoznika Addressed comments. Please take another look.

fvoznika
fvoznika previously approved these changes Oct 9, 2019
Signed-off-by: Lantao Liu <[email protected]>
@Random-Liu Random-Liu merged commit f299b55 into google:master Oct 9, 2019
@Random-Liu Random-Liu deleted the support-volume-annotation branch October 9, 2019 22:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants