Skip to content
Snippets Groups Projects
Unverified Commit 89504ed9 authored by Jonas Stoehr's avatar Jonas Stoehr Committed by GitHub
Browse files

Merge pull request #98 from mookie-/master

feat: configurable sleep after failing to create server
parents 78a8111a 663e59d8
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,8 @@ type Driver struct { ...@@ -58,6 +58,8 @@ type Driver struct {
AdditionalKeys []string AdditionalKeys []string
AdditionalKeyIDs []int AdditionalKeyIDs []int
cachedAdditionalKeys []*hcloud.SSHKey cachedAdditionalKeys []*hcloud.SSHKey
WaitOnError int
} }
const ( const (
...@@ -99,6 +101,9 @@ const ( ...@@ -99,6 +101,9 @@ const (
defaultSSHPort = 22 defaultSSHPort = 22
defaultSSHUser = "root" defaultSSHUser = "root"
flagWaitOnError = "wait-on-error"
defaultWaitOnError = 0
) )
// NewDriver initializes a new driver instance; see [drivers.Driver.NewDriver] // NewDriver initializes a new driver instance; see [drivers.Driver.NewDriver]
...@@ -261,6 +266,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { ...@@ -261,6 +266,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "SSH port", Usage: "SSH port",
Value: defaultSSHPort, Value: defaultSSHPort,
}, },
mcnflag.IntFlag{
EnvVar: "WAIT_ON_ERROR",
Name: flagWaitOnError,
Usage: "Wait if an error happens while creating the server",
Value: defaultWaitOnError,
},
} }
} }
...@@ -295,6 +306,8 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error { ...@@ -295,6 +306,8 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
d.SSHUser = opts.String(flagSshUser) d.SSHUser = opts.String(flagSshUser)
d.SSHPort = opts.Int(flagSshPort) d.SSHPort = opts.Int(flagSshPort)
d.WaitOnError = opts.Int(flagWaitOnError)
d.placementGroup = opts.String(flagPlacementGroup) d.placementGroup = opts.String(flagPlacementGroup)
if opts.Bool(flagAutoSpread) { if opts.Bool(flagAutoSpread) {
if d.placementGroup != "" { if d.placementGroup != "" {
...@@ -450,6 +463,7 @@ func (d *Driver) Create() error { ...@@ -450,6 +463,7 @@ func (d *Driver) Create() error {
srv, _, err := d.getClient().Server.Create(context.Background(), instrumented(*srvopts)) srv, _, err := d.getClient().Server.Create(context.Background(), instrumented(*srvopts))
if err != nil { if err != nil {
time.Sleep(time.Duration(d.WaitOnError) * time.Second)
return errors.Wrap(err, "could not create server") return errors.Wrap(err, "could not create server")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment