add task api endpoint in task create options
Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
@@ -51,6 +51,12 @@ type CreateOpts struct {
|
||||
Runtime string
|
||||
// SandboxID is an optional ID of sandbox this container belongs to
|
||||
SandboxID string
|
||||
// Address is an optional Address for Task API server
|
||||
Address string
|
||||
// Protocol is an optional Protocol for Task API connection
|
||||
Protocol string
|
||||
// Version is an optional Version of the Task API
|
||||
Version uint32
|
||||
}
|
||||
|
||||
// Exit information for a process
|
||||
|
||||
@@ -163,9 +163,22 @@ func (m *ShimManager) ID() string {
|
||||
func (m *ShimManager) Start(ctx context.Context, id string, bundle *Bundle, opts runtime.CreateOpts) (_ ShimInstance, retErr error) {
|
||||
// This container belongs to sandbox which supposed to be already started via sandbox API.
|
||||
if opts.SandboxID != "" {
|
||||
process, err := m.Get(ctx, opts.SandboxID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't find sandbox %s", opts.SandboxID)
|
||||
var params shimbinary.BootstrapParams
|
||||
if opts.Address != "" && opts.Protocol != "" {
|
||||
params = shimbinary.BootstrapParams{
|
||||
Version: int(opts.Version),
|
||||
Address: opts.Address,
|
||||
Protocol: opts.Protocol,
|
||||
}
|
||||
} else {
|
||||
// For those sandbox we can not get endpoint,
|
||||
// fallback to legacy implementation
|
||||
p, restoreErr := m.restoreBootstrapParams(ctx, opts.SandboxID)
|
||||
if restoreErr != nil {
|
||||
return nil, fmt.Errorf("failed to get bootstrap "+
|
||||
"params of sandbox %s, %v, legacy restore error %v", opts.SandboxID, err, restoreErr)
|
||||
}
|
||||
params = p
|
||||
}
|
||||
|
||||
// Write sandbox ID this task belongs to.
|
||||
@@ -173,11 +186,6 @@ func (m *ShimManager) Start(ctx context.Context, id string, bundle *Bundle, opts
|
||||
return nil, err
|
||||
}
|
||||
|
||||
params, err := restoreBootstrapParams(process.Bundle())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := writeBootstrapParams(filepath.Join(bundle.Path, "bootstrap.json"), params); err != nil {
|
||||
return nil, fmt.Errorf("failed to write bootstrap.json for bundle %s: %w", bundle.Path, err)
|
||||
}
|
||||
@@ -251,6 +259,18 @@ func (m *ShimManager) startShim(ctx context.Context, bundle *Bundle, id string,
|
||||
return shim, nil
|
||||
}
|
||||
|
||||
func (m *ShimManager) restoreBootstrapParams(ctx context.Context, sandboxID string) (shimbinary.BootstrapParams, error) {
|
||||
process, err := m.Get(ctx, sandboxID)
|
||||
if err != nil {
|
||||
return shimbinary.BootstrapParams{}, fmt.Errorf("can't find sandbox %s", sandboxID)
|
||||
}
|
||||
params, err := restoreBootstrapParams(filepath.Join(m.state, process.Namespace(), sandboxID))
|
||||
if err != nil {
|
||||
return shimbinary.BootstrapParams{}, err
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// restoreBootstrapParams reads bootstrap.json to restore shim configuration.
|
||||
// If its an old shim, this will perform migration - read address file and write default bootstrap
|
||||
// configuration (version = 2, protocol = ttrpc, and address).
|
||||
|
||||
Reference in New Issue
Block a user