Skip to content
Closed
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
6 changes: 4 additions & 2 deletions api/v1beta1/hetznerbaremetalmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ const (

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

Expand Down
9 changes: 6 additions & 3 deletions controllers/csr_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ func getHbmmWithConstantHostname(ctx context.Context, csrUsername string, cluste
log := ctrl.LoggerFrom(ctx)

clusterFromCSR, serverID := getServerIDFromConstantHostname(ctx, csrUsername, clusterName)
providerID := "hcloud://bm-" + serverID
legacyProviderID := "hcloud://bm-" + serverID
providerID := "hrobot://" + serverID
hList := &infrav1.HetznerBareMetalMachineList{}
selector := labels.NewSelector()
req, err := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Equals, []string{clusterFromCSR})
Expand All @@ -348,13 +349,15 @@ func getHbmmWithConstantHostname(ctx context.Context, csrUsername string, cluste
if hList.Items[i].Spec.ProviderID == nil {
continue
}
if *hList.Items[i].Spec.ProviderID == providerID {
if *hList.Items[i].Spec.ProviderID == providerID ||
*hList.Items[i].Spec.ProviderID == legacyProviderID {
hbmm = &hList.Items[i]
break
}
}

if hbmm == nil {
return nil, fmt.Errorf("ProviderID: %q %w", providerID, errNoHetznerBareMetalMachineByProviderIDFound)
return nil, fmt.Errorf("ProviderID: %q (or %q): %w", providerID, legacyProviderID, errNoHetznerBareMetalMachineByProviderIDFound)
}

log.Info("Found HetznerBareMetalMachine with constant hostname", "csr-username", csrUsername, "hetznerBareMetalMachine", hbmm.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ default my-cluster-control-plane-qwsq6 my-cluster my-cluster-control-pla
default my-cluster-md-0-2xgj5-c5bhc my-cluster my-cluster-md-0-6xttr hcloud://45443694 Running 10h v1.31.6
default my-cluster-md-0-2xgj5-rbnbw my-cluster my-cluster-md-0-fdq9l hcloud://45443693 Running 10h v1.31.6
default my-cluster-md-0-2xgj5-tl2jr my-cluster my-cluster-md-0-59cgw hcloud://45443692 Running 10h v1.31.6
default my-cluster-md-1-cp2fd-7nld7 my-cluster bm-my-cluster-md-1-d7526 hcloud://bm-2317525 Running 9h v1.31.6
default my-cluster-md-1-cp2fd-n74sm my-cluster bm-my-cluster-md-1-l5dnr hcloud://bm-2105469 Running 10h v1.31.6
default my-cluster-md-1-cp2fd-7nld7 my-cluster bm-my-cluster-md-1-d7526 hrobot://2317525 Running 9h v1.31.6
default my-cluster-md-1-cp2fd-n74sm my-cluster bm-my-cluster-md-1-l5dnr hrobot://2105469 Running 10h v1.31.6
```

Please note that hcloud servers are prefixed with `hcloud://` and baremetal servers are prefixed with `hcloud://bm-`.
Please note that hcloud servers are prefixed with `hcloud://` and baremetal servers are prefixed with `hrobot://`.
10 changes: 7 additions & 3 deletions pkg/services/baremetal/baremetal/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ import (
// TODO: Implement logic for removal of unpaid servers.

const (
// providerIDPrefix is a prefix for ProviderID.
providerIDPrefix = "hcloud://"
providerIDPrefix = "hrobot://"

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

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

func analyzePatchError(err error, ignoreNotFound bool) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/baremetal/baremetal/baremetal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ var _ = Describe("Test ensureClusterLabel", func() {
})

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

var _ = Describe("Test hostKey", func() {
Expand Down
6 changes: 6 additions & 0 deletions pkg/services/hcloud/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ func ServerIDFromProviderID(providerID *string) (int64, error) {
if providerID == nil {
return 0, ErrNilProviderID
}

stringParts := strings.Split(*providerID, "://")
if len(stringParts) != 2 || stringParts[0] == "" || stringParts[1] == "" {
return 0, ErrInvalidProviderID
}

if stringParts[0] != "hcloud" {
return 0, ErrInvalidProviderID
}

idString := stringParts[1]
id, err := strconv.ParseInt(idString, 10, 64)
if err != nil {
Expand Down