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

[v1.27][Hetzner] Fix Autoscaling for worker nodes with invalid ProviderID #6722

Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,19 @@ func (m *hetznerManager) addNodeToDrainingPool(node *apiv1.Node) (*hetznerNodeGr
return m.nodeGroups[drainingNodePoolId], nil
}

func (m *hetznerManager) validProviderID(providerID string) bool {
return strings.HasPrefix(providerID, providerIDPrefix)
}

func (m *hetznerManager) serverForNode(node *apiv1.Node) (*hcloud.Server, error) {
var nodeIdOrName string
if node.Spec.ProviderID != "" {
if !m.validProviderID(node.Spec.ProviderID) {
// This cluster-autoscaler provider only handles Hetzner Cloud servers.
// Any other provider ID prefix is invalid, and we return no server. Returning an error here breaks hybrid
// clusters with nodes from Hetzner Cloud & Robot (or other providers).
return nil, nil
}
nodeIdOrName = strings.TrimPrefix(node.Spec.ProviderID, providerIDPrefix)
} else {
nodeIdOrName = node.Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package hetzner

import (
"context"
"errors"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -136,7 +135,8 @@ func (m *serversCache) getServer(nodeIdOrName string) (*hcloud.Server, error) {
}
}

return nil, errors.New("server not found")
// return nil if server not found
return nil, nil
}

func (m *serversCache) getServersByNodeGroupName(nodeGroup string) ([]*hcloud.Server, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestServersCache(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "test2", foundservers.Name)

_, err = c.getServer("test3")
require.Error(t, err)
server, err := c.getServer("test3")
require.Nil(t, server)
require.NoError(t, err)
}
Loading