Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: fix kernel modules annotations
Browse files Browse the repository at this point in the history
Casting in golang doesn't return a pointer to the structure, instead a new
structure is instantiated. This patch is to update the old structure with
the new one in order to apply the changes.

fixes #2016

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Aug 30, 2019
1 parent eb0a3d2 commit c8e5659
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,10 @@ func addAssetAnnotations(ocispec CompatOCISpec, config *vc.SandboxConfig) {
}

if value, ok := ocispec.Annotations[vcAnnotations.KernelModules]; ok {
if c, ok := config.AgentConfig.(*vc.KataAgentConfig); ok {
if c, ok := config.AgentConfig.(vc.KataAgentConfig); ok {
modules := strings.Split(value, KernelModulesSeparator)
c.KernelModules = modules
config.AgentConfig = c
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"

"github.com/cri-o/cri-o/pkg/annotations"
spec "github.com/opencontainers/runtime-spec/specs-go"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -790,3 +792,42 @@ func TestMain(m *testing.M) {

os.Exit(m.Run())
}

func TestAddAssetAnnotations(t *testing.T) {
assert := assert.New(t)

expectedAnnotations := map[string]string{
vcAnnotations.KernelPath: "/abc/rgb/kernel",
vcAnnotations.ImagePath: "/abc/rgb/image",
vcAnnotations.InitrdPath: "/abc/rgb/initrd",
vcAnnotations.KernelHash: "3l2353we871g",
vcAnnotations.ImageHash: "52ss2550983",
vcAnnotations.AssetHashType: "sha",
}

config := vc.SandboxConfig{
Annotations: make(map[string]string),
AgentConfig: vc.KataAgentConfig{},
}

ocispec := CompatOCISpec{
Spec: spec.Spec{
Annotations: expectedAnnotations,
},
}

addAssetAnnotations(ocispec, &config)
assert.Exactly(expectedAnnotations, config.Annotations)

expectedAgentConfig := vc.KataAgentConfig{
KernelModules: []string{
"e1000e InterruptThrottleRate=3000,3000,3000 EEE=1",
"i915 enable_ppgtt=0",
},
}

ocispec.Annotations[vcAnnotations.KernelModules] = strings.Join(expectedAgentConfig.KernelModules, KernelModulesSeparator)
addAssetAnnotations(ocispec, &config)
assert.Exactly(expectedAgentConfig, config.AgentConfig)

}

0 comments on commit c8e5659

Please sign in to comment.