mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-31 15:25:26 +00:00
Merge pull request #634 from sboeuf/add_noop_filesystem
virtcontainers: storage: Rework resource storage
This commit is contained in:
commit
8b5fa32d9b
@ -112,49 +112,6 @@ var runStoragePath = filepath.Join("/run", storagePathSuffix, sandboxPathSuffix)
|
|||||||
// It will contain all guest vm sockets and shared mountpoints.
|
// It will contain all guest vm sockets and shared mountpoints.
|
||||||
var RunVMStoragePath = filepath.Join("/run", storagePathSuffix, vmPathSuffix)
|
var RunVMStoragePath = filepath.Join("/run", storagePathSuffix, vmPathSuffix)
|
||||||
|
|
||||||
// resourceStorage is the virtcontainers resources (configuration, state, etc...)
|
|
||||||
// storage interface.
|
|
||||||
// The default resource storage implementation is filesystem.
|
|
||||||
type resourceStorage interface {
|
|
||||||
// Create all resources for a sandbox
|
|
||||||
createAllResources(ctx context.Context, sandbox *Sandbox) error
|
|
||||||
|
|
||||||
// Resources URIs functions return both the URI
|
|
||||||
// for the actual resource and the URI base.
|
|
||||||
containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error)
|
|
||||||
sandboxURI(sandboxID string, resource sandboxResource) (string, string, error)
|
|
||||||
|
|
||||||
// Sandbox resources
|
|
||||||
storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error
|
|
||||||
deleteSandboxResources(sandboxID string, resources []sandboxResource) error
|
|
||||||
fetchSandboxConfig(sandboxID string) (SandboxConfig, error)
|
|
||||||
fetchSandboxState(sandboxID string) (State, error)
|
|
||||||
fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error)
|
|
||||||
storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error
|
|
||||||
fetchSandboxDevices(sandboxID string) ([]api.Device, error)
|
|
||||||
storeSandboxDevices(sandboxID string, devices []api.Device) error
|
|
||||||
|
|
||||||
// Hypervisor resources
|
|
||||||
fetchHypervisorState(sandboxID string, state interface{}) error
|
|
||||||
storeHypervisorState(sandboxID string, state interface{}) error
|
|
||||||
|
|
||||||
// Agent resources
|
|
||||||
fetchAgentState(sandboxID string, state interface{}) error
|
|
||||||
storeAgentState(sandboxID string, state interface{}) error
|
|
||||||
|
|
||||||
// Container resources
|
|
||||||
storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error
|
|
||||||
deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error
|
|
||||||
fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error)
|
|
||||||
fetchContainerState(sandboxID, containerID string) (State, error)
|
|
||||||
fetchContainerProcess(sandboxID, containerID string) (Process, error)
|
|
||||||
storeContainerProcess(sandboxID, containerID string, process Process) error
|
|
||||||
fetchContainerMounts(sandboxID, containerID string) ([]Mount, error)
|
|
||||||
storeContainerMounts(sandboxID, containerID string, mounts []Mount) error
|
|
||||||
fetchContainerDevices(sandboxID, containerID string) ([]ContainerDevice, error)
|
|
||||||
storeContainerDevices(sandboxID, containerID string, devices []ContainerDevice) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// filesystem is a resourceStorage interface implementation for a local filesystem.
|
// filesystem is a resourceStorage interface implementation for a local filesystem.
|
||||||
type filesystem struct {
|
type filesystem struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@ -246,17 +203,6 @@ func (fs *filesystem) storeFile(file string, data interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypedDevice is used as an intermediate representation for marshalling
|
|
||||||
// and unmarshalling Device implementations.
|
|
||||||
type TypedDevice struct {
|
|
||||||
Type string
|
|
||||||
|
|
||||||
// Data is assigned the Device object.
|
|
||||||
// This being declared as RawMessage prevents it from being marshalled/unmarshalled.
|
|
||||||
// We do that explicitly depending on Type.
|
|
||||||
Data json.RawMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// storeDeviceIDFile is used to marshal and store device IDs to disk.
|
// storeDeviceIDFile is used to marshal and store device IDs to disk.
|
||||||
func (fs *filesystem) storeDeviceIDFile(file string, data interface{}) error {
|
func (fs *filesystem) storeDeviceIDFile(file string, data interface{}) error {
|
||||||
if file == "" {
|
if file == "" {
|
112
virtcontainers/noop_resource_storage.go
Normal file
112
virtcontainers/noop_resource_storage.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// Copyright (c) 2018 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package virtcontainers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/device/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
type noopResourceStorage struct{}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) createAllResources(sandbox *Sandbox) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error) {
|
||||||
|
return "", "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) sandboxURI(sandboxID string, resource sandboxResource) (string, string, error) {
|
||||||
|
return "", "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) deleteSandboxResources(sandboxID string, resources []sandboxResource) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchSandboxConfig(sandboxID string) (SandboxConfig, error) {
|
||||||
|
return SandboxConfig{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchSandboxState(sandboxID string) (State, error) {
|
||||||
|
return State{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error) {
|
||||||
|
return NetworkNamespace{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchSandboxDevices(sandboxID string) ([]api.Device, error) {
|
||||||
|
return []api.Device{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeSandboxDevices(sandboxID string, devices []api.Device) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchHypervisorState(sandboxID string, state interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeHypervisorState(sandboxID string, state interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchAgentState(sandboxID string, state interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeAgentState(sandboxID string, state interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error) {
|
||||||
|
return ContainerConfig{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchContainerState(sandboxID, containerID string) (State, error) {
|
||||||
|
return State{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchContainerProcess(sandboxID, containerID string) (Process, error) {
|
||||||
|
return Process{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeContainerProcess(sandboxID, containerID string, process Process) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchContainerMounts(sandboxID, containerID string) ([]Mount, error) {
|
||||||
|
return []Mount{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeContainerMounts(sandboxID, containerID string, mounts []Mount) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) fetchContainerDevices(sandboxID, containerID string) ([]ContainerDevice, error) {
|
||||||
|
return []ContainerDevice{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopResourceStorage) storeContainerDevices(sandboxID, containerID string, devices []ContainerDevice) error {
|
||||||
|
return nil
|
||||||
|
}
|
188
virtcontainers/noop_resource_storage_test.go
Normal file
188
virtcontainers/noop_resource_storage_test.go
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
// Copyright (c) 2018 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package virtcontainers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/device/api"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNoopCreateAllResources(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.createAllResources(nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopContainerURI(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, _, err := n.containerURI("", "", 0)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopSandboxURI(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, _, err := n.sandboxURI("", 0)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreSandboxResource(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeSandboxResource("", 0, nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopDeleteSandboxResources(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.deleteSandboxResources("", []sandboxResource{0})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchSandboxConfig(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchSandboxConfig("")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchSandboxState(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchSandboxState("")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchSandboxNetwork(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchSandboxNetwork("")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreSandboxNetwork(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeSandboxNetwork("", NetworkNamespace{})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchSandboxDevices(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchSandboxDevices("")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreSandboxDevices(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeSandboxDevices("", []api.Device{})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchHypervisorState(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.fetchHypervisorState("", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreHypervisorState(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeHypervisorState("", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchAgentState(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.fetchAgentState("", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreAgentState(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeAgentState("", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreContainerResource(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeContainerResource("", "", 0, nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopDeleteContainerResources(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.deleteContainerResources("", "", []sandboxResource{0})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchContainerConfig(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchContainerConfig("", "")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchContainerState(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchContainerState("", "")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchContainerProcess(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchContainerProcess("", "")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreContainerProcess(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeContainerProcess("", "", Process{})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchContainerMounts(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchContainerMounts("", "")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreContainerMounts(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeContainerMounts("", "", []Mount{})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopFetchContainerDevices(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
_, err := n.fetchContainerDevices("", "")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoopStoreContainerDevices(t *testing.T) {
|
||||||
|
n := &noopResourceStorage{}
|
||||||
|
|
||||||
|
err := n.storeContainerDevices("", "", []ContainerDevice{})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
67
virtcontainers/resource_storage.go
Normal file
67
virtcontainers/resource_storage.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (c) 2018 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package virtcontainers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/device/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TypedDevice is used as an intermediate representation for marshalling
|
||||||
|
// and unmarshalling Device implementations.
|
||||||
|
type TypedDevice struct {
|
||||||
|
Type string
|
||||||
|
|
||||||
|
// Data is assigned the Device object.
|
||||||
|
// This being declared as RawMessage prevents it from being marshalled/unmarshalled.
|
||||||
|
// We do that explicitly depending on Type.
|
||||||
|
Data json.RawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
// resourceStorage is the virtcontainers resources (configuration, state, etc...)
|
||||||
|
// storage interface.
|
||||||
|
// The default resource storage implementation is filesystem.
|
||||||
|
type resourceStorage interface {
|
||||||
|
// Create all resources for a sandbox
|
||||||
|
createAllResources(ctx context.Context, sandbox *Sandbox) error
|
||||||
|
|
||||||
|
// Resources URIs functions return both the URI
|
||||||
|
// for the actual resource and the URI base.
|
||||||
|
containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error)
|
||||||
|
sandboxURI(sandboxID string, resource sandboxResource) (string, string, error)
|
||||||
|
|
||||||
|
// Sandbox resources
|
||||||
|
storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error
|
||||||
|
deleteSandboxResources(sandboxID string, resources []sandboxResource) error
|
||||||
|
fetchSandboxConfig(sandboxID string) (SandboxConfig, error)
|
||||||
|
fetchSandboxState(sandboxID string) (State, error)
|
||||||
|
fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error)
|
||||||
|
storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error
|
||||||
|
fetchSandboxDevices(sandboxID string) ([]api.Device, error)
|
||||||
|
storeSandboxDevices(sandboxID string, devices []api.Device) error
|
||||||
|
|
||||||
|
// Hypervisor resources
|
||||||
|
fetchHypervisorState(sandboxID string, state interface{}) error
|
||||||
|
storeHypervisorState(sandboxID string, state interface{}) error
|
||||||
|
|
||||||
|
// Agent resources
|
||||||
|
fetchAgentState(sandboxID string, state interface{}) error
|
||||||
|
storeAgentState(sandboxID string, state interface{}) error
|
||||||
|
|
||||||
|
// Container resources
|
||||||
|
storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error
|
||||||
|
deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error
|
||||||
|
fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error)
|
||||||
|
fetchContainerState(sandboxID, containerID string) (State, error)
|
||||||
|
fetchContainerProcess(sandboxID, containerID string) (Process, error)
|
||||||
|
storeContainerProcess(sandboxID, containerID string, process Process) error
|
||||||
|
fetchContainerMounts(sandboxID, containerID string) ([]Mount, error)
|
||||||
|
storeContainerMounts(sandboxID, containerID string, mounts []Mount) error
|
||||||
|
fetchContainerDevices(sandboxID, containerID string) ([]ContainerDevice, error)
|
||||||
|
storeContainerDevices(sandboxID, containerID string, devices []ContainerDevice) error
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user