Skip to content

Commit 11fe536

Browse files
committed
Remove deprecated registry API
Signed-off-by: Ed Bartosh <[email protected]>
1 parent b355496 commit 11fe536

File tree

14 files changed

+68
-1071
lines changed

14 files changed

+68
-1071
lines changed

cmd/cdi/cmd/cdi-api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func cdiPrintCacheErrors() {
339339
return
340340
}
341341

342-
fmt.Printf("CDI Cache has errors:\n")
342+
fmt.Printf("CDI cache has errors:\n")
343343
for path, specErrors := range cdiErrors {
344344
fmt.Printf("Spec file %s:\n", path)
345345
for idx, err := range specErrors {

cmd/cdi/cmd/classes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
// classesCmd is our command for listing device classes in the registry.
23+
// classesCmd is our command for listing device classes in the cache.
2424
var classesCmd = &cobra.Command{
2525
Use: "classes",
2626
Short: "List CDI device classes",
27-
Long: `List CDI device classes found in the registry.`,
27+
Long: `List CDI device classes found in the cache.`,
2828
Run: func(cmd *cobra.Command, args []string) {
2929
cdiListClasses()
3030
},

cmd/cdi/cmd/devices.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ type devicesFlags struct {
2525
output string
2626
}
2727

28-
// devicesCmd is our command for listing devices found in the CDI registry.
28+
// devicesCmd is our command for listing devices found in the CDI cache.
2929
var devicesCmd = &cobra.Command{
3030
Aliases: []string{"devs", "dev"},
3131
Use: "devices",
32-
Short: "List devices in the CDI registry",
32+
Short: "List devices in the CDI cache",
3333
Long: `
34-
The 'devices' command lists devices found in the CDI registry.`,
34+
The 'devices' command lists devices found in the CDI cache.`,
3535
Run: func(cmd *cobra.Command, args []string) {
3636
cdiListDevices(devicesCfg.verbose, devicesCfg.output)
3737
},

cmd/cdi/cmd/dirs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var dirsCmd = &cobra.Command{
2525
Use: "dirs",
2626
Short: "Show CDI Spec directories in use",
2727
Long: `
28-
Show which directories are used by the registry to discover and
28+
Show which directories are used by the cache to discover and
2929
load CDI Specs. The later an entry is in the list the higher its
3030
priority. This priority is inherited by Spec files loaded from
3131
the directory and is used to resolve device conflicts. If there

cmd/cdi/cmd/monitor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ information to show upon each refresh.`,
4848

4949
func monitorSpecDirs(args ...string) {
5050
var (
51-
registry = cdi.GetRegistry()
52-
specDirs = registry.GetSpecDirectories()
51+
cache = cdi.GetDefaultCache()
52+
specDirs = cache.GetSpecDirectories()
5353
dirWatch *fsnotify.Watcher
5454
err error
5555
done chan error
@@ -81,7 +81,7 @@ func monitorSpecDirs(args ...string) {
8181

8282
go func() {
8383
var (
84-
// don't print registry content more often than this
84+
// don't print cache content more often than this
8585
oneSecond = 1 * time.Second
8686
timer *time.Timer
8787
)

cmd/cdi/cmd/root.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ var (
3535
// rootCmd represents the base command when called without any subcommands
3636
var rootCmd = &cobra.Command{
3737
Use: "cdi",
38-
Short: "Inspect and interact with the CDI Registry",
38+
Short: "Inspect and interact with the CDI cache",
3939
Long: `
4040
The 'cdi' utility allows you to inspect and interact with the
41-
CDI Registry. Various commands are available for listing CDI
41+
CDI cache. Various commands are available for listing CDI
4242
Spec files, vendors, classes, devices, validating the content
43-
of the registry, injecting devices into OCI Specs, and for
44-
monitoring changes in the Registry.
43+
of the cache, injecting devices into OCI Specs, and for
44+
monitoring changes in the cache.
4545
4646
See cdi --help for a list of available commands. You can get
4747
additional help about <command> by using 'cdi <command> -h'.`,
@@ -68,11 +68,16 @@ func initSpecDirs() {
6868
cdi.SetSpecValidator(validate.WithSchema(s))
6969

7070
if len(specDirs) > 0 {
71-
cdi.GetRegistry(
71+
cache, err := cdi.NewCache(
7272
cdi.WithSpecDirs(specDirs...),
7373
)
74-
if len(cdi.GetRegistry().GetErrors()) > 0 {
74+
if err != nil {
75+
fmt.Printf("failed to create CDI cache: %v\n", err)
76+
os.Exit(1)
77+
}
78+
if len(cache.GetErrors()) > 0 {
7579
cdiPrintCacheErrors()
80+
os.Exit(1)
7681
}
7782
}
7883
}

cmd/cdi/cmd/specs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var specsCmd = &cobra.Command{
3434
Use: "specs [vendor-list]",
3535
Short: "List available CDI Specs",
3636
Long: fmt.Sprintf(`
37-
The 'specs' command lists all CDI Specs present in the registry.
37+
The 'specs' command lists all CDI Specs present in the cache.
3838
If a vendor list is given, only CDI Specs by the given vendors are
39-
listed. The CDI Specs are discovered and loaded to the registry
40-
from CDI Spec directories. The default CDI Spec directories are:
39+
listed. The CDI Specs are discovered and loaded to the cache from
40+
CDI Spec directories. The default CDI Spec directories are:
4141
%s.`, strings.Join(cdi.DefaultSpecDirs, ", ")),
4242
Run: func(cmd *cobra.Command, vendors []string) {
4343
cdiListSpecs(specCfg.verbose, specCfg.output, vendors...)

cmd/cdi/cmd/validate.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,23 @@ import (
2626
"tags.cncf.io/container-device-interface/pkg/cdi"
2727
)
2828

29-
// validateCmd is our CDI command for validating CDI Spec files in the registry.
29+
// validateCmd is our CDI command for validating CDI Spec files in the cache.
3030
var validateCmd = &cobra.Command{
3131
Use: "validate",
32-
Short: "List CDI registry errors",
32+
Short: "List CDI cache errors",
3333
Long: `
3434
The 'validate' command lists errors encountered during the population
35-
of the CDI registry. It exits with an exit status of 1 if any errors
36-
were reported by the registry.`,
35+
of the CDI cache. It exits with an exit status of 1 if any errors
36+
were reported by the cache.`,
3737
Run: func(cmd *cobra.Command, args []string) {
38-
cdiErrors := cdi.GetRegistry().GetErrors()
38+
cache := cdi.GetDefaultCache()
39+
cdiErrors := cache.GetErrors()
3940
if len(cdiErrors) == 0 {
40-
fmt.Printf("No CDI Registry errors.\n")
41+
fmt.Printf("No CDI cache errors.\n")
4142
return
4243
}
4344

44-
fmt.Printf("CDI Registry has errors:\n")
45+
fmt.Printf("CDI cache has errors:\n")
4546
for path, specErrors := range cdiErrors {
4647
fmt.Printf("Spec file %s:\n", path)
4748
for idx, err := range specErrors {

cmd/cdi/cmd/vendors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
var vendorsCmd = &cobra.Command{
2525
Use: "vendors",
2626
Short: "List vendors",
27-
Long: `List vendors with CDI Specs in the registry.`,
27+
Long: `List vendors with CDI Specs in the cache.`,
2828
Run: func(cmd *cobra.Command, args []string) {
2929
cdiListVendors()
3030
},

pkg/cdi/doc.go

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,11 @@
3535
// available and instantiated the first time it is referenced directly
3636
// or indirectly. The most frequently used cache functions are available
3737
// as identically named package level functions which operate on the
38-
// default cache instance. Moreover, the registry also operates on the
39-
// same default cache. We plan to deprecate the registry and eventually
40-
// remove it in a future release.
41-
//
42-
// # CDI Registry
43-
//
44-
// Note: the Registry and its related interfaces are deprecated and will
45-
// be removed in a future version. Please use the default cache and its
46-
// related package-level function instead.
47-
//
48-
// The primary interface to interact with CDI devices is the Registry. It
49-
// is essentially a cache of all Specs and devices discovered in standard
50-
// CDI directories on the host. The registry has two main functionality,
51-
// injecting devices into an OCI Spec and refreshing the cache of CDI
52-
// Specs and devices.
38+
// default cache instance.
5339
//
5440
// # Device Injection
5541
//
56-
// Using the Registry one can inject CDI devices into a container with code
42+
// Using the Cache one can inject CDI devices into a container with code
5743
// similar to the following snippet:
5844
//
5945
// import (
@@ -63,13 +49,14 @@
6349
// log "github.com/sirupsen/logrus"
6450
//
6551
// "tags.cncf.io/container-device-interface/pkg/cdi"
66-
// oci "github.com/opencontainers/runtime-spec/specs-go"
52+
// "github.com/opencontainers/runtime-spec/specs-go"
6753
// )
6854
//
69-
// func injectCDIDevices(spec *oci.Spec, devices []string) error {
55+
// func injectCDIDevices(spec *specs.Spec, devices []string) error {
7056
// log.Debug("pristine OCI Spec: %s", dumpSpec(spec))
7157
//
72-
// unresolved, err := cdi.GetRegistry().InjectDevices(spec, devices)
58+
// cache := cdi.GetDefaultCache()
59+
// unresolved, err := cache.InjectDevices(spec, devices)
7360
// if err != nil {
7461
// return fmt.Errorf("CDI device injection failed: %w", err)
7562
// }
@@ -106,17 +93,17 @@
10693
// log "github.com/sirupsen/logrus"
10794
//
10895
// "tags.cncf.io/container-device-interface/pkg/cdi"
109-
// oci "github.com/opencontainers/runtime-spec/specs-go"
96+
// "github.com/opencontainers/runtime-spec/specs-go"
11097
// )
11198
//
112-
// func injectCDIDevices(spec *oci.Spec, devices []string) error {
113-
// registry := cdi.GetRegistry()
99+
// func injectCDIDevices(spec *specs.Spec, devices []string) error {
100+
// cache := cdi.GetDefaultCache()
114101
//
115-
// if err := registry.Refresh(); err != nil {
102+
// if err := cache.Refresh(); err != nil {
116103
// // Note:
117104
// // It is up to the implementation to decide whether
118105
// // to abort injection on errors. A failed Refresh()
119-
// // does not necessarily render the registry unusable.
106+
// // does not necessarily render the cache unusable.
120107
// // For instance, a parse error in a Spec file for
121108
// // vendor A does not have any effect on devices of
122109
// // vendor B...
@@ -125,7 +112,7 @@
125112
//
126113
// log.Debug("pristine OCI Spec: %s", dumpSpec(spec))
127114
//
128-
// unresolved, err := registry.InjectDevices(spec, devices)
115+
// unresolved, err := cache.InjectDevices(spec, devices)
129116
// if err != nil {
130117
// return fmt.Errorf("CDI device injection failed: %w", err)
131118
// }
@@ -182,17 +169,17 @@
182169
// Generating a Spec file for a vendor/device class can be done with a
183170
// code snippet similar to the following:
184171
//
185-
// import (
172+
// import (
186173
//
187174
// "fmt"
188175
// ...
189176
// "tags.cncf.io/container-device-interface/specs-go"
190177
// "tags.cncf.io/container-device-interface/pkg/cdi"
191178
//
192-
// )
179+
// )
193180
//
194181
// func generateDeviceSpecs() error {
195-
// registry := cdi.GetRegistry()
182+
// cache := specs.GetDefaultCache()
196183
// spec := &specs.Spec{
197184
// Version: specs.CurrentVersion,
198185
// Kind: vendor+"/"+class,
@@ -210,7 +197,7 @@
210197
// return fmt.Errorf("failed to generate Spec name: %w", err)
211198
// }
212199
//
213-
// return registry.SpecDB().WriteSpec(spec, specName)
200+
// return cache.WriteSpec(spec, specName)
214201
// }
215202
//
216203
// Similarly, generating and later cleaning up transient Spec files can be
@@ -219,17 +206,17 @@
219206
// They are typically created before the associated container is created
220207
// and removed once that container is removed.
221208
//
222-
// import (
209+
// import (
223210
//
224211
// "fmt"
225-
// ...
212+
//
226213
// "tags.cncf.io/container-device-interface/specs-go"
227214
// "tags.cncf.io/container-device-interface/pkg/cdi"
228215
//
229-
// )
216+
// )
230217
//
231218
// func generateTransientSpec(ctr Container) error {
232-
// registry := cdi.GetRegistry()
219+
// cache := specs.GetDefaultCache()
233220
// devices := getContainerDevs(ctr, vendor, class)
234221
// spec := &specs.Spec{
235222
// Version: specs.CurrentVersion,
@@ -257,21 +244,21 @@
257244
// return fmt.Errorf("failed to generate Spec name: %w", err)
258245
// }
259246
//
260-
// return registry.SpecDB().WriteSpec(spec, specName)
247+
// return cache.WriteSpec(spec, specName)
261248
// }
262249
//
263250
// func removeTransientSpec(ctr Container) error {
264-
// registry := cdi.GetRegistry()
251+
// cache := specs.GetDefaultCache()
265252
// transientID := getSomeSufficientlyUniqueIDForContainer(ctr)
266253
// specName := cdi.GenerateNameForTransientSpec(vendor, class, transientID)
267254
//
268-
// return registry.SpecDB().RemoveSpec(specName)
255+
// return cache.RemoveSpec(specName)
269256
// }
270257
//
271258
// # CDI Spec Validation
272259
//
273260
// This package performs both syntactic and semantic validation of CDI
274-
// Spec file data when a Spec file is loaded via the registry or using
261+
// Spec file data when a Spec file is loaded via the cache or using
275262
// the ReadSpec API function. As part of the semantic verification, the
276263
// Spec file is verified against the CDI Spec JSON validation schema.
277264
//

0 commit comments

Comments
 (0)