Skip to content

Commit 1f83d84

Browse files
authored
Merge pull request #168 from bart0sh/PR0014-remove-unused-code
cleanup: remove unused code
2 parents f161fa4 + 32e657d commit 1f83d84

File tree

3 files changed

+0
-510
lines changed

3 files changed

+0
-510
lines changed

pkg/cdi/container-edits_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package cdi
1818

1919
import (
20-
"os"
2120
"testing"
2221

2322
cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
@@ -28,7 +27,6 @@ import (
2827
func TestValidateContainerEdits(t *testing.T) {
2928
type testCase struct {
3029
name string
31-
spec *oci.Spec
3230
edits *cdi.ContainerEdits
3331
invalid bool
3432
}
@@ -624,8 +622,3 @@ func TestAppend(t *testing.T) {
624622
})
625623
}
626624
}
627-
628-
func fileMode(mode int) *os.FileMode {
629-
fm := os.FileMode(mode)
630-
return &fm
631-
}

specs-go/oci.go

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,9 @@
11
package specs
22

33
import (
4-
"errors"
5-
"fmt"
6-
74
spec "github.com/opencontainers/runtime-spec/specs-go"
85
)
96

10-
// ApplyOCIEditsForDevice applies devices OCI edits, in other words
11-
// it finds the device in the CDI spec and applies the OCI patches that device
12-
// requires to the OCI specification.
13-
func ApplyOCIEditsForDevice(config *spec.Spec, cdi *Spec, dev string) error {
14-
for _, d := range cdi.Devices {
15-
if d.Name != dev {
16-
continue
17-
}
18-
19-
return ApplyEditsToOCISpec(config, &d.ContainerEdits)
20-
}
21-
22-
return fmt.Errorf("CDI: device %q not found for spec %q", dev, cdi.Kind)
23-
}
24-
25-
// ApplyOCIEdits applies the OCI edits the CDI spec declares globally
26-
func ApplyOCIEdits(config *spec.Spec, cdi *Spec) error {
27-
return ApplyEditsToOCISpec(config, &cdi.ContainerEdits)
28-
}
29-
30-
// ApplyEditsToOCISpec applies the specified edits to the OCI spec.
31-
func ApplyEditsToOCISpec(config *spec.Spec, edits *ContainerEdits) error {
32-
if config == nil {
33-
return errors.New("spec is nil")
34-
}
35-
if edits == nil {
36-
return nil
37-
}
38-
39-
if len(edits.Env) > 0 {
40-
if config.Process == nil {
41-
config.Process = &spec.Process{}
42-
}
43-
config.Process.Env = append(config.Process.Env, edits.Env...)
44-
}
45-
46-
for _, d := range edits.DeviceNodes {
47-
if config.Linux == nil {
48-
config.Linux = &spec.Linux{}
49-
}
50-
config.Linux.Devices = append(config.Linux.Devices, d.ToOCI())
51-
}
52-
53-
for _, m := range edits.Mounts {
54-
config.Mounts = append(config.Mounts, m.ToOCI())
55-
}
56-
57-
for _, h := range edits.Hooks {
58-
if config.Hooks == nil {
59-
config.Hooks = &spec.Hooks{}
60-
}
61-
switch h.HookName {
62-
case "prestart":
63-
config.Hooks.Prestart = append(config.Hooks.Prestart, h.ToOCI())
64-
case "createRuntime":
65-
config.Hooks.CreateRuntime = append(config.Hooks.CreateRuntime, h.ToOCI())
66-
case "createContainer":
67-
config.Hooks.CreateContainer = append(config.Hooks.CreateContainer, h.ToOCI())
68-
case "startContainer":
69-
config.Hooks.StartContainer = append(config.Hooks.StartContainer, h.ToOCI())
70-
case "poststart":
71-
config.Hooks.Poststart = append(config.Hooks.Poststart, h.ToOCI())
72-
case "poststop":
73-
config.Hooks.Poststop = append(config.Hooks.Poststop, h.ToOCI())
74-
default:
75-
fmt.Printf("CDI: Unknown hook %q\n", h.HookName)
76-
}
77-
}
78-
79-
return nil
80-
}
81-
827
// ToOCI returns the opencontainers runtime Spec Hook for this Hook.
838
func (h *Hook) ToOCI() spec.Hook {
849
return spec.Hook{

0 commit comments

Comments
 (0)