Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions drivers/hetznercloud/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package hetznercloud

import (
"context"
"io"
"strconv"
"strings"

"github.com/drone/autoscaler"
"github.com/drone/autoscaler/logger"
Expand All @@ -28,10 +30,13 @@ func (p *provider) Destroy(ctx context.Context, instance *autoscaler.Instance) e

logger.Debugln("deleting instance")

_, err = p.client.Server.Delete(ctx, &hcloud.Server{ID: id})
msg, err := p.client.Server.Delete(ctx, &hcloud.Server{ID: id})

if err != nil {
if err.Error() == "hcloud: server responded with status code 404" {
// json response contains a code=not_found field
msgBytes, err2 := io.ReadAll(msg.Response.Body)
msgStr := string(msgBytes)
if err2 == nil && strings.Contains(msgStr, "not_found") {
logger.WithError(err).
Debugln("instance does not exist")
return autoscaler.ErrInstanceNotFound
Expand Down