File tree Expand file tree Collapse file tree
cmd/docker-machine-driver-pve/driver Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,9 +4,11 @@ import (
44 "context"
55 "errors"
66 "fmt"
7+ "math/rand"
78 "net"
89 "slices"
910 "strings"
11+ "time"
1012
1113 "github.com/luthermonson/go-proxmox"
1214 "github.com/rancher/machine/libmachine/drivers"
@@ -103,16 +105,34 @@ func (d *Driver) Create() error {
103105
104106 log .Info ("Creating the machine..." )
105107
106- vmid , err := d .createPVEVirtualMachine (context .TODO ())
107- if err != nil {
108- if vmid > 0 {
109- log .Warn ("Machine might have been created with ID='%d'" , vmid )
108+ retryBackoff := 1 // seconds
109+
110+ for {
111+ vmid , err := d .createPVEVirtualMachine (context .TODO ())
112+ if err != nil {
113+ if strings .Contains (err .Error (), "config file already exists" ) {
114+ log .Warn ("Hit ID conflict when cloning the machine, will retry..." )
115+
116+ //nolint:gosec // Weak number generator is good enough for this case
117+ <- time .After (time .Duration (retryBackoff + rand .Intn (retryBackoff )) * time .Second )
118+
119+ // Double the backoff for next iteration
120+ retryBackoff *= 2
121+
122+ continue
123+ }
124+
125+ if vmid > 0 {
126+ log .Warnf ("Machine might have been created with ID='%d'" , vmid )
127+ }
128+
129+ return fmt .Errorf ("failed to create machine: %w" , err )
110130 }
111131
112- return fmt .Errorf ("failed to create machine: %w" , err )
113- }
132+ d .PVEMachineID = & vmid
114133
115- d .PVEMachineID = & vmid
134+ break
135+ }
116136
117137 if err := d .initialize (); err != nil {
118138 if removeErr := d .Remove (); removeErr != nil {
You can’t perform that action at this time.
0 commit comments