Skip to content

Commit

Permalink
vc: add agent.container_pipe_size annotation
Browse files Browse the repository at this point in the history
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 kata-containers#2467

Signed-off-by: Alex Price <aprice@atlassian.com>
  • Loading branch information
awprice committed Mar 5, 2020
1 parent e94cf0f commit 53bf2bd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 60 deletions.
20 changes: 13 additions & 7 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ func ephemeralPath() string {
// KataAgentConfig is a structure storing information needed
// to reach the Kata Containers agent.
type KataAgentConfig struct {
LongLiveConn bool
UseVSock bool
Debug bool
Trace bool
TraceMode string
TraceType string
KernelModules []string
LongLiveConn bool
UseVSock bool
Debug bool
Trace bool
ContainerPipeSize uint32
TraceMode string
TraceType string
KernelModules []string
}

// KataAgentState is the structure describing the data stored from this
Expand Down Expand Up @@ -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: "agent.container_pipe_size", Value: containerPipeSize})
}

return params
}

Expand Down
111 changes: 59 additions & 52 deletions virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,11 +923,12 @@ func TestKataAgentKernelParams(t *testing.T) {
assert := assert.New(t)

type testData struct {
debug bool
trace bool
traceMode string
traceType string
expectedParams []Param
debug bool
trace bool
containerPipeSize uint32
traceMode string
traceType string
expectedParams []Param
}

debugParam := Param{Key: "agent.log", Value: "debug"}
Expand All @@ -937,58 +938,64 @@ func TestKataAgentKernelParams(t *testing.T) {

traceFooParam := Param{Key: "agent.trace", Value: "foo"}

containerPipeSizeParam := Param{Key: "agent.container_pipe_size", Value: "2097152"}

data := []testData{
{false, false, "", "", []Param{}},
{true, false, "", "", []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, 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, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, false, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},

{false, false, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},
{false, false, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},

{false, true, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, true, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},
{true, true, 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, 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, agentTraceModeStatic, "foo", []Param{traceFooParam}},
{true, true, agentTraceModeStatic, "foo", []Param{debugParam, traceFooParam}},
{false, false, 0, "", "", []Param{}},
{true, false, 0, "", "", []Param{debugParam}},

{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, 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, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, false, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},

{false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},
{false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}},

{false, true, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}},
{false, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}},
{true, true, 0, agentTraceModeDynamic, 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, 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, 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 {
config := KataAgentConfig{
Debug: d.debug,
Trace: d.trace,
TraceMode: d.traceMode,
TraceType: d.traceType,
Debug: d.debug,
Trace: d.trace,
TraceMode: d.traceMode,
TraceType: d.traceType,
ContainerPipeSize: d.containerPipeSize,
}

count := len(d.expectedParams)
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ 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 + "container_pipe_size"
)

const (
Expand Down
8 changes: 8 additions & 0 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 agent.container_pipe_size: Please specify uint32 value")
}
c.ContainerPipeSize = uint32(containerPipeSize)
}

config.AgentConfig = c

return nil
Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,11 @@ 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)
}
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 53bf2bd

Please sign in to comment.