vc: add agent.container_pipe_size annotation

This adds the `agent.container_pipe_size` annotation which allows
configuration of the size of the pipes for stdout/stderr for containers
inside the guest.

fixes #2467

Signed-off-by: Alex Price <aprice@atlassian.com>
This commit is contained in:
Alex Price 2020-03-05 16:09:02 +11:00
parent e94cf0f135
commit 4c28717335
6 changed files with 103 additions and 52 deletions

View File

@ -166,6 +166,7 @@ type KataAgentConfig struct {
UseVSock bool
Debug bool
Trace bool
ContainerPipeSize uint32
TraceMode string
TraceType string
KernelModules []string
@ -265,6 +266,11 @@ func KataAgentKernelParams(config KataAgentConfig) []Param {
params = append(params, Param{Key: "agent.trace", Value: config.TraceType})
}
if config.ContainerPipeSize > 0 {
containerPipeSize := strconv.FormatUint(uint64(config.ContainerPipeSize), 10)
params = append(params, Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: containerPipeSize})
}
return params
}

View File

@ -9,6 +9,7 @@ import (
"bufio"
"context"
"fmt"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"io/ioutil"
"net"
"os"
@ -925,6 +926,7 @@ func TestKataAgentKernelParams(t *testing.T) {
type testData struct {
debug bool
trace bool
containerPipeSize uint32
traceMode string
traceType string
expectedParams []Param
@ -937,50 +939,55 @@ func TestKataAgentKernelParams(t *testing.T) {
traceFooParam := Param{Key: "agent.trace", Value: "foo"}
containerPipeSizeParam := Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: "2097152"}
data := []testData{
{false, false, "", "", []Param{}},
{true, false, "", "", []Param{debugParam}},
{false, false, 0, "", "", []Param{}},
{true, false, 0, "", "", []Param{debugParam}},
{false, false, "foo", "", []Param{}},
{false, false, "foo", "", []Param{}},
{false, false, "", "foo", []Param{}},
{false, false, "", "foo", []Param{}},
{false, false, "foo", "foo", []Param{}},
{false, true, "foo", "foo", []Param{}},
{false, false, 0, "foo", "", []Param{}},
{false, false, 0, "foo", "", []Param{}},
{false, false, 0, "", "foo", []Param{}},
{false, false, 0, "", "foo", []Param{}},
{false, false, 0, "foo", "foo", []Param{}},
{false, true, 0, "foo", "foo", []Param{}},
{false, false, agentTraceModeDynamic, "", []Param{}},
{false, false, agentTraceModeStatic, "", []Param{}},
{false, false, "", agentTraceTypeIsolated, []Param{}},
{false, false, "", agentTraceTypeCollated, []Param{}},
{false, false, "foo", agentTraceTypeIsolated, []Param{}},
{false, false, "foo", agentTraceTypeCollated, []Param{}},
{false, false, 0, agentTraceModeDynamic, "", []Param{}},
{false, false, 0, agentTraceModeStatic, "", []Param{}},
{false, false, 0, "", agentTraceTypeIsolated, []Param{}},
{false, false, 0, "", agentTraceTypeCollated, []Param{}},
{false, false, 0, "foo", agentTraceTypeIsolated, []Param{}},
{false, false, 0, "foo", agentTraceTypeCollated, []Param{}},
{false, false, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, false, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},
{false, false, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, false, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},
{false, false, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},
{false, false, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},
{false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},
{false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},
{false, true, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, true, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},
{true, true, agentTraceModeDynamic, agentTraceTypeCollated, []Param{debugParam}},
{false, true, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},
{true, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{debugParam}},
{false, true, "", agentTraceTypeIsolated, []Param{}},
{false, true, "", agentTraceTypeCollated, []Param{}},
{true, true, "", agentTraceTypeIsolated, []Param{debugParam}},
{true, true, "", agentTraceTypeCollated, []Param{debugParam}},
{false, true, "foo", agentTraceTypeIsolated, []Param{}},
{false, true, "foo", agentTraceTypeCollated, []Param{}},
{true, true, "foo", agentTraceTypeIsolated, []Param{debugParam}},
{true, true, "foo", agentTraceTypeCollated, []Param{debugParam}},
{false, true, 0, "", agentTraceTypeIsolated, []Param{}},
{false, true, 0, "", agentTraceTypeCollated, []Param{}},
{true, true, 0, "", agentTraceTypeIsolated, []Param{debugParam}},
{true, true, 0, "", agentTraceTypeCollated, []Param{debugParam}},
{false, true, 0, "foo", agentTraceTypeIsolated, []Param{}},
{false, true, 0, "foo", agentTraceTypeCollated, []Param{}},
{true, true, 0, "foo", agentTraceTypeIsolated, []Param{debugParam}},
{true, true, 0, "foo", agentTraceTypeCollated, []Param{debugParam}},
{false, true, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam}},
{false, true, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam}},
{true, true, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam, debugParam}},
{true, true, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam, debugParam}},
{false, true, 0, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam}},
{false, true, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam}},
{true, true, 0, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam, debugParam}},
{true, true, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam, debugParam}},
{false, true, agentTraceModeStatic, "foo", []Param{traceFooParam}},
{true, true, agentTraceModeStatic, "foo", []Param{debugParam, traceFooParam}},
{false, true, 0, agentTraceModeStatic, "foo", []Param{traceFooParam}},
{true, true, 0, agentTraceModeStatic, "foo", []Param{debugParam, traceFooParam}},
{false, false, 0, "", "", []Param{}},
{false, false, 2097152, "", "", []Param{containerPipeSizeParam}},
}
for i, d := range data {
@ -989,6 +996,7 @@ func TestKataAgentKernelParams(t *testing.T) {
Trace: d.trace,
TraceMode: d.traceMode,
TraceType: d.traceType,
ContainerPipeSize: d.containerPipeSize,
}
count := len(d.expectedParams)

View File

@ -237,6 +237,11 @@ const (
// AgentTraceMode is a sandbox annotation to specify the trace type for the agent.
AgentTraceType = kataAnnotAgentPrefix + "trace_type"
// AgentContainerPipeSize is an annotation to specify the size of the pipes created for containers
AgentContainerPipeSize = kataAnnotAgentPrefix + ContainerPipeSizeOption
ContainerPipeSizeOption = "container_pipe_size"
ContainerPipeSizeKernelParam = "agent." + ContainerPipeSizeOption
)
const (

View File

@ -775,6 +775,14 @@ func addAgentConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig) error
c.TraceType = value
}
if value, ok := ocispec.Annotations[vcAnnotations.AgentContainerPipeSize]; ok {
containerPipeSize, err := strconv.ParseUint(value, 10, 32)
if err != nil {
return fmt.Errorf("Error parsing annotation for %s: Please specify uint32 value", vcAnnotations.AgentContainerPipeSize)
}
c.ContainerPipeSize = uint32(containerPipeSize)
}
config.AgentConfig = c
return nil

