pkg/machine/vmconfigs: simplify IsFirstBoot

This is faster and, to my best knowledge, is equivalent to the old code.

Remove the error return (as we don't guarantee stable API here), and
simplify callers.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-03-27 15:23:40 -07:00
parent 490eb476a8
commit a776c1d82a
4 changed files with 5 additions and 23 deletions

View File

@ -216,11 +216,6 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
cmd.Args = append(cmd.Args, endpointArgs...)
firstBoot, err := mc.IsFirstBoot()
if err != nil {
return nil, nil, err
}
if logrus.IsLevelEnabled(logrus.DebugLevel) {
debugDevArgs, err := GetDebugDevicesCMDArgs()
if err != nil {
@ -230,7 +225,7 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
cmd.Args = append(cmd.Args, "--gui") // add command line switch to pop the gui open
}
if firstBoot {
if mc.IsFirstBoot() {
// If this is the first boot of the vm, we need to add the vsock
// device to vfkit so we can inject the ignition file
socketName := fmt.Sprintf("%s-%s", mc.Name, ignitionSocketName)

View File

@ -182,12 +182,7 @@ func (h HyperVStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func(
defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal()
firstBoot, err := mc.IsFirstBoot()
if err != nil {
return nil, nil, err
}
if firstBoot {
if mc.IsFirstBoot() {
// Add ignition entries to windows registry
// for first boot only
if err := readAndSplitIgnition(mc, vm); err != nil {

View File

@ -578,11 +578,7 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
}
}
isFirstBoot, err := mc.IsFirstBoot()
if err != nil {
logrus.Error(err)
}
if mp.VMType() == machineDefine.WSLVirt && mc.Ansible != nil && isFirstBoot {
if mp.VMType() == machineDefine.WSLVirt && mc.Ansible != nil && mc.IsFirstBoot() {
if err := machine.CommonSSHSilent(mc.Ansible.User, mc.SSH.IdentityPath, mc.Name, mc.SSH.Port, []string{"ansible-playbook", mc.Ansible.PlaybookPath}); err != nil {
logrus.Error(err)
}

View File

@ -303,12 +303,8 @@ func (mc *MachineConfig) LogFile() (*define.VMFile, error) {
return rtDir.AppendToNewVMFile(mc.Name+".log", nil)
}
func (mc *MachineConfig) IsFirstBoot() (bool, error) {
never, err := time.Parse(time.RFC3339, "0001-01-01T00:00:00Z")
if err != nil {
return false, err
}
return mc.LastUp == never, nil
func (mc *MachineConfig) IsFirstBoot() bool {
return mc.LastUp.IsZero()
}
func (mc *MachineConfig) ConnectionInfo(vmtype define.VMType) (*define.VMFile, *define.VMFile, error) {