crc
crc copied to clipboard
Add status change event
Solution/Idea
PR adds event API and new SSE(server sent event) channel status_change
.
Proposed changes
PR adds event API implementation in pkg/crc/api/events/events.go
Modify sync
client implementation to trigger event when status is changed.
Fixes in existing log events, rename constants related to SSE
Testing
- launch demon
- connect to
status_change
channel withcurl -GET -i --unix-socket <path to socket>/crc-http.sock "http://localhost/events?stream=status_change"
- start crc with
curl -GET -i --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
- Ensure that new events appeared, like:
id: │
data: {"status":{"CrcStatus":"Starting","OpenshiftStatus":"Starting","OpenshiftVersion":"","PodmanVersion":"","DiskUse":0,"DiskSize":0,"RAMUse":0,"RAMSize":0,"Preset":"microshift"}}
event: status_change
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please ask for approval from evidolob. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve
in a comment
Approvers can cancel approval by writing /approve cancel
in a comment
/retest
- connect to status_change channel with curl -GET -i --unix-socket
/crc-http.sock "http://localhost/events?stream=status_change" - start crc with crc start
the events are shown only when starting via the api curl --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
running the crc start
command the events are not shown, is this expected?
the events are shown only when starting via the api
curl --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
running thecrc start
command the events are not shown, is this expected?
Yes, that is expected, as start
, stop
is performed on CLI side, not on daemon, at least for now.
Tested locally and functionality is working as expected, LGTM. it'd be nice to have more detailed commit messages explaining the changes in each commit
/need-rebase
I've rebased it at https://github.com/cfergeau/crc/tree/stus-change-event and added a fixup commit to fix compliation of the first commit in the series.
I'm not sure step 3. is correct in the testing instructions:
- start crc with crc start
Don't we need to start it with the REST API for now as otherwise start
won't get through the daemon?
curl -GET -i --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
I was wondering if curl -GET -i --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
should also send a status event to help with syncing state if the state change behind the daemon's back?
Don't we need to start it with the REST API for now as otherwise
start
won't get through the daemon?
Yes, you are correct, need to start with rest API.
curl -GET -i --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
I was wondering if
curl -GET -i --unix-socket ~/.crc/crc-http.sock "http://localhost/api/start"
should also send a status event to help with syncing state if the state change behind the daemon's back?
Daemon send response only after start is finished(or error incase of any error), but calling api/start
will trigger events on events?stream=status_change
event channel.
Few more things I noticed during testing, if VM exists, and then I call delete
, I get
id:
data: {"status":{"CrcStatus":"Error","OpenshiftStatus":"","OpenshiftVersion":"","PodmanVersion":"","DiskUse":0,"DiskSize":0,"RAMUse":0,"RAMSize":0,"Preset":""},"error":"Cannot load 'crc' virtual machine: no such libmachine vm: crc"}
event: status_change
which does not seem correct as the VM existed before being deleted.
After that, if I call again delete
I don't get any notifications. If I call stop
, I get first stopping
and then error
Probably something that can improve with the NoVM
state.
Few more things I noticed during testing, if VM exists, and then I call
delete
, I getid: data: {"status":{"CrcStatus":"Error","OpenshiftStatus":"","OpenshiftVersion":"","PodmanVersion":"","DiskUse":0,"DiskSize":0,"RAMUse":0,"RAMSize":0,"Preset":""},"error":"Cannot load 'crc' virtual machine: no such libmachine vm: crc"} event: status_change
which does not seem correct as the VM existed before being deleted. After that, if I call again
delete
I don't get any notifications. If I callstop
, I get firststopping
and thenerror
That was actually bug, status
was not report NoVm
state, only error. (It was due to not implementing Is
method for MissingHostError
, so comparing error was always wrong)
Now it should work properly.
What is holding back this PR?
What is holding back this PR?
Some discussion around https://github.com/crc-org/crc/pull/3903#discussion_r1476130780 would have been useful
Apart from this, as said multiple times, the comit log must be a lot more detailed about how this works:
If we don't record this knowledge now when it's more or less fresh in our minds, it will be very difficult to find this back in 6 months from now if we need it :-/
I'd say we can go with this for now, more details about the design choices, the implementation limitations, ... (this sentence is malformed though :-/ )
And https://github.com/crc-org/crc/pull/3903#discussion_r1474772073 is also still pending
@cfergeau Could you look on this?
@evidolob: The following test failed, say /retest
to rerun all failed tests or /retest-required
to rerun all mandatory failed tests:
Test name | Commit | Details | Required | Rerun command |
---|---|---|---|---|
ci/prow/security | 66237fa488efcb61403c07f015cbfd789fdc33b8 | link | false | /test security |
Full PR test history. Your PR dashboard.
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-sigs/prow repository. I understand the commands that are listed here.