gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/kata_shim.go (about)

     1  // Copyright (c) 2017 Intel Corporation
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  
     6  package virtcontainers
     7  
     8  import (
     9  	"fmt"
    10  )
    11  
    12  type kataShim struct{}
    13  
    14  // start is the ccShim start implementation.
    15  // It starts the cc-shim binary with URL and token flags provided by
    16  // the proxy.
    17  func (s *kataShim) start(sandbox *Sandbox, params ShimParams) (int, error) {
    18  	if sandbox.config == nil {
    19  		return -1, fmt.Errorf("Sandbox config cannot be nil")
    20  	}
    21  
    22  	config, ok := newShimConfig(*(sandbox.config)).(ShimConfig)
    23  	if !ok {
    24  		return -1, fmt.Errorf("Wrong shim config type, should be ShimConfig type")
    25  	}
    26  
    27  	if config.Path == "" {
    28  		return -1, fmt.Errorf("Shim path cannot be empty")
    29  	}
    30  
    31  	if params.URL == "" {
    32  		return -1, fmt.Errorf("URL cannot be empty")
    33  	}
    34  
    35  	if params.Container == "" {
    36  		return -1, fmt.Errorf("Container cannot be empty")
    37  	}
    38  
    39  	if params.Token == "" {
    40  		return -1, fmt.Errorf("Process token cannot be empty")
    41  	}
    42  
    43  	args := []string{config.Path, "-agent", params.URL, "-container", params.Container, "-exec-id", params.Token}
    44  
    45  	if params.Terminal {
    46  		args = append(args, "-terminal")
    47  	}
    48  
    49  	if config.Debug {
    50  		args = append(args, "-log", "debug")
    51  		if params.ConsoleURL != "" {
    52  			args = append(args, "-agent-logs-socket", params.ConsoleURL)
    53  		}
    54  	}
    55  
    56  	if config.Trace {
    57  		args = append(args, "-trace")
    58  	}
    59  
    60  	return startShim(args, params)
    61  }