/
cache_webhook.go
40 lines (32 loc) · 1.49 KB
/
cache_webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package v1alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)
// log is for logging in this package.
var cachelog = logf.Log.WithName("cache-resource")
func (r *Cache) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}
//+kubebuilder:webhook:path=/validate-hazelcast-com-v1alpha1-cache,mutating=false,failurePolicy=fail,sideEffects=None,groups=hazelcast.com,resources=caches,verbs=create;update,versions=v1alpha1,name=vcache.kb.io,admissionReviewVersions=v1
var _ webhook.Validator = &Cache{}
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (c *Cache) ValidateCreate() (admission.Warnings, error) {
cachelog.Info("validate create", "name", c.Name)
return admission.Warnings{}, c.ValidateSpecCreate()
}
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (c *Cache) ValidateUpdate(runtime.Object) (admission.Warnings, error) {
cachelog.Info("validate update", "name", c.Name)
return admission.Warnings{}, c.ValidateSpecUpdate()
}
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (c *Cache) ValidateDelete() (admission.Warnings, error) {
cachelog.Info("validate delete", "name", c.Name)
return admission.Warnings{}, nil
}