@@ -21,6 +21,7 @@ import (
21
21
"os"
22
22
23
23
cdiapi "tags.cncf.io/container-device-interface/pkg/cdi"
24
+ cdiparser "tags.cncf.io/container-device-interface/pkg/parser"
24
25
cdispec "tags.cncf.io/container-device-interface/specs-go"
25
26
)
26
27
@@ -33,30 +34,23 @@ const (
33
34
)
34
35
35
36
type CDIHandler struct {
36
- registry cdiapi.Registry
37
+ cache * cdiapi.Cache
37
38
}
38
39
39
40
func NewCDIHandler (config * Config ) (* CDIHandler , error ) {
40
- registry := cdiapi .GetRegistry (
41
+ cache , err := cdiapi .NewCache (
41
42
cdiapi .WithSpecDirs (config .flags .cdiRoot ),
42
43
)
43
-
44
- err := registry .Refresh ()
45
44
if err != nil {
46
- return nil , fmt .Errorf ("unable to refresh the CDI registry : %v " , err )
45
+ return nil , fmt .Errorf ("unable to create a new CDI cache : %w " , err )
47
46
}
48
-
49
47
handler := & CDIHandler {
50
- registry : registry ,
48
+ cache : cache ,
51
49
}
52
50
53
51
return handler , nil
54
52
}
55
53
56
- func (cdi * CDIHandler ) GetDevice (device string ) * cdiapi.Device {
57
- return cdi .registry .DeviceDB ().GetDevice (device )
58
- }
59
-
60
54
func (cdi * CDIHandler ) CreateCommonSpecFile () error {
61
55
spec := & cdispec.Spec {
62
56
Kind : cdiKind ,
@@ -84,7 +78,7 @@ func (cdi *CDIHandler) CreateCommonSpecFile() error {
84
78
return fmt .Errorf ("failed to generate Spec name: %w" , err )
85
79
}
86
80
87
- return cdi .registry . SpecDB () .WriteSpec (spec , specName )
81
+ return cdi .cache .WriteSpec (spec , specName )
88
82
}
89
83
90
84
func (cdi * CDIHandler ) CreateClaimSpecFile (claimUID string , devices PreparedDevices ) error {
@@ -115,21 +109,21 @@ func (cdi *CDIHandler) CreateClaimSpecFile(claimUID string, devices PreparedDevi
115
109
}
116
110
spec .Version = minVersion
117
111
118
- return cdi .registry . SpecDB () .WriteSpec (spec , specName )
112
+ return cdi .cache .WriteSpec (spec , specName )
119
113
}
120
114
121
115
func (cdi * CDIHandler ) DeleteClaimSpecFile (claimUID string ) error {
122
116
specName := cdiapi .GenerateTransientSpecName (cdiVendor , cdiClass , claimUID )
123
- return cdi .registry . SpecDB () .RemoveSpec (specName )
117
+ return cdi .cache .RemoveSpec (specName )
124
118
}
125
119
126
120
func (cdi * CDIHandler ) GetClaimDevices (devices []string ) []string {
127
121
cdiDevices := []string {
128
- cdiapi .QualifiedName (cdiVendor , cdiClass , cdiCommonDeviceName ),
122
+ cdiparser .QualifiedName (cdiVendor , cdiClass , cdiCommonDeviceName ),
129
123
}
130
124
131
125
for _ , device := range devices {
132
- cdiDevice := cdiapi .QualifiedName (cdiVendor , cdiClass , device )
126
+ cdiDevice := cdiparser .QualifiedName (cdiVendor , cdiClass , device )
133
127
cdiDevices = append (cdiDevices , cdiDevice )
134
128
}
135
129
0 commit comments