Skip to content

Commit

Permalink
fix: Add timeout for calling cloud-hypervisor api
Browse files Browse the repository at this point in the history
  • Loading branch information
scuzhanglei committed Jan 10, 2023
1 parent 514a8c7 commit d7d5162
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cmd/cloud-hypervisor-client-gen/client.go.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Client) {{name}}(ctx context.Context{{#arg}}, arg {{arg}}{{/arg}}) {{#r
}
{{/arg}}

req, err := http.NewRequest("{{method}}", "http://localhost/api/v1{{path}}", {{#arg}}bytes.NewBuffer(reqBody){{/arg}}{{^arg}}nil{{/arg}})
req, err := http.NewRequestWithContext(ctx, "{{method}}", "http://localhost/api/v1{{path}}", {{#arg}}bytes.NewBuffer(reqBody){{/arg}}{{^arg}}nil{{/arg}})
if err != nil {
return {{#ret}}nil, {{/ret}}fmt.Errorf("build request: %s", err)
}
Expand Down
54 changes: 27 additions & 27 deletions pkg/cloudhypervisor/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/daemon/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ func (r *VMReconciler) reconcile(ctx context.Context, vm *virtv1alpha1.VirtualMa
}
case virtv1alpha1.VirtualMachineMigrationSent:
if vm.Status.Migration.TargetNodeName == r.NodeName {
vmInfo, err := r.getMigrationTargetCloudHypervisorClient(vm).VmInfo(ctx)
timeoutCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel()
vmInfo, err := r.getMigrationTargetCloudHypervisorClient(vm).VmInfo(timeoutCtx)
if err != nil {
return err
}
Expand Down

0 comments on commit d7d5162

Please sign in to comment.