virtcontainers: fix kernel modules annotations

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 <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2019-08-30 17:21:15 +00:00
parent eb0a3d23d9
commit c8e5659c07
2 changed files with 43 additions and 1 deletions

View File

@ -455,9 +455,10 @@ func addAssetAnnotations(ocispec CompatOCISpec, config *vc.SandboxConfig) {
} }
if value, ok := ocispec.Annotations[vcAnnotations.KernelModules]; ok { 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) modules := strings.Split(value, KernelModulesSeparator)
c.KernelModules = modules c.KernelModules = modules
config.AgentConfig = c
} }
} }
} }

View File

@ -14,9 +14,11 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"testing" "testing"
"github.com/cri-o/cri-o/pkg/annotations" "github.com/cri-o/cri-o/pkg/annotations"
spec "github.com/opencontainers/runtime-spec/specs-go"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -790,3 +792,42 @@ func TestMain(m *testing.M) {
os.Exit(m.Run()) 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)
}