Skip to content

Commit

Permalink
Merge pull request #168 from bart0sh/PR0014-remove-unused-code
Browse files Browse the repository at this point in the history
cleanup: remove unused code
  • Loading branch information
klihub authored Sep 28, 2023
2 parents f161fa4 + 32e657d commit 1f83d84
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 510 deletions.
7 changes: 0 additions & 7 deletions pkg/cdi/container-edits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package cdi

import (
"os"
"testing"

cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
Expand All @@ -28,7 +27,6 @@ import (
func TestValidateContainerEdits(t *testing.T) {
type testCase struct {
name string
spec *oci.Spec
edits *cdi.ContainerEdits
invalid bool
}
Expand Down Expand Up @@ -624,8 +622,3 @@ func TestAppend(t *testing.T) {
})
}
}

func fileMode(mode int) *os.FileMode {
fm := os.FileMode(mode)
return &fm
}
75 changes: 0 additions & 75 deletions specs-go/oci.go
Original file line number Diff line number Diff line change
@@ -1,84 +1,9 @@
package specs

import (
"errors"
"fmt"

spec "github.com/opencontainers/runtime-spec/specs-go"
)

// ApplyOCIEditsForDevice applies devices OCI edits, in other words
// it finds the device in the CDI spec and applies the OCI patches that device
// requires to the OCI specification.
func ApplyOCIEditsForDevice(config *spec.Spec, cdi *Spec, dev string) error {
for _, d := range cdi.Devices {
if d.Name != dev {
continue
}

return ApplyEditsToOCISpec(config, &d.ContainerEdits)
}

return fmt.Errorf("CDI: device %q not found for spec %q", dev, cdi.Kind)
}

// ApplyOCIEdits applies the OCI edits the CDI spec declares globally
func ApplyOCIEdits(config *spec.Spec, cdi *Spec) error {
return ApplyEditsToOCISpec(config, &cdi.ContainerEdits)
}

// ApplyEditsToOCISpec applies the specified edits to the OCI spec.
func ApplyEditsToOCISpec(config *spec.Spec, edits *ContainerEdits) error {
if config == nil {
return errors.New("spec is nil")
}
if edits == nil {
return nil
}

if len(edits.Env) > 0 {
if config.Process == nil {
config.Process = &spec.Process{}
}
config.Process.Env = append(config.Process.Env, edits.Env...)
}

for _, d := range edits.DeviceNodes {
if config.Linux == nil {
config.Linux = &spec.Linux{}
}
config.Linux.Devices = append(config.Linux.Devices, d.ToOCI())
}

for _, m := range edits.Mounts {
config.Mounts = append(config.Mounts, m.ToOCI())
}

for _, h := range edits.Hooks {
if config.Hooks == nil {
config.Hooks = &spec.Hooks{}
}
switch h.HookName {
case "prestart":
config.Hooks.Prestart = append(config.Hooks.Prestart, h.ToOCI())
case "createRuntime":
config.Hooks.CreateRuntime = append(config.Hooks.CreateRuntime, h.ToOCI())
case "createContainer":
config.Hooks.CreateContainer = append(config.Hooks.CreateContainer, h.ToOCI())
case "startContainer":
config.Hooks.StartContainer = append(config.Hooks.StartContainer, h.ToOCI())
case "poststart":
config.Hooks.Poststart = append(config.Hooks.Poststart, h.ToOCI())
case "poststop":
config.Hooks.Poststop = append(config.Hooks.Poststop, h.ToOCI())
default:
fmt.Printf("CDI: Unknown hook %q\n", h.HookName)
}
}

return nil
}

// ToOCI returns the opencontainers runtime Spec Hook for this Hook.
func (h *Hook) ToOCI() spec.Hook {
return spec.Hook{
Expand Down
Loading

0 comments on commit 1f83d84

Please sign in to comment.