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

Clean up/update CDI API. #39

Merged
merged 11 commits into from
Jan 11, 2022
Merged

Conversation

klihub
Copy link
Contributor

@klihub klihub commented Nov 29, 2021

This is an implementation of the API cleanup/update mentioned in #38 .

@klihub klihub force-pushed the draft/api-update-proposal branch 5 times, most recently from 6ff1e37 to 36a5e9a Compare November 29, 2021 19:25
Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

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

Thanks for the work here! Some initial comments. I will continue tomorrow.

One general comment, it may be useful to remove the "auto" refresh of the cache from this change to simplify the API somewhat. The monitor utility added could still implement this in a loop.

cmd/cdi/LICENSE Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
pkg/cdi/container-edits.go Outdated Show resolved Hide resolved
pkg/cdi/container-edits.go Outdated Show resolved Hide resolved
pkg/cdi/container-edits_test.go Show resolved Hide resolved
pkg/cdi/container-edits.go Outdated Show resolved Hide resolved
pkg/cdi/registry.go Outdated Show resolved Hide resolved
pkg/cdi/registry.go Outdated Show resolved Hide resolved
pkg/cdi/cache.go Outdated Show resolved Hide resolved
pkg/cdi/cache.go Outdated Show resolved Hide resolved
@klihub klihub force-pushed the draft/api-update-proposal branch 2 times, most recently from f108ad7 to d6df4bd Compare December 1, 2021 00:03
@klihub
Copy link
Contributor Author

klihub commented Dec 1, 2021

Thanks for the work here! Some initial comments. I will continue tomorrow.

One general comment, it may be useful to remove the "auto" refresh of the cache from this change to simplify the API somewhat. The monitor utility added could still implement this in a loop.

Yes, I concluded to the same based on our discussion in the meeting so I already did exactly that.

@klihub klihub force-pushed the draft/api-update-proposal branch 5 times, most recently from 4454a8e to faf66cf Compare December 2, 2021 23:12
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Implement composing, parsing and validating qualified device
names and their vendor, class and device components.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Implement container edit validation, applying container edits
to OCI Specs.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Implement loading and validation of specs and devices.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
@klihub klihub force-pushed the draft/api-update-proposal branch 5 times, most recently from e149207 to f0957c9 Compare December 10, 2021 13:39
@klihub klihub changed the title RFC: Proposal to clean up/update CDI API. Clean up/update CDI API. Dec 13, 2021
Implement discovery and caching of spec files and devices,
refreshing the cache.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Implement registry, related interfaces and functions.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in getting to this @klihub. I am currently on PTO.

I think the changes are already a lot cleaner from an API perspective with the utility / extra functionality provided by the CLI. I would also like to get @klueska's input here if that's ok.

// InjectDevices injects the given qualified devices to an OCI Spec. It
// returns any unresolvable devices and an error if injection fails for
// any of the devices.
func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it really make sense to have InjectDevices associated with a "cache"? The storage of the specs and applying the required OCI modifications seem like different (orthogonal) concerns.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the last open question that I have.

This assumes that the client has instantiated a Cache and is performing all injections for a spec through this. From my perspective it is more intuitive for a Cache to essentially be a structure that allows a user to obtain a CDI spec for a given device ID. This spec object can then be used to apply edits to the OCI spec. What is the motivation for doing the lookup and modification in a single method associated with the Spec store?

From the code below it seems that one concern is that we may be applying the same spec modifications for different devices and that collecting this in a single method allows us to keep track of this (as well as ensure that the cache is locked while making updates). If applying duplicate edits is a concern, then I would also expect some form of deduplication of the input device names.

Copy link
Contributor Author

@klihub klihub Jan 11, 2022

Choose a reason for hiding this comment

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

Well, the whole idea here is that if you are a consumer of CDI specs (a runtime or the orchestration), then you

  • only need to deal with the cache/registry,
  • can perform commonly needed tasks (injection) with preferably a single function call, and
  • without having to understand any intricacies of CDI itself

About deduplication of devices to inject vs. deduplication of global-scope container edits from CDI Specs... The latter is an intricacy of CDI itself, so we need/want to take care of it. That situation arises/occurs naturally whenever two or more devices are injected from a single CDI Spec which defines more than one device and has global-scope edits. AFAICT, this is different from deduplicating the consumer-provided set of devices to inject. While that would definitely be also possible, unless there is a common use case where CDI device duplicates arise/occur naturally in the input without special care being taken by the consumer, I think we should just process the input as is without trying to filter duplicates (and let requests with duplicates eventually fail in the worst case, if that happens to be the runtime's behavior).

pkg/cdi/container-edits.go Show resolved Hide resolved
pkg/cdi/device.go Show resolved Hide resolved
@klihub
Copy link
Contributor Author

klihub commented Dec 14, 2021

Sorry for the delay in getting to this @klihub. I am currently on PTO.

No problemo.

I think the changes are already a lot cleaner from an API perspective with the utility / extra functionality provided by the CLI. I would also like to get @klueska's input here if that's ok.

Sure, no problem. His input is welcome.

Copy link
Contributor

@bart0sh bart0sh left a comment

Choose a reason for hiding this comment

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

I think this API is a way better than what we currently have. I'd propose to merge it ASAP and update our pending PRs and podman implementation.

@elezar
Copy link
Contributor

elezar commented Dec 14, 2021

I think this API is a way better than what we currently have. I'd propose to merge it ASAP and update our pending PRs and podman implementation.

Yes, I agree that this is definitely a huge improvement over what we have. With this in mind, I'm also ok to merge this as part of the next iteration of the API. Since we're still pre-v1 we don't have as strict guarantees to uphold if we do decide to change things.

@klihub klihub marked this pull request as ready for review December 14, 2021 20:04
Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

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

Thanks @klihub. One final question / comment. I don't think it's a blocker but would like to get your motivation regarding the InjectDevices method.

cmd/cdi/cmd/cdi-api.go Outdated Show resolved Hide resolved
// InjectDevices injects the given qualified devices to an OCI Spec. It
// returns any unresolvable devices and an error if injection fails for
// any of the devices.
func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the last open question that I have.

This assumes that the client has instantiated a Cache and is performing all injections for a spec through this. From my perspective it is more intuitive for a Cache to essentially be a structure that allows a user to obtain a CDI spec for a given device ID. This spec object can then be used to apply edits to the OCI spec. What is the motivation for doing the lookup and modification in a single method associated with the Spec store?

From the code below it seems that one concern is that we may be applying the same spec modifications for different devices and that collecting this in a single method allows us to keep track of this (as well as ensure that the cache is locked while making updates). If applying duplicate edits is a concern, then I would also expect some form of deduplication of the input device names.

Add a sample 'cdi' binary to exercise the API. It can also serve
as a CDI command line debug utility for Spec maintainers.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Add a package-level documentation/overview.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

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

Thanks for this @klihub. This is definitely an improvement over the current API.

I think the questions around where exactly we're implementing the InjectDevices method are not blockers and are due to me not having used the API myself. Thanks for all your clarifying discussions.

@elezar elezar merged commit 46367ec into cncf-tags:master Jan 11, 2022
@klihub klihub deleted the draft/api-update-proposal branch January 11, 2022 16:57
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.

3 participants