func (r *TestResource) ValidateDelete() error {
	testresourcelog.Info("validate delete", "name", r.Name)
	return nil
}
ValidateDelete implements webhook.Validator so a webhook will be registered for the type
package v1
import (
	"fmt"
	"path"
	"k8s.io/apimachinery/pkg/runtime"
	ctrl "sigs.k8s.io/controller-runtime"
	logf "sigs.k8s.io/controller-runtime/pkg/log"
	"sigs.k8s.io/controller-runtime/pkg/webhook"
)
const (
	mountPrefix = "/mnt"
)
var testresourcelog = logf.Log.WithName("testresource-resource")
func (r *TestResource) SetupWebhookWithManager(mgr ctrl.Manager) error {
	return ctrl.NewWebhookManagedBy(mgr).
		For(r).
		Complete()
}
var _ webhook.Defaulter = &TestResource{}
func (r *TestResource) Default() {
	testresourcelog.Info("default", "name", r.Name)
	for name, disk := range r.Spec.Disks {
		if disk.MountPath == "" {
			disk.MountPath = path.Join(mountPrefix, name)
		}
		if disk.Size == "" {
			disk.Size = disk.Size.Zero()
		}
		r.Spec.Disks[name] = disk
	}
}
var _ webhook.Validator = &TestResource{}
func (r *TestResourceSpec) ValidateCreate() error {
	if _, err := r.Memory.ToSize(); err != nil {
		return fmt.Errorf("invalid memory size: %s", err.Error())
	}
	for _, disk := range r.Disks {
		if _, err := disk.Size.ToSize(); disk.Size != "" && err != nil {
			return fmt.Errorf("invalid disk size: %s", err.Error())
		}
	}
	return nil
}
func (r *TestResource) ValidateCreate() error {
	testresourcelog.Info("validate create", "name", r.Name)
	return r.Spec.ValidateCreate()
}
func (r *TestResource) ValidateUpdate(old runtime.Object) error {
	testresourcelog.Info("validate update", "name", r.Name)
	return nil
}