Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hetzner: search for not_found code explicitly before returning ErrInstanceNotFound #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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, errReadResponse := io.ReadAll(msg.Response.Body)
msgStr := string(msgBytes)
if errReadResponse == nil && strings.Contains(msgStr, "not_found") {
logger.WithError(err).
Debugln("instance does not exist")
return autoscaler.ErrInstanceNotFound
Expand Down