Skip to content

Commit a958fc0

Browse files
committed
✨ Support upstream hcloud-ccm. ProviderID changes to hrobot://NNNN
1 parent ba8c768 commit a958fc0

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

api/v1beta1/hetznerbaremetalmachine_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ const (
6767

6868
// HetznerBareMetalMachineSpec defines the desired state of HetznerBareMetalMachine.
6969
type HetznerBareMetalMachineSpec struct {
70-
// ProviderID will be the hetznerbaremetalmachine which is set by the controller
71-
// in the `hcloud://bm-<server-id>` format.
70+
// ProviderID will be the hetznerbaremetalmachine which is set by the controller in the
71+
// `hrobot://<server-id>` format. Before caph v1.1.0 the ProviderID had the format
72+
// `hcloud://bm-NNNNN`. Starting with caph v1.1.x this was changed to `hrobot://NNNNN`. This
73+
// alligns to the upstream hcloud ccm. In the long run we want discontinue our ccm fork.
7274
// +optional
7375
ProviderID *string `json:"providerID,omitempty"`
7476

controllers/csr_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ func getHbmmWithConstantHostname(ctx context.Context, csrUsername string, cluste
325325
log := ctrl.LoggerFrom(ctx)
326326

327327
clusterFromCSR, serverID := getServerIDFromConstantHostname(ctx, csrUsername, clusterName)
328-
providerID := "hcloud://bm-" + serverID
328+
legacyProviderID := "hcloud://bm-" + serverID
329+
providerID := "hrobot://" + serverID
329330
hList := &infrav1.HetznerBareMetalMachineList{}
330331
selector := labels.NewSelector()
331332
req, err := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Equals, []string{clusterFromCSR})
@@ -348,13 +349,15 @@ func getHbmmWithConstantHostname(ctx context.Context, csrUsername string, cluste
348349
if hList.Items[i].Spec.ProviderID == nil {
349350
continue
350351
}
351-
if *hList.Items[i].Spec.ProviderID == providerID {
352+
if *hList.Items[i].Spec.ProviderID == providerID ||
353+
*hList.Items[i].Spec.ProviderID == legacyProviderID {
352354
hbmm = &hList.Items[i]
353355
break
354356
}
355357
}
358+
356359
if hbmm == nil {
357-
return nil, fmt.Errorf("ProviderID: %q %w", providerID, errNoHetznerBareMetalMachineByProviderIDFound)
360+
return nil, fmt.Errorf("ProviderID: %q (or %q): %w", providerID, legacyProviderID, errNoHetznerBareMetalMachineByProviderIDFound)
358361
}
359362

360363
log.Info("Found HetznerBareMetalMachine with constant hostname", "csr-username", csrUsername, "hetznerBareMetalMachine", hbmm.Name)

docs/caph/02-topics/05-baremetal/03-creating-workload-cluster.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ default my-cluster-control-plane-qwsq6 my-cluster my-cluster-control-pla
124124
default my-cluster-md-0-2xgj5-c5bhc my-cluster my-cluster-md-0-6xttr hcloud://45443694 Running 10h v1.31.6
125125
default my-cluster-md-0-2xgj5-rbnbw my-cluster my-cluster-md-0-fdq9l hcloud://45443693 Running 10h v1.31.6
126126
default my-cluster-md-0-2xgj5-tl2jr my-cluster my-cluster-md-0-59cgw hcloud://45443692 Running 10h v1.31.6
127-
default my-cluster-md-1-cp2fd-7nld7 my-cluster bm-my-cluster-md-1-d7526 hcloud://bm-2317525 Running 9h v1.31.6
128-
default my-cluster-md-1-cp2fd-n74sm my-cluster bm-my-cluster-md-1-l5dnr hcloud://bm-2105469 Running 10h v1.31.6
127+
default my-cluster-md-1-cp2fd-7nld7 my-cluster bm-my-cluster-md-1-d7526 hrobot://2317525 Running 9h v1.31.6
128+
default my-cluster-md-1-cp2fd-n74sm my-cluster bm-my-cluster-md-1-l5dnr hrobot://2105469 Running 10h v1.31.6
129129
```
130130

131-
Please note that hcloud servers are prefixed with `hcloud://` and baremetal servers are prefixed with `hcloud://bm-`.
131+
Please note that hcloud servers are prefixed with `hcloud://` and baremetal servers are prefixed with `hrobot://`.

pkg/services/baremetal/baremetal/baremetal.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ import (
5555
// TODO: Implement logic for removal of unpaid servers.
5656

5757
const (
58-
// providerIDPrefix is a prefix for ProviderID.
59-
providerIDPrefix = "hcloud://"
58+
providerIDPrefix = "hrobot://"
6059

6160
// requeueAfter gives the duration of time until the next reconciliation should be performed.
6261
requeueAfter = time.Second * 30
@@ -900,8 +899,13 @@ func checkForRequeueError(err error, errMessage string) (res reconcile.Result, r
900899
return reconcile.Result{}, fmt.Errorf("%s: %w", errMessage, err)
901900
}
902901

902+
// providerIDFromServerID returns the ProviderID.
903+
// Before caph v1.1.0 the ProviderID had the format `hcloud://bm-NNNNN`.
904+
// Starting with caph v1.1.x this was changed to `hrobot://NNNNN`.
905+
// This alligns to the upstream hcloud ccm. In the long run we want
906+
// discontinue our ccm fork.
903907
func providerIDFromServerID(serverID int) string {
904-
return fmt.Sprintf("%s%s%d", providerIDPrefix, infrav1.BareMetalHostNamePrefix, serverID)
908+
return fmt.Sprintf("%s%d", providerIDPrefix, serverID)
905909
}
906910

907911
func analyzePatchError(err error, ignoreNotFound bool) error {

pkg/services/baremetal/baremetal/baremetal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ var _ = Describe("Test ensureClusterLabel", func() {
703703
})
704704

705705
var _ = Describe("Test providerIDFromServerID", func() {
706-
Expect(providerIDFromServerID(42)).To(Equal("hcloud://bm-42"))
706+
Expect(providerIDFromServerID(42)).To(Equal("hrobot://42"))
707707
})
708708

709709
var _ = Describe("Test hostKey", func() {

pkg/services/hcloud/util/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ func ServerIDFromProviderID(providerID *string) (int64, error) {
5050
if providerID == nil {
5151
return 0, ErrNilProviderID
5252
}
53+
5354
stringParts := strings.Split(*providerID, "://")
5455
if len(stringParts) != 2 || stringParts[0] == "" || stringParts[1] == "" {
5556
return 0, ErrInvalidProviderID
5657
}
58+
59+
if stringParts[0] != "hcloud" {
60+
return 0, ErrInvalidProviderID
61+
}
62+
5763
idString := stringParts[1]
5864
id, err := strconv.ParseInt(idString, 10, 64)
5965
if err != nil {

0 commit comments

Comments
 (0)