-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinterface.go
52 lines (40 loc) · 1.55 KB
/
interface.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
41
42
43
44
45
46
47
48
49
50
51
52
/*
* SPDX-FileCopyrightText: 2020 SAP SE or an SAP affiliate company and Gardener contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
package bound
import (
"github.com/gardener/controller-manager-library/pkg/controllermanager/webhook"
"github.com/gardener/controller-manager-library/pkg/logger"
"github.com/gardener/controller-manager-library/pkg/controllermanager/webhook/admission"
"github.com/gardener/controller-manager-library/pkg/resources"
)
// Request describes the admission.Attributes for the admission request.
type Request struct {
Request admission.Request
Object resources.Object
OldObject resources.Object
}
// Interface can handle an AdmissionRequest.
type Interface interface {
Handle(logger.LogContext, Request) admission.Response
}
type AdmissionHandlerType func(webhook.Interface) (Interface, error)
// WebhookFunc implements Handler interface using a single function.
type WebhookFunc func(logger.LogContext, Request) admission.Response
var _ Interface = WebhookFunc(nil)
// Handle process the AdmissionRequest by invoking the underlying function.
func (this WebhookFunc) Handle(logger logger.LogContext, req Request) admission.Response {
return this(logger, req)
}
func (this WebhookFunc) Type() AdmissionHandlerType {
return func(webhook.Interface) (Interface, error) { return this, nil }
}
// DefaultHandler can be used for a default implementation of all interface
// methods
type DefaultHandler struct {
}
func (this *DefaultHandler) Handle(logger.LogContext, Request) admission.Response {
return admission.Allowed("always")
}