@@ -27,6 +27,7 @@ import (
27
27
ctrl "sigs.k8s.io/controller-runtime"
28
28
logf "sigs.k8s.io/controller-runtime/pkg/log"
29
29
"sigs.k8s.io/controller-runtime/pkg/webhook"
30
+ "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
30
31
)
31
32
32
33
// log is for logging in this package.
@@ -53,7 +54,7 @@ func (r *CloudStackMachine) Default() {
53
54
var _ webhook.Validator = & CloudStackMachine {}
54
55
55
56
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
56
- func (r * CloudStackMachine ) ValidateCreate () error {
57
+ func (r * CloudStackMachine ) ValidateCreate () (admission. Warnings , error ) {
57
58
cloudstackmachinelog .V (1 ).Info ("entered validate create webhook" , "api resource name" , r .Name )
58
59
59
60
var errorList field.ErrorList
@@ -64,18 +65,18 @@ func (r *CloudStackMachine) ValidateCreate() error {
64
65
errorList = webhookutil .EnsureIntFieldsAreNotNegative (r .Spec .DiskOffering .CustomSize , "customSizeInGB" , errorList )
65
66
}
66
67
67
- return webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
68
+ return nil , webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
68
69
}
69
70
70
71
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
71
- func (r * CloudStackMachine ) ValidateUpdate (old runtime.Object ) error {
72
+ func (r * CloudStackMachine ) ValidateUpdate (old runtime.Object ) (admission. Warnings , error ) {
72
73
cloudstackmachinelog .V (1 ).Info ("entered validate update webhook" , "api resource name" , r .Name )
73
74
74
75
var errorList field.ErrorList
75
76
76
77
oldMachine , ok := old .(* CloudStackMachine )
77
78
if ! ok {
78
- return errors .NewBadRequest (fmt .Sprintf ("expected a CloudStackMachine but got a %T" , old ))
79
+ return nil , errors .NewBadRequest (fmt .Sprintf ("expected a CloudStackMachine but got a %T" , old ))
79
80
}
80
81
oldSpec := oldMachine .Spec
81
82
@@ -98,12 +99,12 @@ func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
98
99
errorList = append (errorList , field .Forbidden (field .NewPath ("spec" , "AffinityGroupIDs" ), "AffinityGroupIDs" ))
99
100
}
100
101
101
- return webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
102
+ return nil , webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
102
103
}
103
104
104
105
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
105
- func (r * CloudStackMachine ) ValidateDelete () error {
106
+ func (r * CloudStackMachine ) ValidateDelete () (admission. Warnings , error ) {
106
107
cloudstackmachinelog .V (1 ).Info ("entered validate delete webhook" , "api resource name" , r .Name )
107
108
// No deletion validations. Deletion webhook not enabled.
108
- return nil
109
+ return nil , nil
109
110
}
0 commit comments