Update the validating webhook plugin to be a ValidatingInterface, rather than a MutatingInterface

pull/6/head
Chao Xu 2017-11-20 14:57:07 -08:00
parent 6b97376a53
commit cbfc9d33b7
3 changed files with 12 additions and 8 deletions

View File

@ -102,6 +102,8 @@ func NewMutatingWebhook(configFile io.Reader) (*MutatingWebhook, error) {
}, nil
}
var _ admission.MutationInterface = &MutatingWebhook{}
// MutatingWebhook is an implementation of admission.Interface.
type MutatingWebhook struct {
*admission.Handler

View File

@ -101,6 +101,8 @@ func NewValidatingAdmissionWebhook(configFile io.Reader) (*ValidatingAdmissionWe
}, nil
}
var _ admission.ValidationInterface = &ValidatingAdmissionWebhook{}
// ValidatingAdmissionWebhook is an implementation of admission.Interface.
type ValidatingAdmissionWebhook struct {
*admission.Handler
@ -185,8 +187,8 @@ func (a *ValidatingAdmissionWebhook) loadConfiguration(attr admission.Attributes
return hookConfig, nil
}
// Admit makes an admission decision based on the request attributes.
func (a *ValidatingAdmissionWebhook) Admit(attr admission.Attributes) error {
// Validate makes an admission decision based on the request attributes.
func (a *ValidatingAdmissionWebhook) Validate(attr admission.Attributes) error {
hookConfig, err := a.loadConfiguration(attr)
if err != nil {
return err

View File

@ -116,8 +116,8 @@ func (c urlConfigGenerator) ccfgURL(urlPath string) registrationv1alpha1.Webhook
}
}
// TestAdmit tests that ValidatingAdmissionWebhook#Admit works as expected
func TestAdmit(t *testing.T) {
// TestValidate tests that ValidatingAdmissionWebhook#Validate works as expected
func TestValidate(t *testing.T) {
scheme := runtime.NewScheme()
v1alpha1.AddToScheme(scheme)
corev1.AddToScheme(scheme)
@ -393,7 +393,7 @@ func TestAdmit(t *testing.T) {
}
t.Run(name, func(t *testing.T) {
wh.hookSource = &tt.hookSource
err = wh.Admit(admission.NewAttributesRecord(&object, &oldObject, kind, namespace, name, resource, subResource, operation, &userInfo))
err = wh.Validate(admission.NewAttributesRecord(&object, &oldObject, kind, namespace, name, resource, subResource, operation, &userInfo))
if tt.expectAllow != (err == nil) {
t.Errorf("expected allowed=%v, but got err=%v", tt.expectAllow, err)
}
@ -410,8 +410,8 @@ func TestAdmit(t *testing.T) {
}
}
// TestAdmitCachedClient tests that ValidatingAdmissionWebhook#Admit should cache restClient
func TestAdmitCachedClient(t *testing.T) {
// TestValidateCachedClient tests that ValidatingAdmissionWebhook#Validate should cache restClient
func TestValidateCachedClient(t *testing.T) {
scheme := runtime.NewScheme()
v1alpha1.AddToScheme(scheme)
corev1.AddToScheme(scheme)
@ -560,7 +560,7 @@ func TestAdmitCachedClient(t *testing.T) {
t.Fatal(err)
}
err = wh.Admit(admission.NewAttributesRecord(&object, &oldObject, kind, namespace, testcase.name, resource, subResource, operation, &userInfo))
err = wh.Validate(admission.NewAttributesRecord(&object, &oldObject, kind, namespace, testcase.name, resource, subResource, operation, &userInfo))
if testcase.expectAllow != (err == nil) {
t.Errorf("expected allowed=%v, but got err=%v", testcase.expectAllow, err)
}