diff --git a/cmd/woodpecker-autoscaler.go b/cmd/woodpecker-autoscaler.go index 21dce45..0091f48 100644 --- a/cmd/woodpecker-autoscaler.go +++ b/cmd/woodpecker-autoscaler.go @@ -59,6 +59,12 @@ func main() { }).Fatal(fmt.Sprintf("Error spawning new agent: %s", err.Error())) } for { + server, err = hetzner.RefreshNodeInfo(cfg, server.ID) + if err != nil { + log.WithFields(log.Fields{ + "Caller": "Main", + }).Fatal(fmt.Sprintf("Failed to start Agent: %s", err.Error())) + } if server.Status == hcloud.ServerStatusRunning { log.WithFields(log.Fields{ "Caller": "Main", diff --git a/internal/hetzner/hetzneragent.go b/internal/hetzner/hetzneragent.go index 5d7c558..6881480 100644 --- a/internal/hetzner/hetzneragent.go +++ b/internal/hetzner/hetzneragent.go @@ -134,3 +134,12 @@ func DecomNode(cfg *config.Config, server *hcloud.Server) error { } return nil } + +func RefreshNodeInfo(cfg *config.Config, serverID int) (*hcloud.Server, error) { + client := hcloud.NewClient(hcloud.WithToken(cfg.HcloudToken)) + server, _, err := client.Server.GetByID(context.Background(), serverID) + if err != nil { + return nil, errors.New(fmt.Sprintf("Could not refresh server info: %s", err.Error())) + } + return server, nil +}