Merge pull request #9736 from abel-von/sandbox-task-0201
sandbox: Store bootstrap parameters in sandbox metadata and shim get them from sandbox metadata rather than other shim's bootstrap.json file.
This commit is contained in:
@@ -188,10 +188,12 @@ func (c *controllerLocal) Start(ctx context.Context, sandboxID string) (sandbox.
|
||||
c.cleanupShim(ctx, sandboxID, svc)
|
||||
return sandbox.ControllerInstance{}, fmt.Errorf("failed to start sandbox %s: %w", sandboxID, errdefs.FromGRPC(err))
|
||||
}
|
||||
|
||||
address, version := shim.Endpoint()
|
||||
return sandbox.ControllerInstance{
|
||||
SandboxID: sandboxID,
|
||||
Pid: resp.GetPid(),
|
||||
Address: address,
|
||||
Version: uint32(version),
|
||||
CreatedAt: resp.GetCreatedAt().AsTime(),
|
||||
}, nil
|
||||
}
|
||||
@@ -302,6 +304,12 @@ func (c *controllerLocal) Status(ctx context.Context, sandboxID string, verbose
|
||||
return sandbox.ControllerStatus{}, fmt.Errorf("failed to query sandbox %s status: %w", sandboxID, err)
|
||||
}
|
||||
|
||||
shim, err := c.shims.Get(ctx, sandboxID)
|
||||
if err != nil {
|
||||
return sandbox.ControllerStatus{}, fmt.Errorf("unable to find sandbox %q", sandboxID)
|
||||
}
|
||||
address, version := shim.Endpoint()
|
||||
|
||||
return sandbox.ControllerStatus{
|
||||
SandboxID: resp.GetSandboxID(),
|
||||
Pid: resp.GetPid(),
|
||||
@@ -310,6 +318,8 @@ func (c *controllerLocal) Status(ctx context.Context, sandboxID string, verbose
|
||||
CreatedAt: resp.GetCreatedAt().AsTime(),
|
||||
ExitedAt: resp.GetExitedAt().AsTime(),
|
||||
Extra: resp.GetExtra(),
|
||||
Address: address,
|
||||
Version: uint32(version),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -155,10 +155,23 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
checkpointPath, err := getRestorePath(container.Runtime.Name, r.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var (
|
||||
checkpointPath string
|
||||
taskAPIAddress string
|
||||
taskAPIVersion uint32
|
||||
)
|
||||
|
||||
if r.Options != nil {
|
||||
taskOptions, err := formatOptions(container.Runtime.Name, r.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
checkpointPath = taskOptions.CriuImagePath
|
||||
taskAPIAddress = taskOptions.TaskApiAddress
|
||||
taskAPIVersion = taskOptions.TaskApiVersion
|
||||
}
|
||||
|
||||
// jump get checkpointPath from checkpoint image
|
||||
if checkpointPath == "" && r.Checkpoint != nil {
|
||||
checkpointPath, err = os.MkdirTemp(os.Getenv("XDG_RUNTIME_DIR"), "ctrd-checkpoint")
|
||||
@@ -196,6 +209,8 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
|
||||
RuntimeOptions: container.Runtime.Options,
|
||||
TaskOptions: r.Options,
|
||||
SandboxID: container.SandboxID,
|
||||
Address: taskAPIAddress,
|
||||
Version: taskAPIVersion,
|
||||
}
|
||||
if r.RuntimePath != "" {
|
||||
opts.Runtime = r.RuntimePath
|
||||
@@ -723,22 +738,14 @@ func getCheckpointPath(runtime string, option *ptypes.Any) (string, error) {
|
||||
return checkpointPath, nil
|
||||
}
|
||||
|
||||
// getRestorePath only suitable for runc runtime now
|
||||
func getRestorePath(runtime string, option *ptypes.Any) (string, error) {
|
||||
if option == nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var restorePath string
|
||||
func formatOptions(runtime string, option *ptypes.Any) (*options.Options, error) {
|
||||
v, err := typeurl.UnmarshalAny(option)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
opts, ok := v.(*options.Options)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid task create option for %s", runtime)
|
||||
return nil, fmt.Errorf("invalid task create option for %s", runtime)
|
||||
}
|
||||
restorePath = opts.CriuImagePath
|
||||
|
||||
return restorePath, nil
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user