Skip to content

Commit d96cb0c

Browse files
authored
docs: differing Robot server name and Node name not supported (#1170)
In the [docs we state](https://github.com/hetznercloud/hcloud-cloud-controller-manager/blob/main/docs/explanation/robot-support.md#identifying-the-correct-serve): > If you absolutely need to use different names in Robot & Hostname, you can also configure the Provider ID yourself. This can be done on the kubelet through the flag [--provider-id](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/). You need to follow the format hrobot://$SERVER_NUMBER when setting this. If this format is not followed exactly we can not process this node. This is actually not supported and changing this would be a breaking change.
1 parent e165984 commit d96cb0c

File tree

5 files changed

+81
-7
lines changed

5 files changed

+81
-7
lines changed

docs/explanation/robot-support.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ When a new Node joins the cluster, we first need to figure out which Robot (or C
5050

5151
_This means that by default, your **Hostname** needs to be the **name of the server in Robot**_. If this does not match, we can not properly match the two entities. Once we have made this connection, we save the Robot Server Number to the field `spec.providerId` on the Node, and use this identifier for any further processing.
5252

53-
If you absolutely need to use different names in Robot & Hostname, you can also configure the Provider ID yourself. This can be done on the `kubelet` through the flag [`--provider-id`](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/). You need to follow the format `hrobot://$SERVER_NUMBER` when setting this. If this format is not followed exactly we can not process this node.
54-
5553
## Credentials
5654

5755
Robot API credentials (`ROBOT_USER` / `ROBOT_PASSWORD`) are **optional**. They control which features are available:

hcloud/instances_util.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ func getRobotServerByID(i *instances, id int, node *corev1.Node) (*hrobotmodels.
111111
return nil, nil
112112
}
113113

114-
// check whether name matches - otherwise this server does not belong to the respective node anymore
114+
// CAPH reuses Robot servers for multiple clusters and therefore the Robot ID does not change, but only
115+
// the name in the Robot API is updated. As the node no longer exists in the cluster with the old name,
116+
// we need to return nil here.
115117
if server.Name != node.Name {
116118
i.recorder.Eventf(
117119
node,
@@ -124,7 +126,6 @@ func getRobotServerByID(i *instances, id int, node *corev1.Node) (*hrobotmodels.
124126
return nil, nil
125127
}
126128

127-
// return nil, nil if server could not be found
128129
return server, nil
129130
}
130131

hcloud/instances_util_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package hcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
hrobotmodels "github.com/syself/hrobot-go/models"
9+
corev1 "k8s.io/api/core/v1"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/client-go/tools/record"
12+
13+
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/mocks"
14+
)
15+
16+
func TestGetRobotServerByID(t *testing.T) {
17+
tests := []struct {
18+
name string
19+
nodeName string
20+
expectedEvent string
21+
}{
22+
{
23+
name: "no diff robot and node name",
24+
nodeName: "foobar",
25+
},
26+
{
27+
name: "diff robot and node name",
28+
nodeName: "barfoo",
29+
expectedEvent: `Warning PossibleNodeDeletion Might be deleted by node-lifecycle-manager due to name mismatch; Node name "barfoo" differs from Robot name "foobar"`,
30+
},
31+
}
32+
33+
for _, tt := range tests {
34+
t.Run(tt.name, func(t *testing.T) {
35+
recorder := record.NewFakeRecorder(1)
36+
37+
robotClientMock := &mocks.RobotClient{}
38+
robotClientMock.Test(t)
39+
robotClientMock.On("ServerGet").Return(&hrobotmodels.Server{ServerNumber: 1, Name: "foobar"}, nil)
40+
41+
inst := &instances{
42+
recorder: recorder,
43+
robotClient: robotClientMock,
44+
}
45+
46+
node := &corev1.Node{
47+
ObjectMeta: metav1.ObjectMeta{
48+
Name: tt.nodeName,
49+
},
50+
}
51+
52+
server, err := getRobotServerByID(inst, 1, node)
53+
require.NoError(t, err)
54+
55+
if tt.expectedEvent != "" {
56+
require.Nil(t, server)
57+
event := <-recorder.Events
58+
assert.Equal(t, tt.expectedEvent, event)
59+
} else {
60+
assert.Equal(t, "foobar", server.Name)
61+
assert.Empty(t, recorder.Events)
62+
}
63+
})
64+
}
65+
}

internal/mocks/casts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func getLoadBalancerPtrS(args mock.Arguments, i int) []*hcloud.LoadBalancer {
3939
return v.([]*hcloud.LoadBalancer)
4040
}
4141

42+
func getRobotServer(args mock.Arguments, i int) *hrobotmodels.Server {
43+
v := args.Get(i)
44+
if v == nil {
45+
return nil
46+
}
47+
return v.(*hrobotmodels.Server)
48+
}
49+
4250
func getRobotServers(args mock.Arguments, i int) []hrobotmodels.Server {
4351
v := args.Get(i)
4452
if v == nil {

internal/mocks/robot.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ type RobotClient struct {
99
mock.Mock
1010
}
1111

12+
func (m *RobotClient) ServerGet(id int) (*hrobotmodels.Server, error) {
13+
args := m.Called()
14+
return getRobotServer(args, 0), args.Error(1)
15+
}
16+
1217
func (m *RobotClient) ServerGetList() ([]hrobotmodels.Server, error) {
1318
args := m.Called()
1419
return getRobotServers(args, 0), args.Error(1)
@@ -62,9 +67,6 @@ func (m *RobotClient) ResetGet(id int) (*hrobotmodels.Reset, error) {
6267
func (m *RobotClient) ResetSet(id int, input *hrobotmodels.ResetSetInput) (*hrobotmodels.ResetPost, error) {
6368
panic("this method should not be called")
6469
}
65-
func (m *RobotClient) ServerGet(id int) (*hrobotmodels.Server, error) {
66-
panic("this method should not be called")
67-
}
6870
func (m *RobotClient) ServerReverse(id int) (*hrobotmodels.Cancellation, error) {
6971
panic("this method should not be called")
7072
}

0 commit comments

Comments
 (0)