View File

@ -701,13 +701,37 @@ func TestAddAgentAnnotations(t *testing.T) {
"e1000e InterruptThrottleRate=3000,3000,3000 EEE=1",
"i915 enable_ppgtt=0",
},
ContainerPipeSize: 1024,
}
ocispec.Annotations[vcAnnotations.KernelModules] = strings.Join(expectedAgentConfig.KernelModules, KernelModulesSeparator)
ocispec.Annotations[vcAnnotations.AgentContainerPipeSize] = "1024"
addAnnotations(ocispec, &config)
assert.Exactly(expectedAgentConfig, config.AgentConfig)
}
func TestContainerPipeSizeAnnotation(t *testing.T) {
assert := assert.New(t)
config := vc.SandboxConfig{
Annotations: make(map[string]string),
AgentConfig: vc.KataAgentConfig{},
}
ocispec := specs.Spec{
Annotations: make(map[string]string),
}
expectedAgentConfig := vc.KataAgentConfig{
ContainerPipeSize: 0,
}
ocispec.Annotations[vcAnnotations.AgentContainerPipeSize] = "foo"
err := addAnnotations(ocispec, &config)
assert.Error(err)
assert.Exactly(expectedAgentConfig, config.AgentConfig)
}
func TestAddHypervisorAnnotations(t *testing.T) {
assert := assert.New(t)

View File

@ -125,7 +125,7 @@ func TestVMConfigGrpc(t *testing.T) {
HypervisorType: QemuHypervisor,
HypervisorConfig: newQemuConfig(),
AgentType: KataContainersAgent,
AgentConfig: KataAgentConfig{false, true, false, false, "", "", []string{}},
AgentConfig: KataAgentConfig{false, true, false, false, 0, "", "", []string{}},
ProxyType: NoopProxyType,
}