Skip to content

Commit

Permalink
Remove deprecated oci and qualified-device APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Bartosh <[email protected]>
  • Loading branch information
bart0sh committed Aug 8, 2024
1 parent 2752614 commit f3e930b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 184 deletions.
3 changes: 2 additions & 1 deletion cmd/cdi/cmd/cdi-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
oci "github.com/opencontainers/runtime-spec/specs-go"
gen "github.com/opencontainers/runtime-tools/generate"
"tags.cncf.io/container-device-interface/pkg/cdi"
"tags.cncf.io/container-device-interface/pkg/parser"
)

func cdiListVendors() {
Expand Down Expand Up @@ -230,7 +231,7 @@ func collectCDIDevicesFromOCISpec(spec *oci.Spec) []string {
g.ClearLinuxDevices()

for _, d := range devices {
if !cdi.IsQualifiedName(d.Path) {
if !parser.IsQualifiedName(d.Path) {
g.AddDevice(d)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cdi/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ParseAnnotations(annotations map[string]string) ([]string, []string, error)
continue
}
for _, d := range strings.Split(value, ",") {
if !IsQualifiedName(d) {
if !parser.IsQualifiedName(d) {
return nil, nil, fmt.Errorf("invalid CDI device name %q", d)
}
devices = append(devices, d)
Expand Down Expand Up @@ -130,7 +130,7 @@ func AnnotationKey(pluginName, deviceID string) (string, error) {
func AnnotationValue(devices []string) (string, error) {
value, sep := "", ""
for _, d := range devices {
if _, _, _, err := ParseQualifiedName(d); err != nil {
if _, _, _, err := parser.ParseQualifiedName(d); err != nil {
return "", err
}
value += sep + d
Expand Down
2 changes: 1 addition & 1 deletion pkg/cdi/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (d *Device) edits() *ContainerEdits {

// Validate the device.
func (d *Device) validate() error {
if err := ValidateDeviceName(d.Name); err != nil {
if err := parser.ValidateDeviceName(d.Name); err != nil {
return err
}
name := d.Name
Expand Down
113 changes: 0 additions & 113 deletions pkg/cdi/qualified-device.go

This file was deleted.

13 changes: 7 additions & 6 deletions pkg/cdi/qualified-device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"tags.cncf.io/container-device-interface/pkg/parser"
)

func TestQualifiedName(t *testing.T) {
Expand Down Expand Up @@ -126,24 +127,24 @@ func TestQualifiedName(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
vendor, class, name, err := ParseQualifiedName(tc.device)
vendor, class, name, err := parser.ParseQualifiedName(tc.device)
if tc.isQualified {
require.True(t, IsQualifiedName(tc.device), "qualified name %q", tc.device)
require.True(t, parser.IsQualifiedName(tc.device), "qualified name %q", tc.device)
require.NoError(t, err)
require.Equal(t, tc.vendor, vendor, "qualified name %q", tc.device)
require.Equal(t, tc.class, class, "qualified name %q", tc.device)
require.Equal(t, tc.name, name, "qualified name %q", tc.device)

vendor, class, name = ParseDevice(tc.device)
vendor, class, name = parser.ParseDevice(tc.device)
require.Equal(t, tc.vendor, vendor, "parsed name %q", tc.device)
require.Equal(t, tc.class, class, "parse name %q", tc.device)
require.Equal(t, tc.name, name, "parsed name %q", tc.device)

device := QualifiedName(vendor, class, name)
device := parser.QualifiedName(vendor, class, name)
require.Equal(t, tc.device, device, "constructed device %q", tc.device)
} else if tc.isParsable {
require.False(t, IsQualifiedName(tc.device), "parsed name %q", tc.device)
vendor, class, name = ParseDevice(tc.device)
require.False(t, parser.IsQualifiedName(tc.device), "parsed name %q", tc.device)
vendor, class, name = parser.ParseDevice(tc.device)
require.Equal(t, tc.vendor, vendor, "parsed name %q", tc.device)
require.Equal(t, tc.class, class, "parse name %q", tc.device)
require.Equal(t, tc.name, name, "parsed name %q", tc.device)
Expand Down
11 changes: 6 additions & 5 deletions pkg/cdi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/yaml"

"tags.cncf.io/container-device-interface/internal/validation"
"tags.cncf.io/container-device-interface/pkg/parser"
cdi "tags.cncf.io/container-device-interface/specs-go"
)

Expand Down Expand Up @@ -105,7 +106,7 @@ func newSpec(raw *cdi.Spec, path string, priority int) (*Spec, error) {
spec.path += defaultSpecExt
}

spec.vendor, spec.class = ParseQualifier(spec.Kind)
spec.vendor, spec.class = parser.ParseQualifier(spec.Kind)

if spec.devices, err = spec.validate(); err != nil {
return nil, fmt.Errorf("invalid CDI Spec: %w", err)
Expand Down Expand Up @@ -211,10 +212,10 @@ func (s *Spec) validate() (map[string]*Device, error) {
if err := cdi.ValidateVersion(s.Spec); err != nil {
return nil, err
}
if err := ValidateVendorName(s.vendor); err != nil {
if err := parser.ValidateVendorName(s.vendor); err != nil {
return nil, err
}
if err := ValidateClassName(s.class); err != nil {
if err := parser.ValidateClassName(s.class); err != nil {
return nil, err
}
if err := validation.ValidateSpecAnnotations(s.Kind, s.Annotations); err != nil {
Expand Down Expand Up @@ -316,7 +317,7 @@ func GenerateTransientSpecName(vendor, class, transientID string) string {
// the Spec does not contain a valid vendor or class, it returns
// an empty name and a non-nil error.
func GenerateNameForSpec(raw *cdi.Spec) (string, error) {
vendor, class := ParseQualifier(raw.Kind)
vendor, class := parser.ParseQualifier(raw.Kind)
if vendor == "" {
return "", fmt.Errorf("invalid vendor/class %q in Spec", raw.Kind)
}
Expand All @@ -330,7 +331,7 @@ func GenerateNameForSpec(raw *cdi.Spec) (string, error) {
// If the Spec does not contain a valid vendor or class, it returns an
// an empty name and a non-nil error.
func GenerateNameForTransientSpec(raw *cdi.Spec, transientID string) (string, error) {
vendor, class := ParseQualifier(raw.Kind)
vendor, class := parser.ParseQualifier(raw.Kind)
if vendor == "" {
return "", fmt.Errorf("invalid vendor/class %q in Spec", raw.Kind)
}
Expand Down
56 changes: 0 additions & 56 deletions specs-go/oci.go

This file was deleted.

0 comments on commit f3e930b

Please sign in to comment.