@@ -28,6 +28,7 @@ import (
2828 ctrl "sigs.k8s.io/controller-runtime"
2929 logf "sigs.k8s.io/controller-runtime/pkg/log"
3030 "sigs.k8s.io/controller-runtime/pkg/webhook"
31+ "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3132)
3233
3334// log is for logging in this package.
@@ -54,7 +55,7 @@ func (r *CloudStackMachineTemplate) Default() {
5455var _ webhook.Validator = & CloudStackMachineTemplate {}
5556
5657// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
57- func (r * CloudStackMachineTemplate ) ValidateCreate () error {
58+ func (r * CloudStackMachineTemplate ) ValidateCreate () (admission. Warnings , error ) {
5859 cloudstackmachinetemplatelog .V (1 ).Info ("entered validate create webhook" , "api resource name" , r .Name )
5960
6061 var errorList field.ErrorList
@@ -75,16 +76,16 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
7576 errorList = webhookutil .EnsureAtLeastOneFieldExists (spec .Offering .ID , spec .Offering .Name , "Offering" , errorList )
7677 errorList = webhookutil .EnsureAtLeastOneFieldExists (spec .Template .ID , spec .Template .Name , "Template" , errorList )
7778
78- return webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
79+ return nil , webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
7980}
8081
8182// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
82- func (r * CloudStackMachineTemplate ) ValidateUpdate (old runtime.Object ) error {
83+ func (r * CloudStackMachineTemplate ) ValidateUpdate (old runtime.Object ) (admission. Warnings , error ) {
8384 cloudstackmachinetemplatelog .V (1 ).Info ("entered validate update webhook" , "api resource name" , r .Name )
8485
8586 oldMachineTemplate , ok := old .(* CloudStackMachineTemplate )
8687 if ! ok {
87- return errors .NewBadRequest (fmt .Sprintf ("expected a CloudStackMachineTemplate but got a %T" , old ))
88+ return nil , errors .NewBadRequest (fmt .Sprintf ("expected a CloudStackMachineTemplate but got a %T" , old ))
8889 }
8990
9091 // CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec
@@ -106,12 +107,12 @@ func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
106107 errorList = append (errorList , field .Forbidden (field .NewPath ("spec" , "AffinityGroupIDs" ), "AffinityGroupIDs" ))
107108 }
108109
109- return webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
110+ return nil , webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
110111}
111112
112113// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
113- func (r * CloudStackMachineTemplate ) ValidateDelete () error {
114+ func (r * CloudStackMachineTemplate ) ValidateDelete () (admission. Warnings , error ) {
114115 cloudstackmachinetemplatelog .V (1 ).Info ("entered validate delete webhook" , "api resource name" , r .Name )
115116 // No deletion validations. Deletion webhook not enabled.
116- return nil
117+ return nil , nil
117118}
0 commit comments