Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions internal/oci/runtime_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/containerd/containerd/runtime/v2/task"
"github.com/containerd/ttrpc"
"github.com/containers/libpod/v2/pkg/cgroups"
crioannotations "github.com/cri-o/cri-o/pkg/annotations"
"github.com/cri-o/cri-o/utils"
"github.com/cri-o/cri-o/utils/errdefs"
"github.com/cri-o/cri-o/utils/fifo"
Expand Down Expand Up @@ -237,6 +238,11 @@ func (r *runtimeVM) startRuntimeDaemon(c *Container) error {
// Retrieve the address from the output
address := strings.TrimSpace(string(out))

if c.state.Annotations == nil {
c.state.Annotations = make(map[string]string)
}
c.state.Annotations[crioannotations.ShimSocketPathAnnotation] = address

// Now the RPC server is running, let's connect to it
conn, err := client.Connect(address, client.AnonDialer)
if err != nil {
Expand Down Expand Up @@ -626,10 +632,21 @@ func (r *runtimeVM) updateContainerStatus(c *Container) error {
logrus.Debug("runtimeVM.updateContainerStatus() start")
defer logrus.Debug("runtimeVM.updateContainerStatus() end")

// This can happen on restore, for example if we switch the runtime type
// for a container from "oci" to "vm" for the same runtime.
if r.task == nil {
return errors.New("runtime not correctly setup")
if address, ok := c.state.Annotations[crioannotations.ShimSocketPathAnnotation]; ok {
// connect with already running gRPC server
conn, err := client.Connect(address, client.AnonDialer)
if err != nil {
return err
}

options := ttrpc.WithOnClose(func() { conn.Close() })
cl := ttrpc.NewClient(conn, options)
r.client = cl
r.task = task.NewTaskClient(cl)
} else {
return errors.New("runtime not correctly setup")
}
}

response, err := r.task.State(r.ctx, &task.StateRequest{
Expand Down
3 changes: 3 additions & 0 deletions pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ const (

// OCISeccompBPFHookAnnotation is the annotation used by the OCI seccomp BPF hook for tracing container syscalls
OCISeccompBPFHookAnnotation = "io.containers.trace-syscall"

// ShimSocketPathAnnotation is a container state annotation created by vm runtime
ShimSocketPathAnnotation = "shim-sock-path.crio.io"
)