CreateSpecFile creates a CDI spec file for the specified devices.
()
| 185 | |
| 186 | // CreateSpecFile creates a CDI spec file for the specified devices. |
| 187 | func (cdi *cdiHandler) CreateSpecFile() error { |
| 188 | var emptySpecs []string |
| 189 | for class, cdilib := range cdi.cdilibs { |
| 190 | cdi.logger.Infof("Generating CDI spec for resource: %s/%s", cdi.vendor, class) |
| 191 | |
| 192 | spec, err := cdilib.GetSpec() |
| 193 | if err != nil { |
| 194 | return fmt.Errorf("failed to get CDI spec: %v", err) |
| 195 | } |
| 196 | |
| 197 | // TODO: Once the NewDriverTransformer is merged in container-toolkit we can instantiate it directly. |
| 198 | transformer := cdi.getRootTransformer() |
| 199 | if err := transformer.Transform(spec.Raw()); err != nil { |
| 200 | return fmt.Errorf("failed to transform driver root in CDI spec: %v", err) |
| 201 | } |
| 202 | |
| 203 | specName, err := cdiapi.GenerateNameForSpec(spec.Raw()) |
| 204 | if err != nil { |
| 205 | return fmt.Errorf("failed to generate spec name: %v", err) |
| 206 | } |
| 207 | |
| 208 | err = spec.Save(filepath.Join(cdiRoot, specName+".json")) |
| 209 | if err != nil { |
| 210 | // TODO: This is a brittle check since it relies on exact string matches. |
| 211 | // We should pull this functionality into the CDI tooling instead. |
| 212 | if strings.Contains(err.Error(), "invalid device, empty device edits") { |
| 213 | klog.ErrorS(err, "Ignoring empty CDI specs", "vendor", cdi.vendor, "class", class) |
| 214 | emptySpecs = append(emptySpecs, class) |
| 215 | continue |
| 216 | } |
| 217 | return fmt.Errorf("failed to save CDI spec: %v", err) |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Remove the classes with empty specs from the supported types. |
| 222 | for _, emptySpec := range emptySpecs { |
| 223 | delete(cdi.cdilibs, emptySpec) |
| 224 | } |
| 225 | |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | func (cdi *cdiHandler) getRootTransformer() transform.Transformer { |
| 230 | driverRootTransformer := transformroot.New( |
nothing calls this directly
no test coverage detected