Skip to content

Commit 25ebf3c

Browse files
authored
🌱 Go Code Update (pre capi v1.11 (beta2)) (#1772)
1 parent 52090eb commit 25ebf3c

19 files changed

Lines changed: 202 additions & 69 deletions

api/v1beta1/conditions_const.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ const (
9999
)
100100

101101
const (
102-
// HostReadyCondition reports on whether the HetznerBareMetalHost is ready or not.
102+
// HostReadyCondition reports on whether the HetznerBareMetalHost is ready or not. The hbmm
103+
// reconciler reads the clusterv1.ReadyCondition condition from the host, and mirrors the Reason
104+
// and Message on the HostReadyCondition of the hbmm.
103105
HostReadyCondition clusterv1.ConditionType = "HostReady"
104106
)
105107

api/v1beta1/hcloudmachine_validation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestValidateHCloudMachineSpecUpdate(t *testing.T) {
4141
args: args{
4242
oldSpec: HCloudMachineSpec{
4343
ImageName: "ubuntu-24.04",
44-
Type: "cpx11",
44+
Type: "cpx22",
4545
},
4646
newSpec: HCloudMachineSpec{
4747
ImageName: "ubuntu-24.04",
@@ -129,13 +129,13 @@ func TestValidateHCloudMachineSpecUpdate(t *testing.T) {
129129
name: "No Errors",
130130
args: args{
131131
oldSpec: HCloudMachineSpec{
132-
Type: "cpx11",
132+
Type: "cpx22",
133133
ImageName: "ubuntu-24.04",
134134
SSHKeys: []SSHKey{{Name: "ssh-key-1"}},
135135
PlacementGroupName: createPlacementGroupName("placement-group-1"),
136136
},
137137
newSpec: HCloudMachineSpec{
138-
Type: "cpx11",
138+
Type: "cpx22",
139139
ImageName: "ubuntu-24.04",
140140
SSHKeys: []SSHKey{{Name: "ssh-key-1"}},
141141
PlacementGroupName: createPlacementGroupName("placement-group-1"),

api/v1beta1/hetznerbaremetalhost_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ type ControllerGeneratedStatus struct {
262262
// +optional
263263
UserData *corev1.SecretReference `json:"userData,omitempty"`
264264

265-
// InstallImage is the configuration that is used for the autosetup configuration for installing an OS via InstallImage.
266-
// +optional
265+
// InstallImage is the configuration that is used for the autosetup configuration for installing
266+
// an OS via InstallImage. The field has an additional usage: When a hbmm gets deleted, then the
267+
// hbmm controller sets this field of the hbmh to nil. This indicates the hbmh controller that
268+
// deprovisioning should started
269+
//
270+
// +optional
267271
InstallImage *InstallImage `json:"installImage,omitempty"`
268272

269273
// StatusHardwareDetails are automatically gathered and should not be modified by the user.

config/crd/bases/infrastructure.cluster.x-k8s.io_hetznerbaremetalhosts.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,11 @@ spec:
355355
needed as some necessary information is stored there, e.g. the hrobot password.
356356
type: string
357357
installImage:
358-
description: InstallImage is the configuration that is used for
359-
the autosetup configuration for installing an OS via InstallImage.
358+
description: |-
359+
InstallImage is the configuration that is used for the autosetup configuration for installing
360+
an OS via InstallImage. The field has an additional usage: When a hbmm gets deleted, then the
361+
hbmm controller sets this field of the hbmh to nil. This indicates the hbmh controller that
362+
deprovisioning should started
360363
properties:
361364
btrfsDefinitions:
362365
description: BTRFSDefinitions define the btrfs subvolume definitions

controllers/controllers_suite_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func TestControllers(t *testing.T) {
7070
}
7171

7272
type ControllerResetter struct {
73+
debug bool
7374
HetznerClusterReconciler *HetznerClusterReconciler
7475
HCloudMachineReconciler *HCloudMachineReconciler
7576
HCloudMachineTemplateReconciler *HCloudMachineTemplateReconciler
@@ -96,6 +97,7 @@ func NewControllerResetter(
9697
HetznerBareMetalMachineReconciler: hetznerBareMetalMachineReconciler,
9798
HCloudRemediationReconciler: hcloudRemediationReconciler,
9899
HetznerBareMetalRemediationReconciler: hetznerBareMetalRemediationReconciler,
100+
debug: os.Getenv("DEBUG") != "",
99101
}
100102
}
101103

@@ -159,6 +161,10 @@ func (r *ControllerResetter) ResetAndInitNamespace(namespace string, testEnv *he
159161
r.HetznerBareMetalMachineReconciler.Namespace = namespace
160162

161163
r.HetznerBareMetalRemediationReconciler.Namespace = namespace
164+
165+
if r.debug {
166+
testEnv.GetLogger().Info("Starting test: ===> ===> ===> ===> ===> ===> ===> " + t.Name())
167+
}
162168
}
163169

164170
var _ = BeforeSuite(func() {

controllers/hcloudmachine_controller_test.go

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

2223
"github.com/hetznercloud/hcloud-go/v2/hcloud"
@@ -346,7 +347,7 @@ var _ = Describe("HCloudMachineReconciler", func() {
346347
},
347348
Spec: infrav1.HCloudMachineSpec{
348349
ImageName: "my-control-plane",
349-
Type: "cpx31",
350+
Type: "cpx32",
350351
PlacementGroupName: &defaultPlacementGroupName,
351352
},
352353
}
@@ -387,9 +388,23 @@ var _ = Describe("HCloudMachineReconciler", func() {
387388

388389
By("checking that bootstrap condition is not ready")
389390

390-
Eventually(func() bool {
391-
return isPresentAndFalseWithReason(key, hcloudMachine, infrav1.BootstrapReadyCondition, infrav1.BootstrapNotReadyReason)
392-
}, timeout, interval).Should(BeTrue())
391+
Eventually(func() error {
392+
err := testEnv.Get(ctx, client.ObjectKeyFromObject(hcloudMachine), hcloudMachine)
393+
if err != nil {
394+
return err
395+
}
396+
c := conditions.Get(hcloudMachine, infrav1.BootstrapReadyCondition)
397+
if c == nil {
398+
return fmt.Errorf("BootstrapReadyCondition not set")
399+
}
400+
if c.Status != corev1.ConditionFalse {
401+
return fmt.Errorf("BootstrapReadyCondition not false")
402+
}
403+
if c.Reason != infrav1.BootstrapNotReadyReason {
404+
return fmt.Errorf("BootstrapNotReadyReason not set. Reason: %q", c.Reason)
405+
}
406+
return nil
407+
}, timeout, interval).Should(Succeed())
393408

394409
By("setting the bootstrap data")
395410

@@ -479,7 +494,7 @@ var _ = Describe("HCloudMachineReconciler", func() {
479494
},
480495
Spec: infrav1.HCloudMachineSpec{
481496
ImageName: "my-control-plane-2",
482-
Type: "cpx31",
497+
Type: "cpx32",
483498
PlacementGroupName: &defaultPlacementGroupName,
484499
},
485500
}
@@ -523,7 +538,7 @@ var _ = Describe("HCloudMachineReconciler", func() {
523538
},
524539
Spec: infrav1.HCloudMachineSpec{
525540
ImageName: "my-control-plane",
526-
Type: "cpx31",
541+
Type: "cpx32",
527542
PlacementGroupName: &defaultPlacementGroupName,
528543
},
529544
}
@@ -613,6 +628,24 @@ var _ = Describe("HCloudMachineReconciler", func() {
613628
EnableIPv6: false,
614629
}
615630
Expect(testEnv.Create(ctx, hetznerCluster)).To(Succeed())
631+
Eventually(func() bool {
632+
var updatedCluster infrav1.HetznerCluster
633+
if err := testEnv.Get(ctx, client.ObjectKeyFromObject(hetznerCluster), &updatedCluster); err != nil {
634+
return false
635+
}
636+
637+
if updatedCluster.Spec.ControlPlaneEndpoint == nil {
638+
return false
639+
}
640+
if updatedCluster.Status.ControlPlaneLoadBalancer == nil {
641+
return false
642+
}
643+
if updatedCluster.Status.ControlPlaneLoadBalancer.IPv4 == "" {
644+
return false
645+
}
646+
647+
return updatedCluster.Spec.ControlPlaneEndpoint.Host == updatedCluster.Status.ControlPlaneLoadBalancer.IPv4
648+
}, timeout, interval).Should(BeTrue())
616649
Expect(testEnv.Create(ctx, hcloudMachine)).To(Succeed())
617650
})
618651

@@ -740,7 +773,7 @@ var _ = Describe("Hetzner secret", func() {
740773
},
741774
Spec: infrav1.HCloudMachineSpec{
742775
ImageName: "my-control-plane",
743-
Type: "cpx31",
776+
Type: "cpx32",
744777
PlacementGroupName: &defaultPlacementGroupName,
745778
},
746779
}
@@ -816,7 +849,7 @@ var _ = Describe("HCloudMachine validation", func() {
816849
},
817850
Spec: infrav1.HCloudMachineSpec{
818851
ImageName: "my-control-plane",
819-
Type: "cpx31",
852+
Type: "cpx32",
820853
},
821854
}
822855
})
@@ -842,7 +875,7 @@ var _ = Describe("HCloudMachine validation", func() {
842875
return testEnv.Client.Get(ctx, key, hcloudMachine)
843876
}, timeout, interval).Should(BeNil())
844877

845-
hcloudMachine.Spec.Type = "cpx32"
878+
hcloudMachine.Spec.Type = "cpx42"
846879
hcloudMachine.Spec.ImageName = "my-control-plane"
847880
Expect(testEnv.Update(ctx, hcloudMachine)).ToNot(Succeed())
848881
})

controllers/hcloudmachinetemplate_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var _ = Describe("HCloudMachineTemplateReconciler", func() {
110110
Template: infrav1.HCloudMachineTemplateResource{
111111
Spec: infrav1.HCloudMachineSpec{
112112
ImageName: "my-control-plane",
113-
Type: "cpx31",
113+
Type: "cpx32",
114114
PlacementGroupName: &defaultPlacementGroupName,
115115
},
116116
},
@@ -187,7 +187,7 @@ var _ = Describe("HCloudMachineTemplateReconciler", func() {
187187
Template: infrav1.HCloudMachineTemplateResource{
188188
Spec: infrav1.HCloudMachineSpec{
189189
ImageName: "my-control-plane",
190-
Type: "cpx31",
190+
Type: "cpx32",
191191
PlacementGroupName: &defaultPlacementGroupName,
192192
},
193193
},

controllers/hcloudremediation_controller_test.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ var _ = Describe("HCloudRemediationReconciler", func() {
151151
},
152152
Spec: infrav1.HCloudMachineSpec{
153153
ImageName: "my-control-plane",
154-
Type: "cpx31",
154+
Type: "cpx32",
155155
},
156156
}
157157
Expect(testEnv.Create(ctx, hcloudMachine)).To(Succeed())
@@ -253,6 +253,9 @@ var _ = Describe("HCloudRemediationReconciler", func() {
253253
if hcloudMachine.Spec.ProviderID == nil {
254254
return fmt.Errorf("hcloudMachine.Spec.ProviderID is still nil")
255255
}
256+
if hcloudMachine.Status.BootState != infrav1.HCloudBootStateOperatingSystemRunning {
257+
return fmt.Errorf("hcloudMachine.Status.BootState is not HCloudBootStateOperatingSystemRunning, but: %q", hcloudMachine.Status.BootState)
258+
}
256259
return nil
257260
}).NotTo(HaveOccurred())
258261

@@ -283,9 +286,12 @@ var _ = Describe("HCloudRemediationReconciler", func() {
283286
if hcloudMachine.Spec.ProviderID == nil {
284287
return fmt.Errorf("hcloudMachine.Spec.ProviderID is still nil")
285288
}
289+
if hcloudMachine.Status.BootState != infrav1.HCloudBootStateOperatingSystemRunning {
290+
return fmt.Errorf("Expected HCloudBootStateOperatingSystemRunning, but: %q",
291+
hcloudMachine.Status.BootState)
292+
}
286293
return nil
287294
}).NotTo(HaveOccurred())
288-
289295
hcloudRemediation.Status.RetryCount = hcloudRemediation.Spec.Strategy.RetryLimit
290296
Expect(testEnv.Create(ctx, hcloudRemediation)).To(Succeed())
291297

@@ -294,7 +300,7 @@ var _ = Describe("HCloudRemediationReconciler", func() {
294300
return err
295301
}
296302
if hcloudRemediation.Status.Phase != infrav1.PhaseWaiting {
297-
return fmt.Errorf("hcloudRemediation.Status.Phase != infrav1.PhaseWaiting (phase is %s)", hcloudRemediation.Status.Phase)
303+
return fmt.Errorf("hcloudRemediation.Status.Phase != infrav1.PhaseWaiting (phase is %q)", hcloudRemediation.Status.Phase)
298304
}
299305
return nil
300306
}, timeout).ShouldNot(HaveOccurred())
@@ -333,10 +339,16 @@ var _ = Describe("HCloudRemediationReconciler", func() {
333339
Name: "myserver",
334340
})
335341
Expect(err).ShouldNot(HaveOccurred())
336-
providerID := hcloudutil.ProviderIDFromServerID(int(server.ID))
337-
hcloudMachine.Spec.ProviderID = &providerID
338-
err = testEnv.Update(ctx, hcloudMachine)
339-
Expect(err).ShouldNot(HaveOccurred())
342+
343+
Eventually(func() error {
344+
err := testEnv.Get(ctx, client.ObjectKeyFromObject(hcloudMachine), hcloudMachine)
345+
if err != nil {
346+
return err
347+
}
348+
providerID := hcloudutil.ProviderIDFromServerID(int(server.ID))
349+
hcloudMachine.Spec.ProviderID = &providerID
350+
return testEnv.Update(ctx, hcloudMachine)
351+
}, timeout).Should(Succeed())
340352

341353
By("Call SetRemediateMachineAnnotationToDeleteMachine")
342354
Eventually(func() error {
@@ -388,6 +400,18 @@ var _ = Describe("HCloudRemediationReconciler", func() {
388400
err = controllerutil.SetOwnerReference(capiMachine, rem, testEnv.GetScheme())
389401
Expect(err).Should(Succeed())
390402

403+
Eventually(func() error {
404+
err := testEnv.Get(ctx, client.ObjectKeyFromObject(hcloudMachine), hcloudMachine)
405+
if err != nil {
406+
return err
407+
}
408+
if hcloudMachine.Status.BootState != infrav1.HCloudBootStateProvisioningFailed {
409+
return fmt.Errorf("Expected HCloudBootStateProvisioningFailed, got %q",
410+
hcloudMachine.Status.BootState)
411+
}
412+
return nil
413+
}, timeout).Should(Succeed())
414+
391415
err = testEnv.Create(ctx, rem)
392416
Expect(err).ShouldNot(HaveOccurred())
393417

controllers/hetznerbaremetalhost_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ func (r *HetznerBareMetalHostReconciler) Reconcile(ctx context.Context, req ctrl
153153
if err != nil {
154154
log.Error(err, "cache sync failed after BootState change")
155155
}
156-
log.Info("Wait for update being in local cache", "durationWaitForLocalCacheSync", time.Since(startReadOwnWrite).Round(time.Millisecond))
156+
if time.Since(startReadOwnWrite) > 50*time.Millisecond {
157+
log.Info("Wait for update being in local cache", "durationWaitForLocalCacheSync", time.Since(startReadOwnWrite).Round(time.Millisecond))
158+
}
157159
}()
158160
// End: avoid conflict errors. Wait until local cache is up-to-date
159161
// ----------------------------------------------------------------

controllers/hetznerbaremetalmachine_controller_test.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223
"testing"
2324
"time"
2425

@@ -660,9 +661,35 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() {
660661
})
661662

662663
It("checks for HostReadyCondition False for hetznerBareMetalMachine with HetznerSecretUnreachableReason", func() {
663-
Eventually(func() bool {
664-
return isPresentAndFalseWithReason(key, bmMachine, infrav1.HostReadyCondition, infrav1.OSSSHSecretMissingReason)
665-
}, timeout, time.Second).Should(BeTrue())
664+
magicString := "could not find OSSSHSecret: failed to fetch secret os-ssh-secret"
665+
Eventually(func() error {
666+
err := testEnv.Get(ctx, client.ObjectKeyFromObject(host), host)
667+
if err != nil {
668+
return err
669+
}
670+
c := conditions.Get(host, clusterv1.ReadyCondition)
671+
if c == nil {
672+
return fmt.Errorf("ReadyCondition not set on host")
673+
}
674+
if !strings.Contains(c.Message, magicString) {
675+
return fmt.Errorf("CredentialsAvailable substring not set (on host). Conditions: %+v", host.Spec.Status.Conditions)
676+
}
677+
err = testEnv.Get(ctx, client.ObjectKeyFromObject(bmMachine), bmMachine)
678+
if err != nil {
679+
return err
680+
}
681+
c = conditions.Get(bmMachine, infrav1.HostReadyCondition)
682+
if c == nil {
683+
return fmt.Errorf("HostReadyCondition not set on hbmm")
684+
}
685+
if c.Reason != infrav1.OSSSHSecretMissingReason {
686+
return fmt.Errorf("%s not set on hbmm. is %q - Conditions: %+v", infrav1.OSSSHSecretMissingReason, c.Reason, bmMachine.Status.Conditions)
687+
}
688+
if !strings.Contains(c.Message, magicString) {
689+
return fmt.Errorf("CredentialsAvailable substring not set (on hbmm). Conditions: %+v", bmMachine.Status.Conditions)
690+
}
691+
return nil
692+
}, timeout, time.Second).Should(Succeed())
666693
})
667694
})
668695
})

0 commit comments

Comments
 (0)