-
Notifications
You must be signed in to change notification settings - Fork 38
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
pkg/cdi: add functions for generating Spec names and removing Spec files. #77
Conversation
@bart0sh @klueska I cooked up this patch set for dealing with consistently named vendor-specific dynamically generated Spec files. Using the added two functions should guarantee global uniqueness of the generated Spec files with atomic updates to the cache/registry from the Refresh() point of view. If this is found to be a usable abstraction then I'll spell out the usage of these functions in doc.go... And I'd also like to replace the current WriteSpec() with a corresponding pair of CreateSpec()/RemoveSpec(). These would provide atomic updates and use a similar vendor+device-namespaced naming convention but with reproducible file names (and take an overwrite flag like WriteSpec()). |
01f1e28
to
f183951
Compare
I only took a high-level look at the code, but in general, I agree with the other sentiments given. Rather than create / delete files through the CDI library, we should add functions to:
It is then up to the user to call these functions to generate these transient filenames / device names, but other than that, nothing changes about the way the current API is used to create a spec / write a spec file out to disk. |
So how about something like this. This is the same as the combined single function above, but it does not hardcode JSON as the file format. I tried to formulate the documentation of how to use it, including the driver and transientID .
We could also use the same Spec the client will pass to WriteSpec() to dig out vendor/class ourselves. With that the signature would be something like |
f183951
to
c1d5064
Compare
c1d5064
to
93a7e7a
Compare
93a7e7a
to
8abef17
Compare
4b74fc5
to
63de3f7
Compare
63de3f7
to
53baa32
Compare
@klihub As far as I understood there are 2 ways of writing spec to the file: Can you describe possible usage scenarios and recommendations for each? |
Unless you are doing something special which requires you to fully control the exact path where the Spec file gets written to, you should always just use WriteSpec(). And as I mentioned already earlier, it might be better to change Spec.Write() into spec.write() (IOW, make it package private function) to eliminate any confusion which one should be used. |
6029c04
to
b986ea7
Compare
@klihub the PR looks good to me. I made some nit-picking comments, but the overall impression is good. Thank you! |
Thanks ! Those are all valid. I'll address/fix them once I'm back from lunch. |
b986ea7
to
e8560f9
Compare
6e955f2
to
0dd793f
Compare
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
RemoveSpec() can be used to remove a Spec file written by WriteSpec(). It takes the same name that was passed to WriteSpec() to create the file. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
0dd793f
to
fbf3535
Compare
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.
Just one small nit.
However, my earlier comment regarding these new functions still stands: because the library assumes that it has direct access to the directories, it cannot be used for the Kubernetes test/e2e/dra/test-driver where all of the logic runs outside of the cluster and only indirectly manipulates files.
fbf3535
to
791ea8f
Compare
@elezar would it make sense to make a new release after merging this? I hope I can update CDI in containerd before their release if we release fast enough. |
Does this change matter for containerd? |
This change doesn't matter for containerd. However, I'd prefer to update CDI there to the latest possible CDI release. |
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.
@bart0sh sure. We can cut a new release as soon as possible after this has landed. The operation is lightweight enough and we don't expect any breaking changes from automatic updates by consumers. |
1bbc039
to
9ce34af
Compare
Add functions for generating ordinary or transient Spec file names. The generated names can be passed to WriteSpec() to create the actual Spec files and to RemoveSpec() to remove them. Also update the package introduction in the golang docs describing how dynamic Spec files should be generated using the API. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
This should reduce confusion about how generates Specs should be written (cache.WriteSpec() vs. spec.Write()) and also reduce the possibility/temptation for users to bypass the registry/cache when interacting with Specs. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Alias specs.CurrentVersion as pkg/cdi.CurrentVersion. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
9ce34af
to
a5fbc2f
Compare
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.
Thanks again for the work here @klihub.
I think we can merge this and then address any minor points in a follow-up.
return errors.New("no Spec directories to write to") | ||
} | ||
|
||
prio = len(c.specDirs) - 1 | ||
specDir = c.specDirs[prio] | ||
path = filepath.Join(specDir, name) | ||
if ext := filepath.Ext(path); ext != ".json" && ext != ".yaml" { |
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 already set in newSpec
, correct? So we could drop this entire conditional.
I updated to the new CDI release and this PR broke how the DRA test driver generates specs:
What is the right way of creating a cdiapi.Spec instance now? I need it further down for:
|
I tried this instead, but tests didn't pass:
|
Something is odd here.
|
Could you check whether re-exporting the NewSpec method does what you want?
I could review it a bit later tonight and cut a new release with the fix?
…On Fri, Nov 4, 2022, 18:11 Patrick Ohly ***@***.***> wrote:
Something is odd here. yaml.Marshal doesn't encode the content of the
variable:
(dlv) p spec
*github.com/container-orchestrated-devices/container-device-interface/specs-go.Spec {
Version: "0.5.0",
Kind: "dra-1856.k8s.io/test",
Devices: []github.com/container-orchestrated-devices/container-device-interface/specs-go.Device len: 1, cap: 1, [
(*"github.com/container-orchestrated-devices/container-device-interface/specs-go.Device")(0xc000548700),
],
ContainerEdits: github.com/container-orchestrated-devices/container-device-interface/specs-go.ContainerEdits {
Env: []string len: 0, cap: 0, nil,
DeviceNodes: []*github.com/container-orchestrated-devices/container-device-interface/specs-go.DeviceNode len: 0, cap: 0, nil,
Hooks: []*github.com/container-orchestrated-devices/container-device-interface/specs-go.Hook len: 0, cap: 0, nil,
Mounts: []*github.com/container-orchestrated-devices/container-device-interface/specs-go.Mount len: 0, cap: 0, nil,},}
(dlv) p spec.Devices[0]github.com/container-orchestrated-devices/container-device-interface/specs-go.Device {
Name: "claim-b558fe5f-16db-4d95-b17f-c128873a9208",
ContainerEdits: github.com/container-orchestrated-devices/container-device-interface/specs-go.ContainerEdits {
Env: []string len: 1, cap: 1, [
"user_a=b",
],
DeviceNodes: []*github.com/container-orchestrated-devices/container-device-interface/specs-go.DeviceNode len: 0, cap: 0, nil,
Hooks: []*github.com/container-orchestrated-devices/container-device-interface/specs-go.Hook len: 0, cap: 0, nil,
Mounts: []*github.com/container-orchestrated-devices/container-device-interface/specs-go.Mount len: 0, cap: 0, nil,},}
(dlv) p string(buffer)
"cdiVersion: 0.5.0\ncontainerEdits: {}\ndevices:\n- containerEdits:\n"
—
Reply to this email directly, view it on GitHub
<#77 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHDMQNVP7ZVC6AUA3C4BDTWGU7T7ANCNFSM56B55WTA>
.
You are receiving this because you modified the open/close state.Message
ID:
<container-orchestrated-devices/container-device-interface/pull/77/c1303897573
@github.com>
|
I found a solution (manual encoding, use version 0.2.0 instead of 0.5.0, use JSON instead of YAML). I filed issues for future investigations. |
0.2.0 is pretty old. Not sure whether the version is checked anywhere..
As long as you're unblocked we can look into this on Monday.
…On Fri, Nov 4, 2022, 19:06 Patrick Ohly ***@***.***> wrote:
I found a solution (manual encoding, use version 0.2.0 instead of 0.5.0,
use JSON instead of YAML). I filed issues for future investigations.
—
Reply to this email directly, view it on GitHub
<#77 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHDMQJADCO6SMVBZBJXIEDWGVGA7ANCNFSM56B55WTA>
.
You are receiving this because you modified the open/close state.Message
ID:
<container-orchestrated-devices/container-device-interface/pull/77/c1303961862
@github.com>
|
Add convenience functions for generating Spec names for ordinary and transient Spec files. The generated names can be passed to WriteSpec() of Cache or Registry to atomically write a Spec file. Also add a function for removing Spec files created with WriteSpec().