mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 08:17:37 +00:00
persist: merge "agent.json"
Manage "agent.json" with new store. Signed-off-by: Wei Zhang <weizhang555.zw@gmail.com>
This commit is contained in:
parent
7d5e48f1b5
commit
99cf3f80d7
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kata-containers/agent/protocols/grpc"
|
||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
@ -255,4 +256,10 @@ type agent interface {
|
||||
|
||||
// cleanup removes all on disk information generated by the agent
|
||||
cleanup(s *Sandbox)
|
||||
|
||||
// return data for saving
|
||||
save() persistapi.AgentState
|
||||
|
||||
// load data from disk
|
||||
load(persistapi.AgentState)
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
kataclient "github.com/kata-containers/agent/protocols/client"
|
||||
"github.com/kata-containers/agent/protocols/grpc"
|
||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
|
||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||
@ -286,8 +287,10 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config interface
|
||||
k.proxyBuiltIn = isProxyBuiltIn(sandbox.config.ProxyType)
|
||||
|
||||
// Fetch agent runtime info.
|
||||
if err := sandbox.store.Load(store.Agent, &k.state); err != nil {
|
||||
k.Logger().Debug("Could not retrieve anything from storage")
|
||||
if !sandbox.supportNewStore() {
|
||||
if err := sandbox.store.Load(store.Agent, &k.state); err != nil {
|
||||
k.Logger().Debug("Could not retrieve anything from storage")
|
||||
}
|
||||
}
|
||||
|
||||
return disableVMShutdown, nil
|
||||
@ -686,7 +689,7 @@ func (k *kataAgent) setProxy(sandbox *Sandbox, proxy proxy, pid int, url string)
|
||||
k.proxy = proxy
|
||||
k.state.ProxyPid = pid
|
||||
k.state.URL = url
|
||||
if sandbox != nil {
|
||||
if sandbox != nil && !sandbox.supportNewStore() {
|
||||
if err := sandbox.store.Store(store.Agent, k.state); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -841,9 +844,11 @@ func (k *kataAgent) stopSandbox(sandbox *Sandbox) error {
|
||||
// clean up agent state
|
||||
k.state.ProxyPid = -1
|
||||
k.state.URL = ""
|
||||
if err := sandbox.store.Store(store.Agent, k.state); err != nil {
|
||||
// ignore error
|
||||
k.Logger().WithError(err).WithField("sandbox", sandbox.id).Error("failed to clean up agent state")
|
||||
if !sandbox.supportNewStore() {
|
||||
if err := sandbox.store.Store(store.Agent, k.state); err != nil {
|
||||
// ignore error
|
||||
k.Logger().WithError(err).WithField("sandbox", sandbox.id).Error("failed to clean up agent state")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -2074,3 +2079,14 @@ func (k *kataAgent) cleanup(s *Sandbox) {
|
||||
k.Logger().WithError(err).Errorf("failed to cleanup vm share path %s", path)
|
||||
}
|
||||
}
|
||||
|
||||
func (k *kataAgent) save() (s persistapi.AgentState) {
|
||||
s.ProxyPid = k.state.ProxyPid
|
||||
s.URL = k.state.URL
|
||||
return
|
||||
}
|
||||
|
||||
func (k *kataAgent) load(s persistapi.AgentState) {
|
||||
k.state.ProxyPid = s.ProxyPid
|
||||
k.state.URL = s.URL
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kata-containers/agent/protocols/grpc"
|
||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -233,3 +234,11 @@ func (n *noopAgent) markDead() {
|
||||
|
||||
func (n *noopAgent) cleanup(s *Sandbox) {
|
||||
}
|
||||
|
||||
// save is the Noop agent state saver. It does nothing.
|
||||
func (n *noopAgent) save() (s persistapi.AgentState) {
|
||||
return
|
||||
}
|
||||
|
||||
// load is the Noop agent state loader. It does nothing.
|
||||
func (n *noopAgent) load(s persistapi.AgentState) {}
|
||||
|
@ -154,6 +154,12 @@ func (s *Sandbox) dumpMounts(cs map[string]persistapi.ContainerState) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sandbox) dumpAgent(ss *persistapi.SandboxState) {
|
||||
if s.agent != nil {
|
||||
ss.AgentState = s.agent.save()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sandbox) Save() error {
|
||||
var (
|
||||
ss = persistapi.SandboxState{}
|
||||
@ -166,6 +172,7 @@ func (s *Sandbox) Save() error {
|
||||
s.dumpDevices(&ss, cs)
|
||||
s.dumpProcess(cs)
|
||||
s.dumpMounts(cs)
|
||||
s.dumpAgent(&ss)
|
||||
|
||||
if err := s.newStore.ToDisk(ss, cs); err != nil {
|
||||
return err
|
||||
@ -196,6 +203,12 @@ func (s *Sandbox) loadHypervisor(hs persistapi.HypervisorState) {
|
||||
s.hypervisor.load(hs)
|
||||
}
|
||||
|
||||
func (s *Sandbox) loadAgent(as persistapi.AgentState) {
|
||||
if s.agent != nil {
|
||||
s.agent.load(as)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sandbox) loadDevices(devStates []persistapi.DeviceState) {
|
||||
s.devManager.LoadDevices(devStates)
|
||||
}
|
||||
@ -245,6 +258,7 @@ func (s *Sandbox) Restore() error {
|
||||
s.loadState(ss)
|
||||
s.loadHypervisor(ss.HypervisorState)
|
||||
s.loadDevices(ss.Devices)
|
||||
s.loadAgent(ss.AgentState)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -8,12 +8,12 @@ package persistapi
|
||||
|
||||
// ============= sandbox level resources =============
|
||||
|
||||
// ProxyState save proxy state data
|
||||
type ProxyState struct {
|
||||
// AgentState save agent state data
|
||||
type AgentState struct {
|
||||
// Pid of proxy process
|
||||
Pid int
|
||||
ProxyPid int
|
||||
|
||||
// URL to connect to proxy
|
||||
// URL to connect to agent
|
||||
URL string
|
||||
}
|
||||
|
||||
@ -46,8 +46,8 @@ type SandboxState struct {
|
||||
// HypervisorState saves hypervisor specific data
|
||||
HypervisorState HypervisorState
|
||||
|
||||
// ProxyState saves state data of proxy process
|
||||
ProxyState ProxyState
|
||||
// AgentState saves state data of agent
|
||||
AgentState AgentState
|
||||
|
||||
// Network saves network configuration of sandbox
|
||||
Network NetworkInfo
|
||||
|
Loading…
Reference in New Issue
Block a user