Skip to content

Commit 63eba3e

Browse files
committed
Updated to new webhook validator pattern.
Controller-runtime's webhook validator types changed due to this issue: kubernetes-sigs/controller-runtime#2641
1 parent b54e57e commit 63eba3e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

api/v1alpha1/certsuiterun_webhook.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (r *CertsuiteRun) SetupWebhookWithManager(mgr ctrl.Manager) error {
4949

5050
return ctrl.NewWebhookManagedBy(mgr).
5151
For(r).
52+
WithValidator(r).
5253
Complete()
5354
}
5455

@@ -58,11 +59,12 @@ func (r *CertsuiteRun) SetupWebhookWithManager(mgr ctrl.Manager) error {
5859
//nolint:lll
5960
//+kubebuilder:webhook:path=/validate-best-practices-for-k8s-openshift-io-v1alpha1-certsuiterun,mutating=false,failurePolicy=fail,sideEffects=None,groups=best-practices-for-k8s.openshift.io,resources=certsuiteruns,verbs=create;update,versions=v1alpha1,name=vcertsuiterun.kb.io,admissionReviewVersions=v1
6061

61-
var _ webhook.Validator = &CertsuiteRun{}
62+
var _ webhook.CustomValidator = &CertsuiteRun{}
6263

6364
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
64-
func (r *CertsuiteRun) ValidateCreate() (admission.Warnings, error) {
65+
func (r *CertsuiteRun) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
6566
logger.Info("validate create", "name", r.Name)
67+
r = obj.(*CertsuiteRun)
6668

6769
err := r.validateConfigMap()
6870
if err != nil {
@@ -158,15 +160,15 @@ func (r *CertsuiteRun) validateLogLevel() error {
158160
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
159161
//
160162
//nolint:revive
161-
func (r *CertsuiteRun) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
163+
func (r *CertsuiteRun) ValidateUpdate(ctx context.Context, oldObj runtime.Object, newObj runtime.Object) (admission.Warnings, error) {
162164
logger.Info("validate update", "name", r.Name)
163165

164166
// TODO(user): fill in your validation logic upon object update.
165167
return nil, nil
166168
}
167169

168170
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
169-
func (r *CertsuiteRun) ValidateDelete() (admission.Warnings, error) {
171+
func (r *CertsuiteRun) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
170172
logger.Info("validate delete", "name", r.Name)
171173

172174
// TODO(user): fill in your validation logic upon object deletion.

0 commit comments

Comments
 (0)