crc-org / vfkit

Apache License 2.0
123 stars 24 forks source link

feat(rest): add can* params in `GET /vm/state` #63

Closed BlackHole1 closed 10 months ago

BlackHole1 commented 10 months ago

In the previous API, there was no way to detect before changing the status, which would make it difficult for developers to handle the following situations:

  1. When the virtual machine status is Stop, calling Pause may fail.
  2. When the virtual machine status is Pause, setting the status to Pause again may fail.

In the previous solution, developers needed to first get the current status of the virtual machine and then decide whether to proceed to the next step. However, the current virtual machine status is very diverse (see: https://github.com/Code-Hex/vz/blob/bd29a7ea3d39465c4224bfb01e990e8c220a8449/virtualization.go#L23), which would require developers to handle various cases perfectly. This PR solves this problem.

openshift-ci[bot] commented 10 months ago

Hi @BlackHole1. Thanks for your PR.

I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
praveenkumar commented 10 months ago

/ok-to-test

cfergeau commented 10 months ago

developers needed to first get the current status of the virtual machine and then decide whether to proceed to the next step.

One minor comment, such an API will be racy, the VM state can change between the canXXX query and the change state query.

I'm not sure /vm/can/:state is the best API for this, maybe this could be added to /vm/state?

{"state": "string", "canStop": "true", "canPause": "false", "canForceStop": "true", "canResume": "..."}

Or when changing state, we could use different errors for "the operation is impossible in this state" and "there was an error when performing the operation"?

BlackHole1 commented 10 months ago

One minor comment, such an API will be racy, the VM state can change between the canXXX query and the change state query.

Good catch! I have changed the code.

BlackHole1 commented 10 months ago

@cfergeau Done

cfergeau commented 10 months ago

@cfergeau Done

I've squashed all commits to a single one, and copied the PR description to the commit, and force-pushed to your feat-can branch, I hope that's fine with you!

cfergeau commented 10 months ago

/lgtm

(I'll approve after CI runs)

BlackHole1 commented 10 months ago

@cfergeau Done

I've squashed all commits to a single one, and copied the PR description to the commit, and force-pushed to your feat-can branch, I hope that's fine with you!

NP. In the future, I will pay attention to this when I submit a PR.

cfergeau commented 10 months ago

NP. In the future, I will pay attention to this when I submit a PR.

The expectations vary between projects, I don't mind doing the adjustments. I did it myself to avoid additional back & forth

cfergeau commented 10 months ago

/approve

openshift-ci[bot] commented 10 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfergeau

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/crc-org/vfkit/blob/main/OWNERS)~~ [cfergeau] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment