@@ -17,13 +17,13 @@ limitations under the License.
1717package v1beta1
1818
1919import (
20+ "context"
2021 "reflect"
2122
2223 apierrors "k8s.io/apimachinery/pkg/api/errors"
2324 "k8s.io/apimachinery/pkg/runtime"
2425 "k8s.io/apimachinery/pkg/util/validation/field"
2526 ctrl "sigs.k8s.io/controller-runtime"
26- "sigs.k8s.io/controller-runtime/pkg/webhook"
2727 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2828)
2929
@@ -34,28 +34,27 @@ const AzureClusterTemplateImmutableMsg = "AzureClusterTemplate spec.template.spe
3434func (c * AzureClusterTemplate ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
3535 return ctrl .NewWebhookManagedBy (mgr ).
3636 For (c ).
37+ WithDefaulter (& AzureClusterTemplate {}).
38+ WithValidator (& AzureClusterTemplate {}).
3739 Complete ()
3840}
3941
4042// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azureclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclustertemplates,versions=v1beta1,name=validation.azureclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4143// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-azureclustertemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclustertemplates,versions=v1beta1,name=default.azureclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4244
43- var _ webhook.Defaulter = & AzureClusterTemplate {}
44-
4545// Default implements webhook.Defaulter so a webhook will be registered for the type.
46- func (c * AzureClusterTemplate ) Default () {
46+ func (c * AzureClusterTemplate ) Default (ctx context. Context , obj runtime. Object ) error {
4747 c .setDefaults ()
48+ return nil
4849}
4950
50- var _ webhook.Validator = & AzureClusterTemplate {}
51-
5251// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
53- func (c * AzureClusterTemplate ) ValidateCreate () (admission.Warnings , error ) {
52+ func (c * AzureClusterTemplate ) ValidateCreate (ctx context. Context , obj runtime. Object ) (admission.Warnings , error ) {
5453 return c .validateClusterTemplate ()
5554}
5655
5756// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
58- func (c * AzureClusterTemplate ) ValidateUpdate (oldRaw runtime.Object ) (admission.Warnings , error ) {
57+ func (c * AzureClusterTemplate ) ValidateUpdate (ctx context. Context , obj runtime. Object , oldRaw runtime.Object ) (admission.Warnings , error ) {
5958 var allErrs field.ErrorList
6059 old := oldRaw .(* AzureClusterTemplate )
6160 if ! reflect .DeepEqual (c .Spec .Template .Spec , old .Spec .Template .Spec ) {
@@ -71,6 +70,6 @@ func (c *AzureClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.
7170}
7271
7372// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
74- func (c * AzureClusterTemplate ) ValidateDelete () (admission.Warnings , error ) {
73+ func (c * AzureClusterTemplate ) ValidateDelete (ctx context. Context , obj runtime. Object ) (admission.Warnings , error ) {
7574 return nil , nil
7675}
0 commit comments