Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
storage: create k8s emptyDir inside VM
Browse files Browse the repository at this point in the history
This introduces a new storage type: local. Local storage type will
tell the kata-agent to create an empty directory in the sandbox
directory within the VM.

K8s host emptyDirs will then use the local storage type and mount it
inside each container. By doing this, we utilise the storage medium
that the sandbox uses. In most cases this will be 9p.

If the VM is using device mapper for container storage, the containers
will benefit from the better performance of device mapper for
host emptyDir.

Fixes #1472

Signed-off-by: Alex Price <aprice@atlassian.com>
  • Loading branch information
awprice committed Apr 5, 2019
1 parent 228d151 commit 3b27b22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/katautils/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func SetEphemeralStorageType(ociSpec oci.CompatOCISpec) oci.CompatOCISpec {
if vc.IsEphemeralStorage(mnt.Source) {
ociSpec.Mounts[idx].Type = "ephemeral"
}
if vc.Isk8sHostEmptyDir(mnt.Source) {
ociSpec.Mounts[idx].Type = "local"
}
}
return ociSpec
}
Expand Down
28 changes: 28 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
kataEphemeralDevType = "ephemeral"
ephemeralPath = filepath.Join(kataGuestSandboxDir, kataEphemeralDevType)
grpcMaxDataSize = int64(1024 * 1024)
kataLocalDevType = "local"
)

// KataAgentConfig is a structure storing information needed
Expand Down Expand Up @@ -1038,6 +1039,9 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,
epheStorages := k.handleEphemeralStorage(ociSpec.Mounts)
ctrStorages = append(ctrStorages, epheStorages...)

localStorages := k.handleLocalStorage(ociSpec.Mounts, sandbox.id)
ctrStorages = append(ctrStorages, localStorages...)

// We replace all OCI mount sources that match our container mount
// with the right source path (The guest one).
if err = k.replaceOCIMountSource(ociSpec, newMounts); err != nil {
Expand Down Expand Up @@ -1134,6 +1138,30 @@ func (k *kataAgent) handleEphemeralStorage(mounts []specs.Mount) []*grpc.Storage
return epheStorages
}

// handleLocalStorage handles local storage within the VM
// by creating a directory in the VM from the source of the mount point
func (k *kataAgent) handleLocalStorage(mounts []specs.Mount, sandboxID string) []*grpc.Storage {
var localStorages []*grpc.Storage
for idx, mnt := range mounts {
if mnt.Type == kataLocalDevType {
// Set the mount source path to a the desired directory point in the VM.
// In this case it is located in the sandbox directory.
mounts[idx].Source = filepath.Join(kataGuestSharedDir, sandboxID, kataLocalDevType, filepath.Base(mnt.Source))

// Create a storage struct so that the kata agent is able to create the
// directory inside the VM.
localStorage := &grpc.Storage{
Driver: kataLocalDevType,
Source: "local",
Fstype: "local",
MountPoint: mounts[idx].Source,
}
localStorages = append(localStorages, localStorage)
}
}
return localStorages
}

// handleBlockVolumes handles volumes that are block devices files
// by passing the block devices as Storage to the agent.
func (k *kataAgent) handleBlockVolumes(c *Container) []*grpc.Storage {
Expand Down

0 comments on commit 3b27b22

Please sign in to comment.