-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
I want to check if the other resources referenced by an object exist within a webhook. Could someone please help me complete the logic in the following code example? Thank you very much.
// SetupWebhookWithManager will setup the manager to manage the webhooks
func (r *Pool) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}
var _ webhook.Validator = &Pool{}
func (r *Pool) Validate() error {
var allErrs field.ErrorList
model := r.Spec.Model
/*
check model is exist here;
*/
if len(allErrs) == 0 {
return nil
}
return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Pool"}, r.Name, allErrs)
}
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *Pool) ValidateCreate() (admission.Warnings, error) {
poollog.Info("validate create", "name", r.Name)
// TODO(user): fill in your validation logic upon object creation.
return nil, r.Validate()
}
### Tasks
Metadata
Metadata
Assignees
Labels
No labels