Skip to content

Commit 686617d

Browse files
committed
cmd/cdi: switch to using the default cache.
Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 7d98426 commit 686617d

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

cmd/cdi/cmd/cdi-api.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929

3030
func cdiListVendors() {
3131
var (
32-
registry = cdi.GetRegistry()
33-
vendors = registry.SpecDB().ListVendors()
32+
cache = cdi.GetDefaultCache()
33+
vendors = cache.ListVendors()
3434
)
3535

3636
if len(vendors) == 0 {
@@ -41,20 +41,20 @@ func cdiListVendors() {
4141
fmt.Printf("CDI vendors found:\n")
4242
for idx, vendor := range vendors {
4343
fmt.Printf(" %d. %q (%d CDI Spec Files)\n", idx, vendor,
44-
len(registry.SpecDB().GetVendorSpecs(vendor)))
44+
len(cache.GetVendorSpecs(vendor)))
4545
}
4646
}
4747

4848
func cdiListClasses() {
4949
var (
50-
registry = cdi.GetRegistry()
51-
vendors = map[string][]string{}
50+
cache = cdi.GetDefaultCache()
51+
vendors = map[string][]string{}
5252
)
5353

54-
for _, class := range registry.SpecDB().ListClasses() {
54+
for _, class := range cache.ListClasses() {
5555
vendors[class] = []string{}
56-
for _, vendor := range registry.SpecDB().ListVendors() {
57-
for _, spec := range registry.SpecDB().GetVendorSpecs(vendor) {
56+
for _, vendor := range cache.ListVendors() {
57+
for _, spec := range cache.GetVendorSpecs(vendor) {
5858
if spec.GetClass() == class {
5959
vendors[class] = append(vendors[class], vendor)
6060
}
@@ -68,7 +68,7 @@ func cdiListClasses() {
6868
}
6969

7070
fmt.Printf("CDI device classes found:\n")
71-
for idx, class := range registry.SpecDB().ListClasses() {
71+
for idx, class := range cache.ListClasses() {
7272
sort.Strings(vendors[class])
7373
fmt.Printf(" %d. %s (%d vendors: %s)\n", idx, class,
7474
len(vendors[class]), strings.Join(vendors[class], ", "))
@@ -77,8 +77,8 @@ func cdiListClasses() {
7777

7878
func cdiListDevices(verbose bool, format string) {
7979
var (
80-
registry = cdi.GetRegistry()
81-
devices = registry.DeviceDB().ListDevices()
80+
cache = cdi.GetDefaultCache()
81+
devices = cache.ListDevices()
8282
)
8383

8484
if len(devices) == 0 {
@@ -88,7 +88,7 @@ func cdiListDevices(verbose bool, format string) {
8888

8989
fmt.Printf("CDI devices found:\n")
9090
for idx, device := range devices {
91-
cdiPrintDevice(idx, registry.DeviceDB().GetDevice(device), verbose, format, 2)
91+
cdiPrintDevice(idx, cache.GetDevice(device), verbose, format, 2)
9292
}
9393
}
9494

@@ -119,9 +119,9 @@ func cdiPrintDevice(idx int, dev *cdi.Device, verbose bool, format string, level
119119

120120
func cdiShowSpecDirs() {
121121
var (
122-
registry = cdi.GetRegistry()
123-
specDirs = registry.GetSpecDirectories()
124-
cdiErrors = registry.GetErrors()
122+
cache = cdi.GetDefaultCache()
123+
specDirs = cache.GetSpecDirectories()
124+
cdiErrors = cache.GetErrors()
125125
)
126126
fmt.Printf("CDI Spec directories in use:\n")
127127
for prio, dir := range specDirs {
@@ -139,12 +139,12 @@ func cdiShowSpecDirs() {
139139

140140
func cdiInjectDevices(format string, ociSpec *oci.Spec, patterns []string) error {
141141
var (
142-
registry = cdi.GetRegistry()
143-
matches = map[string]struct{}{}
144-
devices = []string{}
142+
cache = cdi.GetDefaultCache()
143+
matches = map[string]struct{}{}
144+
devices = []string{}
145145
)
146146

147-
for _, device := range registry.DeviceDB().ListDevices() {
147+
for _, device := range cache.ListDevices() {
148148
for _, glob := range patterns {
149149
match, err := filepath.Match(glob, device)
150150
if err != nil {
@@ -161,7 +161,7 @@ func cdiInjectDevices(format string, ociSpec *oci.Spec, patterns []string) error
161161
}
162162
sort.Strings(devices)
163163

164-
unresolved, err := registry.InjectDevices(ociSpec, devices...)
164+
unresolved, err := cache.InjectDevices(ociSpec, devices...)
165165

166166
if len(unresolved) > 0 {
167167
fmt.Printf("Unresolved CDI devices:\n")
@@ -242,18 +242,18 @@ func collectCDIDevicesFromOCISpec(spec *oci.Spec) []string {
242242

243243
func cdiListSpecs(verbose bool, format string, vendors ...string) {
244244
var (
245-
registry = cdi.GetRegistry()
245+
cache = cdi.GetDefaultCache()
246246
)
247247

248248
format = chooseFormat(format, "format-as.yaml")
249249

250250
if len(vendors) == 0 {
251-
vendors = registry.SpecDB().ListVendors()
251+
vendors = cache.ListVendors()
252252
}
253253

254254
if len(vendors) == 0 {
255255
fmt.Printf("No CDI Specs found.\n")
256-
cdiErrors := registry.GetErrors()
256+
cdiErrors := cache.GetErrors()
257257
if len(cdiErrors) > 0 {
258258
for path, specErrors := range cdiErrors {
259259
fmt.Printf("%s has errors:\n", path)
@@ -266,9 +266,9 @@ func cdiListSpecs(verbose bool, format string, vendors ...string) {
266266
}
267267

268268
fmt.Printf("CDI Specs found:\n")
269-
for _, vendor := range registry.SpecDB().ListVendors() {
269+
for _, vendor := range cache.ListVendors() {
270270
fmt.Printf("Vendor %s:\n", vendor)
271-
for _, spec := range registry.SpecDB().GetVendorSpecs(vendor) {
271+
for _, spec := range cache.GetVendorSpecs(vendor) {
272272
cdiPrintSpec(spec, verbose, format, 2)
273273
cdiPrintSpecErrors(spec, verbose, 2)
274274
}
@@ -285,8 +285,8 @@ func cdiPrintSpec(spec *cdi.Spec, verbose bool, format string, level int) {
285285

286286
func cdiPrintSpecErrors(spec *cdi.Spec, verbose bool, level int) {
287287
var (
288-
registry = cdi.GetRegistry()
289-
cdiErrors = registry.GetErrors()
288+
cache = cdi.GetDefaultCache()
289+
cdiErrors = cache.GetErrors()
290290
)
291291

292292
if len(cdiErrors) > 0 {
@@ -302,7 +302,7 @@ func cdiPrintSpecErrors(spec *cdi.Spec, verbose bool, level int) {
302302
}
303303
}
304304

305-
func cdiPrintRegistry(args ...string) {
305+
func cdiPrintCache(args ...string) {
306306
if len(args) == 0 {
307307
args = []string{"all"}
308308
}
@@ -328,17 +328,17 @@ func cdiPrintRegistry(args ...string) {
328328
}
329329
}
330330

331-
func cdiPrintRegistryErrors() {
331+
func cdiPrintCacheErrors() {
332332
var (
333-
registry = cdi.GetRegistry()
334-
cdiErrors = registry.GetErrors()
333+
cache = cdi.GetDefaultCache()
334+
cdiErrors = cache.GetErrors()
335335
)
336336

337337
if len(cdiErrors) == 0 {
338338
return
339339
}
340340

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

cmd/cdi/cmd/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func monitorSpecDirs(args ...string) {
121121

122122
case _ = <-refresh:
123123
refresh = nil
124-
cdiPrintRegistry(args...)
124+
cdiPrintCache(args...)
125125
}
126126
}
127127
}()

cmd/cdi/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func initSpecDirs() {
7272
cdi.WithSpecDirs(specDirs...),
7373
)
7474
if len(cdi.GetRegistry().GetErrors()) > 0 {
75-
cdiPrintRegistryErrors()
75+
cdiPrintCacheErrors()
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)