diff --git a/api/v1beta1/hetznerbaremetalmachine_types.go b/api/v1beta1/hetznerbaremetalmachine_types.go index a671c9806..cfa3f96d0 100644 --- a/api/v1beta1/hetznerbaremetalmachine_types.go +++ b/api/v1beta1/hetznerbaremetalmachine_types.go @@ -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-` format. + // ProviderID will be the hetznerbaremetalmachine which is set by the controller in the + // `hrobot://` 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"` diff --git a/controllers/csr_controller.go b/controllers/csr_controller.go index 5e5cfd726..1554af7be 100644 --- a/controllers/csr_controller.go +++ b/controllers/csr_controller.go @@ -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}) @@ -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) diff --git a/docs/caph/02-topics/05-baremetal/03-creating-workload-cluster.md b/docs/caph/02-topics/05-baremetal/03-creating-workload-cluster.md index e0811a7a8..0dda41a09 100644 --- a/docs/caph/02-topics/05-baremetal/03-creating-workload-cluster.md +++ b/docs/caph/02-topics/05-baremetal/03-creating-workload-cluster.md @@ -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://`. diff --git a/pkg/services/baremetal/baremetal/baremetal.go b/pkg/services/baremetal/baremetal/baremetal.go index 50a8f9275..8d65a79e8 100644 --- a/pkg/services/baremetal/baremetal/baremetal.go +++ b/pkg/services/baremetal/baremetal/baremetal.go @@ -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 @@ -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 { diff --git a/pkg/services/baremetal/baremetal/baremetal_test.go b/pkg/services/baremetal/baremetal/baremetal_test.go index 6bbb0e20c..709f7b23e 100644 --- a/pkg/services/baremetal/baremetal/baremetal_test.go +++ b/pkg/services/baremetal/baremetal/baremetal_test.go @@ -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() { diff --git a/pkg/services/hcloud/util/utils.go b/pkg/services/hcloud/util/utils.go index 54dc74ada..3b6056108 100644 --- a/pkg/services/hcloud/util/utils.go +++ b/pkg/services/hcloud/util/utils.go @@ -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 {