Merge pull request #2017 from devimc/topic/virtcontainers/loadKernelModules

virtcontainers: fix kernel modules annotations
This commit is contained in:
Julio Montes 2019-09-02 12:12:50 -05:00 committed by GitHub
commit 52cff50e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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
}
}
}

View File

@ -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"
@ -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)
}