mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 06:52:13 +00:00
clh: return error if apiSocketPath failed
If apiSocketPath failed, should return the error, but not nil Fixes: #1724 Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
parent
17d33868c2
commit
0d0a520d42
@ -131,7 +131,6 @@ type cloudHypervisor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var clhKernelParams = []Param{
|
var clhKernelParams = []Param{
|
||||||
|
|
||||||
{"root", "/dev/pmem0p1"},
|
{"root", "/dev/pmem0p1"},
|
||||||
{"panic", "1"}, // upon kernel panic wait 1 second before reboot
|
{"panic", "1"}, // upon kernel panic wait 1 second before reboot
|
||||||
{"no_timer_check", ""}, // do not check broken timer IRQ resources
|
{"no_timer_check", ""}, // do not check broken timer IRQ resources
|
||||||
@ -141,7 +140,6 @@ var clhKernelParams = []Param{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var clhDebugKernelParams = []Param{
|
var clhDebugKernelParams = []Param{
|
||||||
|
|
||||||
{"console", "ttyS0,115200n8"}, // enable serial console
|
{"console", "ttyS0,115200n8"}, // enable serial console
|
||||||
{"systemd.log_target", "console"}, // send loggng to the console
|
{"systemd.log_target", "console"}, // send loggng to the console
|
||||||
}
|
}
|
||||||
@ -192,13 +190,11 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
err = clh.getAvailableVersion()
|
err = clh.getAvailableVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := clh.checkVersion(); err != nil {
|
if err := clh.checkVersion(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clh.Logger().WithField("function", "createSandbox").Info("creating Sandbox")
|
clh.Logger().WithField("function", "createSandbox").Info("creating Sandbox")
|
||||||
@ -206,7 +202,6 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id)
|
virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if clh.state.PID > 0 {
|
if clh.state.PID > 0 {
|
||||||
@ -222,7 +217,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
|
|
||||||
// No need to return an error from there since there might be nothing
|
// No need to return an error from there since there might be nothing
|
||||||
// to fetch if this is the first time the hypervisor is created.
|
// to fetch if this is the first time the hypervisor is created.
|
||||||
clh.Logger().WithField("function", "createSandbox").WithError(err).Info("Sandbox not found creating ")
|
clh.Logger().WithField("function", "createSandbox").Info("Sandbox not found creating")
|
||||||
|
|
||||||
// Set initial memomory size of the virtual machine
|
// Set initial memomory size of the virtual machine
|
||||||
// Convert to int64 openApiClient only support int64
|
// Convert to int64 openApiClient only support int64
|
||||||
@ -260,7 +255,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
params = append(params, clhDebugKernelParams...)
|
params = append(params, clhDebugKernelParams...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Followed by extra debug parameters defined in the configuration file
|
// Followed by extra kernel parameters defined in the configuration file
|
||||||
params = append(params, clh.config.KernelParams...)
|
params = append(params, clh.config.KernelParams...)
|
||||||
|
|
||||||
clh.vmconfig.Cmdline.Args = kernelParamsToString(params)
|
clh.vmconfig.Cmdline.Args = kernelParamsToString(params)
|
||||||
@ -291,7 +286,6 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
clh.vmconfig.Serial = chclient.ConsoleConfig{
|
clh.vmconfig.Serial = chclient.ConsoleConfig{
|
||||||
Mode: cctTTY,
|
Mode: cctTTY,
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
clh.vmconfig.Serial = chclient.ConsoleConfig{
|
clh.vmconfig.Serial = chclient.ConsoleConfig{
|
||||||
Mode: cctNULL,
|
Mode: cctNULL,
|
||||||
@ -311,8 +305,8 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
// Overwrite the default value of HTTP API socket path for cloud hypervisor
|
// Overwrite the default value of HTTP API socket path for cloud hypervisor
|
||||||
apiSocketPath, err := clh.apiSocketPath(id)
|
apiSocketPath, err := clh.apiSocketPath(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
clh.Logger().Info("Invalid api socket path for cloud-hypervisor")
|
clh.Logger().WithError(err).Info("Invalid api socket path for cloud-hypervisor")
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
clh.state.apiSocket = apiSocketPath
|
clh.state.apiSocket = apiSocketPath
|
||||||
|
|
||||||
@ -377,10 +371,10 @@ func (clh *cloudHypervisor) startSandbox(ctx context.Context, timeout int) error
|
|||||||
return errors.New("cloud-hypervisor only supports virtio based file sharing")
|
return errors.New("cloud-hypervisor only supports virtio based file sharing")
|
||||||
}
|
}
|
||||||
|
|
||||||
pid, err := clh.LaunchClh()
|
pid, err := clh.launchClh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if shutdownErr := clh.virtiofsd.Stop(ctx); shutdownErr != nil {
|
if shutdownErr := clh.virtiofsd.Stop(ctx); shutdownErr != nil {
|
||||||
clh.Logger().WithField("error", shutdownErr).Warn("error shutting down Virtiofsd")
|
clh.Logger().WithError(shutdownErr).Warn("error shutting down Virtiofsd")
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to launch cloud-hypervisor: %q", err)
|
return fmt.Errorf("failed to launch cloud-hypervisor: %q", err)
|
||||||
}
|
}
|
||||||
@ -400,7 +394,7 @@ func (clh *cloudHypervisor) getSandboxConsole(ctx context.Context, id string) (s
|
|||||||
clh.Logger().WithField("function", "getSandboxConsole").WithField("id", id).Info("Get Sandbox Console")
|
clh.Logger().WithField("function", "getSandboxConsole").WithField("id", id).Info("Get Sandbox Console")
|
||||||
master, slave, err := console.NewPty()
|
master, slave, err := console.NewPty()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
clh.Logger().Debugf("Error create pseudo tty: %v", err)
|
clh.Logger().WithError(err).Error("Error create pseudo tty")
|
||||||
return consoleProtoPty, "", err
|
return consoleProtoPty, "", err
|
||||||
}
|
}
|
||||||
clh.console = master
|
clh.console = master
|
||||||
@ -514,7 +508,6 @@ func (clh *cloudHypervisor) hotplugRemoveDevice(ctx context.Context, devInfo int
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
_, err := cl.VmRemoveDevicePut(ctx, chclient.VmRemoveDevice{Id: deviceID})
|
_, err := cl.VmRemoveDevicePut(ctx, chclient.VmRemoveDevice{Id: deviceID})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("failed to hotplug remove (unplug) device %+v: %s", devInfo, openAPIClientError(err))
|
err = fmt.Errorf("failed to hotplug remove (unplug) device %+v: %s", devInfo, openAPIClientError(err))
|
||||||
}
|
}
|
||||||
@ -856,7 +849,6 @@ func (clh *cloudHypervisor) apiSocketPath(id string) (string, error) {
|
|||||||
|
|
||||||
func (clh *cloudHypervisor) waitVMM(timeout uint) error {
|
func (clh *cloudHypervisor) waitVMM(timeout uint) error {
|
||||||
clhRunning, err := clh.isClhRunning(timeout)
|
clhRunning, err := clh.isClhRunning(timeout)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -890,7 +882,6 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
|
|||||||
clhPath, err := clh.clhPath()
|
clhPath, err := clh.clhPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(clhPath, "--version")
|
cmd := exec.Command(clhPath, "--version")
|
||||||
@ -902,7 +893,6 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
|
|||||||
words := strings.Fields(string(out))
|
words := strings.Fields(string(out))
|
||||||
if len(words) != 2 {
|
if len(words) != 2 {
|
||||||
return errors.New("Failed to parse cloud-hypervisor version response. Illegal length")
|
return errors.New("Failed to parse cloud-hypervisor version response. Illegal length")
|
||||||
|
|
||||||
}
|
}
|
||||||
versionSplit := strings.SplitN(words[1], ".", -1)
|
versionSplit := strings.SplitN(words[1], ".", -1)
|
||||||
if len(versionSplit) != 3 {
|
if len(versionSplit) != 3 {
|
||||||
@ -915,12 +905,10 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
|
|||||||
major, err := strconv.ParseUint(versionSplit[0], 10, 64)
|
major, err := strconv.ParseUint(versionSplit[0], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
minor, err := strconv.ParseUint(versionSplit[1], 10, 64)
|
minor, err := strconv.ParseUint(versionSplit[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// revision could have aditional commit information separated by '-'
|
// revision could have aditional commit information separated by '-'
|
||||||
@ -942,7 +930,7 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) LaunchClh() (int, error) {
|
func (clh *cloudHypervisor) launchClh() (int, error) {
|
||||||
|
|
||||||
clhPath, err := clh.clhPath()
|
clhPath, err := clh.clhPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1026,7 +1014,6 @@ func kernelParamsToString(params []Param) string {
|
|||||||
for _, p := range params {
|
for _, p := range params {
|
||||||
paramBuilder.WriteString(p.Key)
|
paramBuilder.WriteString(p.Key)
|
||||||
if len(p.Value) > 0 {
|
if len(p.Value) > 0 {
|
||||||
|
|
||||||
paramBuilder.WriteString("=")
|
paramBuilder.WriteString("=")
|
||||||
paramBuilder.WriteString(p.Value)
|
paramBuilder.WriteString(p.Value)
|
||||||
}
|
}
|
||||||
@ -1084,7 +1071,6 @@ func (clh *cloudHypervisor) newAPIClient() *chclient.DefaultApiService {
|
|||||||
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
|
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return net.DialUnix("unix", nil, addr)
|
return net.DialUnix("unix", nil, addr)
|
||||||
@ -1123,13 +1109,11 @@ func (clh *cloudHypervisor) bootVM(ctx context.Context) error {
|
|||||||
clh.Logger().WithField("body", string(bodyBuf)).Debug("VM config")
|
clh.Logger().WithField("body", string(bodyBuf)).Debug("VM config")
|
||||||
}
|
}
|
||||||
_, err := cl.CreateVM(ctx, clh.vmconfig)
|
_, err := cl.CreateVM(ctx, clh.vmconfig)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return openAPIClientError(err)
|
return openAPIClientError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := clh.vmInfo()
|
info, err := clh.vmInfo()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1142,13 +1126,11 @@ func (clh *cloudHypervisor) bootVM(ctx context.Context) error {
|
|||||||
|
|
||||||
clh.Logger().Debug("Booting VM")
|
clh.Logger().Debug("Booting VM")
|
||||||
_, err = cl.BootVM(ctx)
|
_, err = cl.BootVM(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return openAPIClientError(err)
|
return openAPIClientError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err = clh.vmInfo()
|
info, err = clh.vmInfo()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1176,13 +1158,11 @@ func (clh *cloudHypervisor) addNet(e Endpoint) error {
|
|||||||
|
|
||||||
mac := e.HardwareAddr()
|
mac := e.HardwareAddr()
|
||||||
netPair := e.NetworkPair()
|
netPair := e.NetworkPair()
|
||||||
|
|
||||||
if netPair == nil {
|
if netPair == nil {
|
||||||
return errors.New("net Pair to be added is nil, needed to get TAP path")
|
return errors.New("net Pair to be added is nil, needed to get TAP path")
|
||||||
}
|
}
|
||||||
|
|
||||||
tapPath := netPair.TapInterface.TAPIface.Name
|
tapPath := netPair.TapInterface.TAPIface.Name
|
||||||
|
|
||||||
if tapPath == "" {
|
if tapPath == "" {
|
||||||
return errors.New("TAP path in network pair is empty")
|
return errors.New("TAP path in network pair is empty")
|
||||||
}
|
}
|
||||||
@ -1301,7 +1281,6 @@ func (clh *cloudHypervisor) vmInfo() (chclient.VmInfo, error) {
|
|||||||
clh.Logger().WithError(openAPIClientError(err)).Warn("VmInfoGet failed")
|
clh.Logger().WithError(openAPIClientError(err)).Warn("VmInfoGet failed")
|
||||||
}
|
}
|
||||||
return info, openAPIClientError(err)
|
return info, openAPIClientError(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) isRateLimiterBuiltin() bool {
|
func (clh *cloudHypervisor) isRateLimiterBuiltin() bool {
|
||||||
|
@ -36,7 +36,7 @@ func newClhConfig() (HypervisorConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if testVirtiofsdPath == "" {
|
if testVirtiofsdPath == "" {
|
||||||
return HypervisorConfig{}, errors.New("hypervisor fake path is empty")
|
return HypervisorConfig{}, errors.New("virtiofsd fake path is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(testClhPath); os.IsNotExist(err) {
|
if _, err := os.Stat(testClhPath); os.IsNotExist(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user