@@ -17,10 +17,11 @@ limitations under the License.
17
17
package v1
18
18
19
19
import (
20
+ "context"
20
21
"k8s.io/apimachinery/pkg/runtime"
21
22
ctrl "sigs.k8s.io/controller-runtime"
22
23
logf "sigs.k8s.io/controller-runtime/pkg/log"
23
- // "sigs.k8s.io/controller-runtime/pkg/webhook"
24
+ "sigs.k8s.io/controller-runtime/pkg/webhook"
24
25
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
25
26
)
26
27
@@ -31,6 +32,7 @@ var dpuoperatorconfiglog = logf.Log.WithName("dpuoperatorconfig-resource")
31
32
func (r * DpuOperatorConfig ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
32
33
return ctrl .NewWebhookManagedBy (mgr ).
33
34
For (r ).
35
+ WithValidator (r ).
34
36
Complete ()
35
37
}
36
38
@@ -41,26 +43,28 @@ func (r *DpuOperatorConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
41
43
// Modifying the path for an invalid path can cause API server errors; failing to locate the webhook.
42
44
//+kubebuilder:webhook:path=/validate-config-openshift-io-v1-dpuoperatorconfig,mutating=false,failurePolicy=fail,sideEffects=None,groups=config.openshift.io,resources=dpuoperatorconfigs,verbs=create;update,versions=v1,name=vdpuoperatorconfig.kb.io,admissionReviewVersions=v1
43
45
44
- // var _ webhook.Validator = &DpuOperatorConfig{}
46
+ var _ webhook.CustomValidator = & DpuOperatorConfig {}
45
47
46
48
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
47
- func (r * DpuOperatorConfig ) ValidateCreate () (admission.Warnings , error ) {
49
+ func (r * DpuOperatorConfig ) ValidateCreate (tx context.Context , obj runtime.Object ) (admission.Warnings , error ) {
50
+ r = obj .(* DpuOperatorConfig )
48
51
dpuoperatorconfiglog .Info ("validate create" , "name" , r .Name )
49
52
50
53
// TODO(user): fill in your validation logic upon object creation.
51
54
return nil , nil
52
55
}
53
56
54
57
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
55
- func (r * DpuOperatorConfig ) ValidateUpdate (old runtime.Object ) (admission.Warnings , error ) {
58
+ func (r * DpuOperatorConfig ) ValidateUpdate (ctx context.Context , oldObj runtime.Object , newObj runtime.Object ) (admission.Warnings , error ) {
59
+ r = newObj .(* DpuOperatorConfig )
56
60
dpuoperatorconfiglog .Info ("validate update" , "name" , r .Name )
57
61
58
62
// TODO(user): fill in your validation logic upon object update.
59
63
return nil , nil
60
64
}
61
65
62
66
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
63
- func (r * DpuOperatorConfig ) ValidateDelete () (admission.Warnings , error ) {
67
+ func (r * DpuOperatorConfig ) ValidateDelete (ctx context. Context , obj runtime. Object ) (admission.Warnings , error ) {
64
68
dpuoperatorconfiglog .Info ("validate delete" , "name" , r .Name )
65
69
66
70
// TODO(user): fill in your validation logic upon object deletion.
0 commit comments