Skip to content

Commit 0db3f80

Browse files
committed
mapNodeToServerID: strip any provider prefix #32962
previously we only stripped the brightbox:// prefix but would then go on to try use any other providerIDs with the api. So instead, strip all provider prefixes and trust the Brightbox API to be the authority on what is a brightbox server and what is not. This fixes using the provider with k3s, which uses a k3s:// provider prefix, but should also work for future prefixes.
1 parent 4151eaa commit 0db3f80

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

brightbox/util.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ func mapNodeToServerID(node *v1.Node) string {
8787
if node.Spec.ProviderID == "" {
8888
return node.Name
8989
}
90-
return k8ssdk.MapProviderIDToServerID(node.Spec.ProviderID)
90+
91+
parts := strings.SplitN(node.Spec.ProviderID, "://", 2)
92+
93+
if len(parts) == 2 {
94+
// some providers have 3 forward slashes so handle that
95+
return strings.TrimPrefix(parts[1], "/")
96+
}
97+
98+
return parts[0]
9199
}
92100

93101
func mapServerIDToNode(name string) *v1.Node {

brightbox/util_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ func TestMapNodeToServerID(t *testing.T) {
9191
if serverID != expected {
9292
t.Errorf("Expected ServerID to be '%s', got '%s'", expected, serverID)
9393
}
94+
node = &v1.Node{Spec: v1.NodeSpec{ProviderID: "k3s://server789"}}
95+
serverID = mapNodeToServerID(node)
96+
expected = "server789"
97+
if serverID != expected {
98+
t.Errorf("Expected ServerID to be '%s', got '%s'", expected, serverID)
99+
}
100+
node = &v1.Node{Spec: v1.NodeSpec{ProviderID: "", Name: "server789"}}
101+
serverID = mapNodeToServerID(node)
102+
expected = "server789"
103+
if serverID != expected {
104+
t.Errorf("Expected ServerID to be '%s', got '%s'", expected, serverID)
105+
}
94106
}
95107

96108
// TestMapServerIDToNode verifies that a ServerID is correctly mapped to a Node with that ID as name

0 commit comments

Comments
 (0)