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

neonvm-controller: Add image mapping feature #1236

Closed
wants to merge 1 commit into from
Closed

Conversation

hlinnaka
Copy link
Contributor

@hlinnaka hlinnaka commented Feb 1, 2025

The image map allows quickly overriding image names specified in the VirtualMachine spec. This is for local developmnet, there's currently no intention of using this in production.

I will use this to implement fast reloading of compute images, when you run the console and control plane under Tilt.

Copy link

github-actions bot commented Feb 1, 2025

No changes to the coverage.

HTML Report

Click to open

@hlinnaka hlinnaka force-pushed the heikki/imagemap branch 2 times, most recently from 2dc0fa2 to c7fcda3 Compare February 1, 2025 22:36
@hlinnaka hlinnaka changed the title Add image mapping feature to neonvm-controller neonvm-controller: Add image mapping feature Feb 1, 2025
@hlinnaka hlinnaka marked this pull request as ready for review February 3, 2025 13:23
The image map allows quickly overriding image names specified in the
VirtualMachine spec. This is for local developmnet, there's currently
no intention of using this in production.

I will use this to implement fast reloading of compute images, when
you run the console and control plane under Tilt.
@mikhail-sakhnov
Copy link
Contributor

I am a bit concerned that we already have fields to control images in VM:

- spec.guest.rootDisk.image
- spec.guest.kernelImage
- spec.runnerImage

and now introducing something that overlaps it.

Should it be better instead to introduce a new field like spec.image_live_reload: bool and handle those fields in a controller? What do you think?

For example, in the controller loop we could have a logic (pseudocode)

if spec.image_live_reload == true && anyOfTheImageFieldsHasChanged(vm_from_req, current_vm) { 
  recreatePod()
}

func anyOfTheImageFieldsHasChanged(vm_from_req, current_vm) bool {
// if any of the images in vm_from_req is different from current_vm we trigger pod recreation
}

@hlinnaka
Copy link
Contributor Author

hlinnaka commented Feb 4, 2025

I am a bit concerned that we already have fields to control images in VM:

- spec.guest.rootDisk.image
- spec.guest.kernelImage
- spec.runnerImage

and now introducing something that overlaps it.

Wouldn't say "overlaps". Rather, it provides an extra layer of indirection to it. :-)

Should it be better instead to introduce a new field like spec.image_live_reload: bool and handle those fields in a controller? What do you think?

For example, in the controller loop we could have a logic (pseudocode)

if spec.image_live_reload == true && anyOfTheImageFieldsHasChanged(vm_from_req, current_vm) { 
  recreatePod()
}

func anyOfTheImageFieldsHasChanged(vm_from_req, current_vm) bool {
// if any of the images in vm_from_req is different from current_vm we trigger pod recreation
}

The problem I'm trying to solve with this is that when I hook up Tilt to automatically build the compute image from sources, it uses a different image tag on every build. For example, k3d-neon-local-registry:5000/vm-compute-node-v17:tilt-bce03df2bbb7ad9d. We need to somehow get that image tag to the pods that are created.

What you're proposing with image_live_reload doesn't address that problem. We might want to have that too, i.e. automatically recreate the pod when the image changes, but it's a different issue.

One option would be to modify the the default image tag in the control plane configmap, and restart the control plane. Another would be to update the settings in the control plane db; that's how we deploy images in staging and production. But it's a bit tedious to write a script that would do that as part of a tilt reload.

This PR is a third alternative: Use the original image tag, e.g. neondatabase/vm-compute-node-v17:latest in the control plane, but have this extra mapping that tells neonvm-controller that "when neondatabase/vm-compute-node-v17:latest is requested, actually use k3d-neon-local-registry:5000/vm-compute-node-v17:tilt-bce03df2bbb7ad9d instead". It seemed like the simplest way to accomplish this.

Yet another approach might be to always import the generated k3d-neon-local-registry:5000/vm-compute-node-v17:tilt-bce03df2bbb7ad9d image to the k3d cluster with the same tag, neondatabase/vm-compute-node-v17:latest, overriding the previous image. I think I tried to do that at some point, but it was also a bit ugly: you need to invoke k3d image import from the tiltfile, and it adds another image-copying step which makes it slower.

@sharnoff
Copy link
Member

sharnoff commented Feb 4, 2025

Would it work to re-tag each new image to some consistent tag? e.g. k3d-neon-local-registry:5000/vm-compute-node-v17:tilt-bce03df2bbb7ad9d -> k3d-neon-local-registry:5000/vm-compute-node-v17:latest in the actual local registry (so we're still only copying on-demand, but we don't need substantial changes elsewhere)

We'd also need to set ImagePullPolicy: Always in the VM spec, IIRC

@hlinnaka
Copy link
Contributor Author

hlinnaka commented Feb 4, 2025

Would it work to re-tag each new image to some consistent tag? e.g. k3d-neon-local-registry:5000/vm-compute-node-v17:tilt-bce03df2bbb7ad9d -> k3d-neon-local-registry:5000/vm-compute-node-v17:latest in the actual local registry (so we're still only copying on-demand, but we don't need substantial changes elsewhere)

Hmm, I don't know how to do that. Would need a command that connects to the k3d-neon-local-registry and creates a new tag for the image. I'll google around a bit, but let me know if you have ideas..

@hlinnaka
Copy link
Contributor Author

hlinnaka commented Feb 5, 2025

Ok, I was able to cajole Tilt to use a constant tag, instead of generating a new one every time the image is built. With that, I don't need this PR anymore.

@hlinnaka hlinnaka closed this Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants