@@ -14,45 +14,54 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package v1alpha1
17
+ package webhooks
18
18
19
19
import (
20
+ "context"
21
+
20
22
"k8s.io/apimachinery/pkg/runtime"
21
23
ctrl "sigs.k8s.io/controller-runtime"
22
24
"sigs.k8s.io/controller-runtime/pkg/webhook"
23
25
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
26
+
27
+ "sigs.k8s.io/cluster-api/test/infrastructure/inmemory/api/v1alpha1"
24
28
)
25
29
26
- func (c * InMemoryClusterTemplate ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
30
+ // InMemoryClusterTemplate implements a validating and defaulting webhook for InMemoryClusterTemplate.
31
+ type InMemoryClusterTemplate struct {}
32
+
33
+ func (webhook * InMemoryClusterTemplate ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
27
34
return ctrl .NewWebhookManagedBy (mgr ).
28
- For (c ).
35
+ For (& v1alpha1.InMemoryClusterTemplate {}).
36
+ WithDefaulter (webhook ).
37
+ WithValidator (webhook ).
29
38
Complete ()
30
39
}
31
40
32
41
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1alpha1-inmemoryclustertemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=inmemoryclustertemplates,versions=v1alpha1,name=default.inmemoryclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
33
42
34
- var _ webhook.Defaulter = & InMemoryClusterTemplate {}
43
+ var _ webhook.CustomDefaulter = & InMemoryClusterTemplate {}
35
44
36
45
// Default implements webhook.Defaulter so a webhook will be registered for the type.
37
- func (c * InMemoryClusterTemplate ) Default () {
38
-
46
+ func (webhook * InMemoryClusterTemplate ) Default (_ context. Context , _ runtime. Object ) error {
47
+ return nil
39
48
}
40
49
41
50
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha1-inmemoryclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=inmemoryclustertemplates,versions=v1alpha1,name=validation.inmemoryclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
42
51
43
- var _ webhook.Validator = & InMemoryClusterTemplate {}
52
+ var _ webhook.CustomValidator = & InMemoryClusterTemplate {}
44
53
45
54
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
46
- func (c * InMemoryClusterTemplate ) ValidateCreate () (admission.Warnings , error ) {
55
+ func (webhook * InMemoryClusterTemplate ) ValidateCreate (_ context. Context , _ runtime. Object ) (admission.Warnings , error ) {
47
56
return nil , nil
48
57
}
49
58
50
59
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
51
- func (c * InMemoryClusterTemplate ) ValidateUpdate (_ runtime.Object ) (admission.Warnings , error ) {
60
+ func (webhook * InMemoryClusterTemplate ) ValidateUpdate (_ context. Context , _ , _ runtime.Object ) (admission.Warnings , error ) {
52
61
return nil , nil
53
62
}
54
63
55
64
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
56
- func (c * InMemoryClusterTemplate ) ValidateDelete () (admission.Warnings , error ) {
65
+ func (webhook * InMemoryClusterTemplate ) ValidateDelete (_ context. Context , _ runtime. Object ) (admission.Warnings , error ) {
57
66
return nil , nil
58
67
}
0 commit comments