-
-
Notifications
You must be signed in to change notification settings - Fork 26
Persistent vm naming #524
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
base: master
Are you sure you want to change the base?
Persistent vm naming #524
Conversation
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.
Sorry forgot about this after #515.
Can it be rebased and updated based on that?
Also I assume AI was used to help with most of this? Not against that, but it generates a ton of useless code comments.
@@ -1,3 +1,4 @@ | |||
trellis-cli | |||
dist | |||
tmp | |||
.DS_Store |
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 should only exist on user's personal global gitignore and not here
// This file provides centralized declarations of functions as variables | ||
// to enable mocking in tests and prevent duplicate implementations. | ||
// Previously, these functions were defined in multiple places, causing | ||
// "redeclared in this block" errors during compilation. |
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 we avoid all these changes for now? This is a whole new pattern that I'm not sure about yet
I'm okay if this limits the testability temporarily
Need to think about this pull request. Also kind of forgot this since last improvement in pull request #515 which got merged. This pull request will add some additional functionality now like
but the vm naming can be set already by adding name to
and yes, did get AI help here and if we go through I would need to clean up stuff some more and remove some user only stuff. |
This pull request introduces several significant changes to the VM management and configuration handling within the Trellis CLI. The most notable updates include the addition of a new instance name management system, the centralization of VM manager creation logic, and the enhancement of testability for VM-related commands.
Key changes:
VM Instance Management:
InstanceName
field toVmConfig
struct incli_config/cli_config.go
to allow custom naming of VM instances.GetVMInstanceName
andSaveVMInstanceName
methods intrellis/vm_instance.go
to manage VM instance names with a priority system.VmStartCommand
to useGetVMInstanceName
for setting the VM name and saving it for future reference. [1] [2]Centralization and Testability:
cmd/main.go
to avoid duplicate implementations and enable easier mocking in tests.newVmManager
function fromcmd/vm.go
and updated references to use the centralized version.Testing Enhancements:
trellis/vm_instance_test.go
.VmDeleteCommand
andVmStartCommand
tests to verify instance file handling and VM name resolution. [1] [2]These changes improve the flexibility, maintainability, and testability of the Trellis CLI's VM management functionality.
VM Instance Name Resolution
The VM creation and start processes now follow a structured approach to determine which instance name to use. This is a significant improvement over the previous implementation which always defaulted to the first site alphabetically.
How VM Name Resolution Works Now
Priority Order for VM Name Resolution
The new code in
trellis/vm_instance.go
implements a priority-based approach:.trellis/lima/instance
fileVM Start Process
When running
trellis vm start
:GetVMInstanceName()
instead of directly usingMainSiteFromEnvironment()
GetVMInstanceName()
first tries to read from the instance fileimagewize.com
), it will use that nameThis ensures that once you've created a VM for a specific site, subsequent vm start commands will consistently use the same VM, rather than creating or starting a different one based on alphabetical order.
VM Creation Process
When creating a new VM:
.trellis/lima/instance
file usingSaveVMInstanceName()
Benefits
This solves your specific issue where vm start was always using "
blocks.imagewize.com
" instead of "imagewize.com
":imagewize.com
, that name is saved in the instance fileblocks.imagewize.com
comes first alphabetically, the saved instance name will be preferredThis provides consistency and predictability when managing VMs across multiple sites in a Trellis project.