Skip to content

Commit

Permalink
🌱 Remove HetznerBareMetalMachineTemplate create webhook (#1393)
Browse files Browse the repository at this point in the history
* 🌱 Remove HetznerBareMetalMachineTemplate create webhook

We have to remove it as it is currently incapable of working with the
CLusterClass.

* 🐛 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.
  • Loading branch information
janiskemper committed Jul 24, 2024
1 parent b9b1f9c commit b20e879
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 46 deletions.
6 changes: 3 additions & 3 deletions api/v1beta1/hetznerbaremetalmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 0 additions & 43 deletions controllers/hetznerbaremetalmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -807,7 +769,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() {
},
}
Expect(testEnv.Client.Update(ctx, hbmmt)).ToNot(Succeed())

})

It("should not allow update of SSHSpec", func() {
Expand All @@ -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() {
Expand All @@ -857,7 +817,6 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() {
},
}
Expect(testEnv.Client.Update(ctx, hbmmt)).ToNot(Succeed())

})

It("should allow update of mutable fields", func() {
Expand All @@ -868,9 +827,7 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() {
}
hbmmt.ObjectMeta.Annotations["test"] = "should_succeed"
Expect(testEnv.Client.Update(ctx, hbmmt)).To(Succeed())

})

})
})
})

0 comments on commit b20e879

Please sign in to comment.