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: add control loop framework for microvm reconciliation #75

Merged
merged 2 commits into from
Aug 26, 2021

Conversation

richardcase
Copy link
Member

@richardcase richardcase commented Aug 24, 2021

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:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

Release note:

Implement controller host for microvm reconciliation.

@richardcase richardcase added the kind/feature New feature or request label Aug 24, 2021
@richardcase richardcase changed the title wip WIP feat: add control loop framework for microvm reconciliation Aug 24, 2021
@richardcase richardcase force-pushed the control_loop branch 2 times, most recently from 3af7628 to c59c6f2 Compare August 25, 2021 09:53
@richardcase richardcase changed the title WIP feat: add control loop framework for microvm reconciliation feat: add control loop framework for microvm reconciliation Aug 25, 2021
core/models/vmid.go Outdated Show resolved Hide resolved
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]>
cmd/dev-helper/main.go Outdated Show resolved Hide resolved
@@ -7,7 +7,7 @@ import "github.com/weaveworks/reignite/core/ports"
type App interface {
ports.MicroVMCommandUseCases
ports.MicroVMQueryUseCases
// ports.ReconcileMicroVMsUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been uncommented.

data, err := json.Marshal(id1)
Expect(err).NotTo(HaveOccurred())

t.Logf("marshalled id to %s", string(data))

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these

core/models/vmid_test.go Outdated Show resolved Hide resolved
ID string `json:"id"`
// Namespace is the namespace for the microvm.
Namespace string `json:"namespace"`
ID *VMID `json:"id"`

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 "" ?

Copy link
Member Author

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.

Copy link
Member Author

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.

core/ports/usecases.go Show resolved Hide resolved
)

// VMID represents the identifier for a microvm.
type VMID struct {

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 ?

Copy link
Member Author

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

Copy link
Member Author

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)

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

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)

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?

Copy link
Member Author

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.

Copy link

@bigkevmcd bigkevmcd left a 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.

@richardcase richardcase merged commit a1aff98 into main Aug 26, 2021
@richardcase richardcase deleted the control_loop branch August 26, 2021 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a vmid type Create control loop framework
2 participants