mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-30 20:44:26 +01:00
container's rootfs is a string type, which cannot represent a
block storage backed rootfs which hasn't been mounted.
Change it to a mount alike struct as below:
RootFs struct {
// Source specify the BlockDevice path
Source string
// Target specify where the rootfs is mounted if it has been mounted
Target string
// Type specifies the type of filesystem to mount.
Type string
// Options specifies zero or more fstab style mount options.
Options []string
// Mounted specifies whether the rootfs has be mounted or not
Mounted bool
}
If the container's rootfs has been mounted as before, then this struct can be
initialized as: RootFs{Target: <rootfs>, Mounted: true} to be compatible with
previous case.
Fixes:#1158
Signed-off-by: lifupan <lifupan@gmail.com>
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
// Copyright (c) 2016 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package virtcontainers_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
|
)
|
|
|
|
var containerRootfs = vc.RootFs{Target: "/var/lib/container/bundle/", Mounted: true}
|
|
|
|
// This example creates and starts a single container sandbox,
|
|
// using qemu as the hypervisor and hyperstart as the VM agent.
|
|
func Example_createAndStartSandbox() {
|
|
envs := []types.EnvVar{
|
|
{
|
|
Var: "PATH",
|
|
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
|
|
},
|
|
}
|
|
|
|
cmd := types.Cmd{
|
|
Args: strings.Split("/bin/sh", " "),
|
|
Envs: envs,
|
|
WorkDir: "/",
|
|
}
|
|
|
|
// Define the container command and bundle.
|
|
container := vc.ContainerConfig{
|
|
ID: "1",
|
|
RootFs: containerRootfs,
|
|
Cmd: cmd,
|
|
}
|
|
|
|
// Sets the hypervisor configuration.
|
|
hypervisorConfig := vc.HypervisorConfig{
|
|
KernelPath: "/usr/share/kata-containers/vmlinux.container",
|
|
ImagePath: "/usr/share/kata-containers/kata-containers.img",
|
|
HypervisorPath: "/usr/bin/qemu-system-x86_64",
|
|
MemorySize: 1024,
|
|
}
|
|
|
|
// Use hyperstart default values for the agent.
|
|
agConfig := vc.HyperConfig{}
|
|
|
|
// The sandbox configuration:
|
|
// - One container
|
|
// - Hypervisor is QEMU
|
|
// - Agent is hyperstart
|
|
sandboxConfig := vc.SandboxConfig{
|
|
HypervisorType: vc.QemuHypervisor,
|
|
HypervisorConfig: hypervisorConfig,
|
|
|
|
AgentType: vc.HyperstartAgent,
|
|
AgentConfig: agConfig,
|
|
|
|
Containers: []vc.ContainerConfig{container},
|
|
}
|
|
|
|
_, err := vc.RunSandbox(context.Background(), sandboxConfig, nil)
|
|
if err != nil {
|
|
fmt.Printf("Could not run sandbox: %s", err)
|
|
}
|
|
|
|
return
|
|
}
|