add task api endpoint in task create options
Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
		@@ -155,10 +155,25 @@ 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
 | 
			
		||||
		taskAPIProtocol 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
 | 
			
		||||
		taskAPIProtocol = taskOptions.TaskApiProtocol
 | 
			
		||||
		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 +211,9 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
 | 
			
		||||
		RuntimeOptions: container.Runtime.Options,
 | 
			
		||||
		TaskOptions:    r.Options,
 | 
			
		||||
		SandboxID:      container.SandboxID,
 | 
			
		||||
		Address:        taskAPIAddress,
 | 
			
		||||
		Protocol:       taskAPIProtocol,
 | 
			
		||||
		Version:        taskAPIVersion,
 | 
			
		||||
	}
 | 
			
		||||
	if r.RuntimePath != "" {
 | 
			
		||||
		opts.Runtime = r.RuntimePath
 | 
			
		||||
@@ -723,22 +741,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