-
Notifications
You must be signed in to change notification settings - Fork 37
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: add control loop framework for microvm reconciliation #75
Conversation
3af7628
to
c59c6f2
Compare
The adds the control loop that is used to kick off microvm reconciliation. The actual reconciliation is empty and will be implemented in later changes. This change also introduces a value object `VMID` that i sused to represent the identity of a microvm. Signed-off-by: Richard Case <[email protected]>
c59c6f2
to
251f73a
Compare
@@ -7,7 +7,7 @@ import "github.com/weaveworks/reignite/core/ports" | |||
type App interface { | |||
ports.MicroVMCommandUseCases | |||
ports.MicroVMQueryUseCases | |||
// ports.ReconcileMicroVMsUseCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been uncommented.
core/models/vmid_test.go
Outdated
data, err := json.Marshal(id1) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
t.Logf("marshalled id to %s", string(data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to leave these in, but if you do, %s
will stringify the data, without string(data)
.
There's another one of these below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed these
core/models/microvm.go
Outdated
ID string `json:"id"` | ||
// Namespace is the namespace for the microvm. | ||
Namespace string `json:"namespace"` | ||
ID *VMID `json:"id"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a pointer?
Do you need to be able to differentiate between unset ""
and set to empty string ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using a pointer would be preferable. I could add an Empty
function instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a function to indicate the ID is empty.
) | ||
|
||
// VMID represents the identifier for a microvm. | ||
type VMID struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be an alias for types.NamespacedName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it could but i'm trying not to add any reference to Kubernetes in reignite. Plus i'm not 100% certain that it will stay as ns/name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left this as is.
var name, namespace string | ||
switch v := envelope.Event.(type) { | ||
case *events.MicroVMSpecCreated: | ||
created, _ := envelope.Event.(*events.MicroVMSpecCreated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do this, v
is of the type in the case https://tour.golang.org/methods/16
So, you could simplify this to:
case *events.MicroVMSpecCreated:
name = v.ID
namespace = v.Namespace
I wonder if there's not an interface for Events missing here, maybe with Name()
and Namespace()
or possibly (because namespace/name are indivisible) NamespacedName()
?
With an interface, you wouldn't need the type switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider this and its probably worth thinking about it again. I wasn't sure whether the fields would expand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, it's likely the list of events that will cause a reconciliation will be added to and some will be outside our control (i.e. containerd events).
using v
was more for the default
case but it could be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The v
would let you avoid doing the second type-assertion.
// it will be ignored. | ||
Enqueue(item interface{}) | ||
// Dequeue will get an item from the queue. If there are no items on the queue then it will wait. | ||
Dequeue() (interface{}, bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this accept a timeout or context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dequeue
will wait. However, if Shutdown is called on the queue, then it will cause this to return. As this is based on the client-go workqueue i kept this functionality the same.
Signed-off-by: Richard Case <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with this, I do think the type switch should be tidied up, but it's not broken.
What this PR does / why we need it:
The adds the control loop that is used to kick off microvm reconciliation. The actual reconciliation is empty and will be
implemented in later changes.
This change also introduces a value object
VMID
that is used to represent the identity of a microvm.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #30
Fixes #76
Special notes for your reviewer:
Checklist:
Release note: