-
Notifications
You must be signed in to change notification settings - Fork 242
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
oss: support CoCo direct volume feature #882
oss: support CoCo direct volume feature #882
Conversation
Welcome @mozillazg! |
Hi @mozillazg. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
||
// Remove deletes the direct volume path including all the files inside it. | ||
func Remove(volumePath string) error { | ||
return os.RemoveAll(filepath.Join(kataDirectVolumeRootPath, b64.URLEncoding.EncodeToString([]byte(volumePath)))) |
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.
Remove each file using os.Remove
? It's safer.
} | ||
|
||
// Add writes the mount info of a direct volume into a filesystem path known to Kata Container. | ||
func Add(volumePath string, mountInfo string) error { |
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.
pass mountInfo as []byte
?
Add
is only called from AddMountInfo
. Combine them to one func?
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.
This file is copied from https://github.com/kata-containers/kata-containers/blob/c800d0739fe42414a15ac8967f3fa5ccb98c28d7/src/runtime/pkg/direct-volume/utils.go.
We should keep it sync with upstream without any changes.
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.
OK. then how about just importing it? That is a one file package.
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.
We can't just import it. That will cause we depend on the whole kata runtime project.
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.
I think that is not a big deal. We are using vendor mode, which will only introduce one go file into the vendor directory. But I've tried that, this requires several upgrades to other dependencies. So, it is a pity. Maybe we can import this after we sort out our go.mod, and upgrade our dependencies.
} | ||
|
||
var deserialized MountInfo | ||
if err := json.Unmarshal([]byte(mountInfo), &deserialized); err != nil { |
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.
Why unmarshal it?
if isDirectVolumePath(mountPoint) { | ||
return ns.unPublishDirectVolume(ctx, req) | ||
} | ||
|
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.
This is not idempotent. I suppose isDirectVolumePath
would return false on a second unpublish? But it might be OK, because the remaining logic would still determine the volume as not mounted, then return success.
stat, err := os.Stat(volumeDir) | ||
if err != nil { | ||
if !errors.Is(err, os.ErrNotExist) { | ||
return err | ||
} | ||
if err := os.MkdirAll(volumeDir, 0700); err != nil { | ||
return err | ||
} | ||
} | ||
if stat != nil && !stat.IsDir() { | ||
return fmt.Errorf("%s should be a directory", volumeDir) | ||
} | ||
|
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.
How about just call os.MkdirAll
? It will do the Stat
and the checks for you.
stat, err := os.Stat(volumeDir) | |
if err != nil { | |
if !errors.Is(err, os.ErrNotExist) { | |
return err | |
} | |
if err := os.MkdirAll(volumeDir, 0700); err != nil { | |
return err | |
} | |
} | |
if stat != nil && !stat.IsDir() { | |
return fmt.Errorf("%s should be a directory", volumeDir) | |
} | |
if err := os.MkdirAll(volumeDir, 0700); err != nil { | |
return err | |
} |
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.
+1
case optKmsKeyId: | ||
kmsKeyId = strings.TrimSpace(value) | ||
case optAnnotations: | ||
json.Unmarshal([]byte(value), &annotationsObj) |
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.
Is it intentional to ignore the errors here?
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.
Yes. This option is optional, and the invalid value can be ignored.
Device: device, | ||
FsType: fsType, | ||
Metadata: metadata, | ||
Options: strings.Fields(opt.OtherOpts), |
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.
by using strings.Fields()
, we dropped the support for space in the options, e.g.: -o key="hello world"
will not work.
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.
I don't think the ossfs have such cases.
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.
Maybe. But this breaks the current interface. We are parsing the options with shell now, e.g., -o 'key'
is parsed as ["-o", "key"]
, not ["-o", "'key'"]
will the kata containers follow the ossfs version in CSI ? ACK ossfs 1.80.1 is the min version support KMS encryption. |
/ok-to-test |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mowangdk, mozillazg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
oss: support CoCo direct volume feature
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
https://github.com/kata-containers/kata-containers/blob/main/docs/design/direct-blk-device-assignment.md
kata-containers/kata-containers#7943
kata-containers/kata-containers#7965
confidential-containers/guest-components#345
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: