Skip to content

Commit a776c1d

Browse files
committed
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 <[email protected]>
1 parent 490eb47 commit a776c1d

File tree

4 files changed

+5
-23
lines changed

4 files changed

+5
-23
lines changed

pkg/machine/apple/apple.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,6 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
216216

217217
cmd.Args = append(cmd.Args, endpointArgs...)
218218

219-
firstBoot, err := mc.IsFirstBoot()
220-
if err != nil {
221-
return nil, nil, err
222-
}
223-
224219
if logrus.IsLevelEnabled(logrus.DebugLevel) {
225220
debugDevArgs, err := GetDebugDevicesCMDArgs()
226221
if err != nil {
@@ -230,7 +225,7 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
230225
cmd.Args = append(cmd.Args, "--gui") // add command line switch to pop the gui open
231226
}
232227

233-
if firstBoot {
228+
if mc.IsFirstBoot() {
234229
// If this is the first boot of the vm, we need to add the vsock
235230
// device to vfkit so we can inject the ignition file
236231
socketName := fmt.Sprintf("%s-%s", mc.Name, ignitionSocketName)

pkg/machine/hyperv/stubber.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ func (h HyperVStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func(
182182
defer callbackFuncs.CleanIfErr(&err)
183183
go callbackFuncs.CleanOnSignal()
184184

185-
firstBoot, err := mc.IsFirstBoot()
186-
if err != nil {
187-
return nil, nil, err
188-
}
189-
190-
if firstBoot {
185+
if mc.IsFirstBoot() {
191186
// Add ignition entries to windows registry
192187
// for first boot only
193188
if err := readAndSplitIgnition(mc, vm); err != nil {

pkg/machine/shim/host.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,7 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
578578
}
579579
}
580580

581-
isFirstBoot, err := mc.IsFirstBoot()
582-
if err != nil {
583-
logrus.Error(err)
584-
}
585-
if mp.VMType() == machineDefine.WSLVirt && mc.Ansible != nil && isFirstBoot {
581+
if mp.VMType() == machineDefine.WSLVirt && mc.Ansible != nil && mc.IsFirstBoot() {
586582
if err := machine.CommonSSHSilent(mc.Ansible.User, mc.SSH.IdentityPath, mc.Name, mc.SSH.Port, []string{"ansible-playbook", mc.Ansible.PlaybookPath}); err != nil {
587583
logrus.Error(err)
588584
}

pkg/machine/vmconfigs/machine.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,8 @@ func (mc *MachineConfig) LogFile() (*define.VMFile, error) {
303303
return rtDir.AppendToNewVMFile(mc.Name+".log", nil)
304304
}
305305

306-
func (mc *MachineConfig) IsFirstBoot() (bool, error) {
307-
never, err := time.Parse(time.RFC3339, "0001-01-01T00:00:00Z")
308-
if err != nil {
309-
return false, err
310-
}
311-
return mc.LastUp == never, nil
306+
func (mc *MachineConfig) IsFirstBoot() bool {
307+
return mc.LastUp.IsZero()
312308
}
313309

314310
func (mc *MachineConfig) ConnectionInfo(vmtype define.VMType) (*define.VMFile, *define.VMFile, error) {

0 commit comments

Comments
 (0)