Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

BlackHole1
Copy link
Contributor

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
Copy link

openshift-ci bot commented Oct 25, 2023

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. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@praveenkumar
Copy link
Member

/ok-to-test

@cfergeau
Copy link
Collaborator

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
Copy link
Contributor Author

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 BlackHole1 changed the title feat(rest): support check status can be change feat(rest): add can* params in GET /vm/state Oct 27, 2023
pkg/rest/vf/state_change.go Outdated Show resolved Hide resolved
pkg/rest/vf/vm_config.go Show resolved Hide resolved
@BlackHole1
Copy link
Contributor Author

@cfergeau Done

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:

    - When the virtual machine status is Stop, calling Pause may fail.
    - 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.
@cfergeau
Copy link
Collaborator

@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
Copy link
Collaborator

/lgtm

(I'll approve after CI runs)

@BlackHole1
Copy link
Contributor Author

@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
Copy link
Collaborator

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
Copy link
Collaborator

/approve

@openshift-ci
Copy link

openshift-ci bot commented Oct 27, 2023

[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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cfergeau cfergeau merged commit bf93e84 into crc-org:main Oct 27, 2023
4 of 5 checks passed
@BlackHole1 BlackHole1 deleted the feat-can branch October 27, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants