From b20e879dbd787bb4f5bc36a29a974007e3d2d4fb Mon Sep 17 00:00:00 2001 From: janiskemper <63146658+janiskemper@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:49:31 +0200 Subject: [PATCH] :seedling: Remove HetznerBareMetalMachineTemplate create webhook (#1393) * :seedling: Remove HetznerBareMetalMachineTemplate create webhook We have to remove it as it is currently incapable of working with the CLusterClass. * :bug: Fix previous commit to properly remove webhook In the previous commit we updated the update webhook but should have updated the create webhook. This is done here now. --- ...hetznerbaremetalmachinetemplate_webhook.go | 6 +-- ...hetznerbaremetalmachine_controller_test.go | 43 ------------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/api/v1beta1/hetznerbaremetalmachinetemplate_webhook.go b/api/v1beta1/hetznerbaremetalmachinetemplate_webhook.go index 21166c43b..d787de407 100644 --- a/api/v1beta1/hetznerbaremetalmachinetemplate_webhook.go +++ b/api/v1beta1/hetznerbaremetalmachinetemplate_webhook.go @@ -57,9 +57,9 @@ func (r *HetznerBareMetalMachineTemplateWebhook) ValidateCreate(_ context.Contex hbmmt.Spec.Template.Spec.SSHSpec.PortAfterCloudInit = hbmmt.Spec.Template.Spec.SSHSpec.PortAfterInstallImage } - allErrs := validateHetznerBareMetalMachineSpecCreate(hbmmt.Spec.Template.Spec) - - return nil, aggregateObjErrors(hbmmt.GroupVersionKind().GroupKind(), hbmmt.Name, allErrs) + // TODO: Cannot validate it because ClusterClass applies empty template objects + // allErrs := validateHetznerBareMetalMachineSpecCreate(hbmmt.Spec.Template.Spec) + return nil, nil } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. diff --git a/controllers/hetznerbaremetalmachine_controller_test.go b/controllers/hetznerbaremetalmachine_controller_test.go index 852c1621a..e249c0ab7 100644 --- a/controllers/hetznerbaremetalmachine_controller_test.go +++ b/controllers/hetznerbaremetalmachine_controller_test.go @@ -710,43 +710,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() { }) }) - Context("validate create", func() { - var ( - hbmmt *infrav1.HetznerBareMetalMachineTemplate - testNs *corev1.Namespace - ) - BeforeEach(func() { - var err error - testNs, err = testEnv.CreateNamespace(ctx, "hcloudmachine-validation") - Expect(err).NotTo(HaveOccurred()) - - hbmmt = &infrav1.HetznerBareMetalMachineTemplate{ - ObjectMeta: metav1.ObjectMeta{ - Name: bmMachineName, - Namespace: testNs.Name, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: capiCluster.Name, - }, - }, - Spec: infrav1.HetznerBareMetalMachineTemplateSpec{ - Template: infrav1.HetznerBareMetalMachineTemplateResource{ - Spec: getDefaultHetznerBareMetalMachineSpec(), - }, - }, - } - - }) - - AfterEach(func() { - Expect(testEnv.Cleanup(ctx, testNs, hbmmt)).To(Succeed()) - }) - - It("should allow creation of hbmmt", func() { - Expect(testEnv.Create(ctx, hbmmt)).To(Succeed()) - }) - - }) - Context("validate update", func() { var ( hbmmt *infrav1.HetznerBareMetalMachineTemplate @@ -777,7 +740,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() { Eventually(func() error { return testEnv.Client.Get(ctx, key, hbmmt) }, timeout, time.Second).Should(BeNil()) - }) AfterEach(func() { @@ -807,7 +769,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() { }, } Expect(testEnv.Client.Update(ctx, hbmmt)).ToNot(Succeed()) - }) It("should not allow update of SSHSpec", func() { @@ -832,7 +793,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() { }, } Expect(testEnv.Client.Update(ctx, hbmmt)).ToNot(Succeed()) - }) It("should not allow update of Host Selectors", func() { @@ -857,7 +817,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() { }, } Expect(testEnv.Client.Update(ctx, hbmmt)).ToNot(Succeed()) - }) It("should allow update of mutable fields", func() { @@ -868,9 +827,7 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() { } hbmmt.ObjectMeta.Annotations["test"] = "should_succeed" Expect(testEnv.Client.Update(ctx, hbmmt)).To(Succeed()) - }) - }) }) })