Skip to content

Commit

Permalink
Merge pull request kata-containers#6001 from fidencio/topic/add-netwo…
Browse files Browse the repository at this point in the history
…rk-hotplug-support-for-clh

clh: Ensure it works with Docker / Moby
  • Loading branch information
likebreath authored Jan 6, 2023
2 parents ec18368 + efa4fc0 commit 8265aad
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/runtime/virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ var vmAddNetPutRequest = func(clh *cloudHypervisor) error {
resp.Body.Close()
resp.Body = io.NopCloser(bytes.NewBuffer(respBody))

if resp.StatusCode != 204 {
if resp.StatusCode != 200 && resp.StatusCode != 204 {
clh.Logger().Errorf("vmAddNetPut failed with error '%d'. Response: %+v", resp.StatusCode, resp)
return fmt.Errorf("Failed to add the network device '%+v' to Cloud Hypervisor: %v", netDevice, resp.StatusCode)
}
Expand Down Expand Up @@ -886,6 +886,15 @@ func (clh *cloudHypervisor) hotPlugVFIODevice(device *config.VFIODev) error {
return err
}

func (clh *cloudHypervisor) hotplugAddNetDevice(e Endpoint) error {
err := clh.addNet(e)
if err != nil {
return err
}

return clh.vmAddNetPut()
}

func (clh *cloudHypervisor) HotplugAddDevice(ctx context.Context, devInfo interface{}, devType DeviceType) (interface{}, error) {
span, _ := katatrace.Trace(ctx, clh.Logger(), "HotplugAddDevice", clhTracingTags, map[string]string{"sandbox_id": clh.id})
defer span.End()
Expand All @@ -897,6 +906,9 @@ func (clh *cloudHypervisor) HotplugAddDevice(ctx context.Context, devInfo interf
case VfioDev:
device := devInfo.(*config.VFIODev)
return nil, clh.hotPlugVFIODevice(device)
case NetDev:
device := devInfo.(Endpoint)
return nil, clh.hotplugAddNetDevice(device)
default:
return nil, fmt.Errorf("cannot hotplug device: unsupported device type '%v'", devType)
}
Expand Down

0 comments on commit 8265aad

Please sign in to comment.