Commit e4c219df authored by jennybuckley's avatar jennybuckley

block dry run if a webhook would be called

parent 972e1549
...@@ -45,3 +45,9 @@ func ToStatusErr(webhookName string, result *metav1.Status) *apierrors.StatusErr ...@@ -45,3 +45,9 @@ func ToStatusErr(webhookName string, result *metav1.Status) *apierrors.StatusErr
ErrStatus: *result, ErrStatus: *result,
} }
} }
// NewDryRunUnsupportedErr returns a StatusError with information about the webhook plugin
func NewDryRunUnsupportedErr(webhookName string) *apierrors.StatusError {
reason := fmt.Sprintf("admission webhook %q does not support dry run", webhookName)
return apierrors.NewBadRequest(reason)
}
...@@ -82,6 +82,11 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr *generic.Version ...@@ -82,6 +82,11 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr *generic.Version
// note that callAttrMutatingHook updates attr // note that callAttrMutatingHook updates attr
func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *v1beta1.Webhook, attr *generic.VersionedAttributes) error { func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *v1beta1.Webhook, attr *generic.VersionedAttributes) error {
if attr.IsDryRun() {
// TODO: support this
webhookerrors.NewDryRunUnsupportedErr(h.Name)
}
// Make the webhook request // Make the webhook request
request := request.CreateAdmissionReview(attr) request := request.CreateAdmissionReview(attr)
client, err := a.cm.HookClient(h) client, err := a.cm.HookClient(h)
......
...@@ -97,6 +97,11 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr *generic.Versi ...@@ -97,6 +97,11 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr *generic.Versi
} }
func (d *validatingDispatcher) callHook(ctx context.Context, h *v1beta1.Webhook, attr *generic.VersionedAttributes) error { func (d *validatingDispatcher) callHook(ctx context.Context, h *v1beta1.Webhook, attr *generic.VersionedAttributes) error {
if attr.IsDryRun() {
// TODO: support this
webhookerrors.NewDryRunUnsupportedErr(h.Name)
}
// Make the webhook request // Make the webhook request
request := request.CreateAdmissionReview(attr) request := request.CreateAdmissionReview(attr)
client, err := d.cm.HookClient(h) client, err := d.cm.HookClient(h)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment