From e304781ba37a04c6b377498f2b3192c8e38a31b6 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Sat, 4 Nov 2023 22:37:09 +0100 Subject: [PATCH] refresh node information --- cmd/woodpecker-autoscaler.go | 6 ++++++ internal/hetzner/hetzneragent.go | 9 +++++++++ 2 files changed, 15 insertions(+) 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 +}