@@ -17,6 +17,7 @@ limitations under the License.
1717package v1alpha1
1818
1919import (
20+ "context"
2021 "encoding/json"
2122 "fmt"
2223
@@ -37,28 +38,61 @@ var triggerauthenticationlog = logf.Log.WithName("triggerauthentication-validati
3738
3839func (ta * TriggerAuthentication ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
3940 return ctrl .NewWebhookManagedBy (mgr ).
41+ WithValidator (& TriggerAuthenticationCustomValidator {}).
4042 For (ta ).
4143 Complete ()
4244}
4345
4446func (cta * ClusterTriggerAuthentication ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
4547 return ctrl .NewWebhookManagedBy (mgr ).
48+ WithValidator (& ClusterTriggerAuthenticationCustomValidator {}).
4649 For (cta ).
4750 Complete ()
4851}
4952
5053// +kubebuilder:webhook:path=/validate-keda-sh-v1alpha1-triggerauthentication,mutating=false,failurePolicy=ignore,sideEffects=None,groups=keda.sh,resources=triggerauthentications,verbs=create;update,versions=v1alpha1,name=vstriggerauthentication.kb.io,admissionReviewVersions=v1
5154
52- var _ webhook.Validator = & TriggerAuthentication {}
55+ // TriggerAuthenticationCustomValidator is a custom validator for TriggerAuthentication objects
56+ type TriggerAuthenticationCustomValidator struct {}
57+
58+ func (tacv TriggerAuthenticationCustomValidator ) ValidateCreate (ctx context.Context , obj runtime.Object ) (warnings admission.Warnings , err error ) {
59+ request , err := admission .RequestFromContext (ctx )
60+ if err != nil {
61+ return nil , err
62+ }
63+ ta := obj .(* TriggerAuthentication )
64+ return ta .ValidateCreate (request .DryRun )
65+ }
66+
67+ func (tacv TriggerAuthenticationCustomValidator ) ValidateUpdate (ctx context.Context , oldObj , newObj runtime.Object ) (warnings admission.Warnings , err error ) {
68+ request , err := admission .RequestFromContext (ctx )
69+ if err != nil {
70+ return nil , err
71+ }
72+ ta := newObj .(* TriggerAuthentication )
73+ old := oldObj .(* TriggerAuthentication )
74+ return ta .ValidateUpdate (old , request .DryRun )
75+ }
76+
77+ func (tacv TriggerAuthenticationCustomValidator ) ValidateDelete (ctx context.Context , obj runtime.Object ) (warnings admission.Warnings , err error ) {
78+ request , err := admission .RequestFromContext (ctx )
79+ if err != nil {
80+ return nil , err
81+ }
82+ ta := obj .(* TriggerAuthentication )
83+ return ta .ValidateDelete (request .DryRun )
84+ }
85+
86+ var _ webhook.CustomValidator = & TriggerAuthenticationCustomValidator {}
5387
5488// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
55- func (ta * TriggerAuthentication ) ValidateCreate () (admission.Warnings , error ) {
89+ func (ta * TriggerAuthentication ) ValidateCreate (_ * bool ) (admission.Warnings , error ) {
5690 val , _ := json .MarshalIndent (ta , "" , " " )
5791 triggerauthenticationlog .Info (fmt .Sprintf ("validating triggerauthentication creation for %s" , string (val )))
5892 return validateSpec (& ta .Spec )
5993}
6094
61- func (ta * TriggerAuthentication ) ValidateUpdate (old runtime.Object ) (admission.Warnings , error ) {
95+ func (ta * TriggerAuthentication ) ValidateUpdate (old runtime.Object , _ * bool ) (admission.Warnings , error ) {
6296 val , _ := json .MarshalIndent (ta , "" , " " )
6397 scaledobjectlog .V (1 ).Info (fmt .Sprintf ("validating triggerauthentication update for %s" , string (val )))
6498
@@ -70,22 +104,53 @@ func (ta *TriggerAuthentication) ValidateUpdate(old runtime.Object) (admission.W
70104 return validateSpec (& ta .Spec )
71105}
72106
73- func (ta * TriggerAuthentication ) ValidateDelete () (admission.Warnings , error ) {
107+ func (ta * TriggerAuthentication ) ValidateDelete (_ * bool ) (admission.Warnings , error ) {
74108 return nil , nil
75109}
76110
77111// +kubebuilder:webhook:path=/validate-keda-sh-v1alpha1-clustertriggerauthentication,mutating=false,failurePolicy=ignore,sideEffects=None,groups=keda.sh,resources=clustertriggerauthentications,verbs=create;update,versions=v1alpha1,name=vsclustertriggerauthentication.kb.io,admissionReviewVersions=v1
78112
79- var _ webhook.Validator = & ClusterTriggerAuthentication {}
113+ // ClusterTriggerAuthenticationCustomValidator is a custom validator for ClusterTriggerAuthentication objects
114+ type ClusterTriggerAuthenticationCustomValidator struct {}
115+
116+ func (ctacv ClusterTriggerAuthenticationCustomValidator ) ValidateCreate (ctx context.Context , obj runtime.Object ) (warnings admission.Warnings , err error ) {
117+ request , err := admission .RequestFromContext (ctx )
118+ if err != nil {
119+ return nil , err
120+ }
121+ cta := obj .(* ClusterTriggerAuthentication )
122+ return cta .ValidateCreate (request .DryRun )
123+ }
124+
125+ func (ctacv ClusterTriggerAuthenticationCustomValidator ) ValidateUpdate (ctx context.Context , oldObj , newObj runtime.Object ) (warnings admission.Warnings , err error ) {
126+ request , err := admission .RequestFromContext (ctx )
127+ if err != nil {
128+ return nil , err
129+ }
130+ cta := newObj .(* ClusterTriggerAuthentication )
131+ old := oldObj .(* ClusterTriggerAuthentication )
132+ return cta .ValidateUpdate (old , request .DryRun )
133+ }
134+
135+ func (ctacv ClusterTriggerAuthenticationCustomValidator ) ValidateDelete (ctx context.Context , obj runtime.Object ) (warnings admission.Warnings , err error ) {
136+ request , err := admission .RequestFromContext (ctx )
137+ if err != nil {
138+ return nil , err
139+ }
140+ cta := obj .(* ClusterTriggerAuthentication )
141+ return cta .ValidateDelete (request .DryRun )
142+ }
143+
144+ var _ webhook.CustomValidator = & ClusterTriggerAuthenticationCustomValidator {}
80145
81146// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
82- func (cta * ClusterTriggerAuthentication ) ValidateCreate () (admission.Warnings , error ) {
147+ func (cta * ClusterTriggerAuthentication ) ValidateCreate (_ * bool ) (admission.Warnings , error ) {
83148 val , _ := json .MarshalIndent (cta , "" , " " )
84149 triggerauthenticationlog .Info (fmt .Sprintf ("validating clustertriggerauthentication creation for %s" , string (val )))
85150 return validateSpec (& cta .Spec )
86151}
87152
88- func (cta * ClusterTriggerAuthentication ) ValidateUpdate (old runtime.Object ) (admission.Warnings , error ) {
153+ func (cta * ClusterTriggerAuthentication ) ValidateUpdate (old runtime.Object , _ * bool ) (admission.Warnings , error ) {
89154 val , _ := json .MarshalIndent (cta , "" , " " )
90155 scaledobjectlog .V (1 ).Info (fmt .Sprintf ("validating clustertriggerauthentication update for %s" , string (val )))
91156
@@ -98,7 +163,7 @@ func (cta *ClusterTriggerAuthentication) ValidateUpdate(old runtime.Object) (adm
98163 return validateSpec (& cta .Spec )
99164}
100165
101- func (cta * ClusterTriggerAuthentication ) ValidateDelete () (admission.Warnings , error ) {
166+ func (cta * ClusterTriggerAuthentication ) ValidateDelete (_ * bool ) (admission.Warnings , error ) {
102167 return nil , nil
103168}
104169
0 commit comments