From c8e5659c07827b98d2fee2ee1ab566799e969e03 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Fri, 30 Aug 2019 17:21:15 +0000 Subject: [PATCH] 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 --- virtcontainers/pkg/oci/utils.go | 3 +- virtcontainers/pkg/oci/utils_test.go | 41 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/virtcontainers/pkg/oci/utils.go b/virtcontainers/pkg/oci/utils.go index 5c7cab3424..e1e25c3b19 100644 --- a/virtcontainers/pkg/oci/utils.go +++ b/virtcontainers/pkg/oci/utils.go @@ -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 } } } diff --git a/virtcontainers/pkg/oci/utils_test.go b/virtcontainers/pkg/oci/utils_test.go index 1d2df4e36d..d6edeb8e32 100644 --- a/virtcontainers/pkg/oci/utils_test.go +++ b/virtcontainers/pkg/oci/utils_test.go @@ -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) + +}