diff --git a/generate_testdata.sh b/generate_testdata.sh index 3e9570a963b..542cda6ec96 100755 --- a/generate_testdata.sh +++ b/generate_testdata.sh @@ -64,6 +64,7 @@ scaffold_test_project() { $kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false $kb create webhook --group crew --version v1 --kind FirstMate --conversion $kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false + $kb create webhook --group crew --version v1 --kind Admiral --defaulting elif [ $project == "project-v2-multigroup" ] || [ $project == "project-v3-multigroup" ]; then header_text 'Switching to multigroup layout ...' $kb edit --multigroup=true @@ -74,7 +75,9 @@ scaffold_test_project() { $kb create api --group ship --version v1beta1 --kind Frigate --controller=true --resource=true --make=false $kb create webhook --group ship --version v1beta1 --kind Frigate --conversion $kb create api --group ship --version v1 --kind Destroyer --controller=true --resource=true --namespaced=false --make=false + $kb create webhook --group ship --version v1 --kind Destroyer --defaulting $kb create api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false + $kb create webhook --group ship --version v2alpha1 --kind Cruiser --programmatic-validation $kb create api --group sea-creatures --version v1beta1 --kind Kraken --controller=true --resource=true --make=false $kb create api --group sea-creatures --version v1beta2 --kind Leviathan --controller=true --resource=true --make=false $kb create api --group foo.policy --version v1 --kind HealthCheckPolicy --controller=true --resource=true --make=false diff --git a/pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go index 4af8b46f8f3..a3eb9cca7a7 100644 --- a/pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go +++ b/pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go @@ -78,8 +78,10 @@ package {{ .Resource.Version }} import ( ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" - {{- if or .Validating .Defaulting }} + {{- if or .Validating }} "k8s.io/apimachinery/pkg/runtime" + {{- end }} + {{- if or .Validating .Defaulting }} "sigs.k8s.io/controller-runtime/pkg/webhook" {{- end }} ) diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/api/webhook.go b/pkg/plugin/v3/scaffolds/internal/templates/config/api/webhook.go index 95f6732ce93..66ff8ec6687 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/api/webhook.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/api/webhook.go @@ -82,8 +82,10 @@ package {{ .Resource.Version }} import ( ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" - {{- if or .Validating .Defaulting }} + {{- if .Validating }} "k8s.io/apimachinery/pkg/runtime" + {{- end }} + {{- if or .Validating .Defaulting }} "sigs.k8s.io/controller-runtime/pkg/webhook" {{- end }} ) diff --git a/testdata/project-v2-multigroup/apis/ship/v1/destroyer_webhook.go b/testdata/project-v2-multigroup/apis/ship/v1/destroyer_webhook.go new file mode 100644 index 00000000000..3fba6666a28 --- /dev/null +++ b/testdata/project-v2-multigroup/apis/ship/v1/destroyer_webhook.go @@ -0,0 +1,45 @@ +/* +Copyright 2020 The Kubernetes authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" +) + +// log is for logging in this package. +var destroyerlog = logf.Log.WithName("destroyer-resource") + +func (r *Destroyer) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +// +kubebuilder:webhook:path=/mutate-ship-testproject-org-v1-destroyer,mutating=true,failurePolicy=fail,groups=ship.testproject.org,resources=destroyers,verbs=create;update,versions=v1,name=mdestroyer.kb.io + +var _ webhook.Defaulter = &Destroyer{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Destroyer) Default() { + destroyerlog.Info("default", "name", r.Name) + + // TODO(user): fill in your defaulting logic. +} diff --git a/testdata/project-v2-multigroup/apis/ship/v2alpha1/cruiser_webhook.go b/testdata/project-v2-multigroup/apis/ship/v2alpha1/cruiser_webhook.go new file mode 100644 index 00000000000..eeb241633e8 --- /dev/null +++ b/testdata/project-v2-multigroup/apis/ship/v2alpha1/cruiser_webhook.go @@ -0,0 +1,64 @@ +/* +Copyright 2020 The Kubernetes authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2alpha1 + +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" +) + +// log is for logging in this package. +var cruiserlog = logf.Log.WithName("cruiser-resource") + +func (r *Cruiser) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. +// +kubebuilder:webhook:verbs=create;update,path=/validate-ship-testproject-org-v2alpha1-cruiser,mutating=false,failurePolicy=fail,groups=ship.testproject.org,resources=cruisers,versions=v2alpha1,name=vcruiser.kb.io + +var _ webhook.Validator = &Cruiser{} + +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type +func (r *Cruiser) ValidateCreate() error { + cruiserlog.Info("validate create", "name", r.Name) + + // TODO(user): fill in your validation logic upon object creation. + return nil +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type +func (r *Cruiser) ValidateUpdate(old runtime.Object) error { + cruiserlog.Info("validate update", "name", r.Name) + + // TODO(user): fill in your validation logic upon object update. + return nil +} + +// ValidateDelete implements webhook.Validator so a webhook will be registered for the type +func (r *Cruiser) ValidateDelete() error { + cruiserlog.Info("validate delete", "name", r.Name) + + // TODO(user): fill in your validation logic upon object deletion. + return nil +} diff --git a/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go index f730e043751..2aa29fbd0c5 100644 --- a/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v2alpha1 import ( - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/testdata/project-v2-multigroup/config/webhook/manifests.yaml b/testdata/project-v2-multigroup/config/webhook/manifests.yaml index 07e89cfcf3b..50c03663000 100644 --- a/testdata/project-v2-multigroup/config/webhook/manifests.yaml +++ b/testdata/project-v2-multigroup/config/webhook/manifests.yaml @@ -24,6 +24,24 @@ webhooks: - UPDATE resources: - captains +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /mutate-ship-testproject-org-v1-destroyer + failurePolicy: Fail + name: mdestroyer.kb.io + rules: + - apiGroups: + - ship.testproject.org + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - destroyers --- apiVersion: admissionregistration.k8s.io/v1beta1 @@ -50,3 +68,21 @@ webhooks: - UPDATE resources: - captains +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /validate-ship-testproject-org-v2alpha1-cruiser + failurePolicy: Fail + name: vcruiser.kb.io + rules: + - apiGroups: + - ship.testproject.org + apiVersions: + - v2alpha1 + operations: + - CREATE + - UPDATE + resources: + - cruisers diff --git a/testdata/project-v2-multigroup/main.go b/testdata/project-v2-multigroup/main.go index e9009d18efc..c4572f3ffc0 100644 --- a/testdata/project-v2-multigroup/main.go +++ b/testdata/project-v2-multigroup/main.go @@ -114,6 +114,10 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Destroyer") os.Exit(1) } + if err = (&shipv1.Destroyer{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Destroyer") + os.Exit(1) + } if err = (&shipcontroller.CruiserReconciler{ Client: mgr.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("Cruiser"), @@ -122,6 +126,10 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Cruiser") os.Exit(1) } + if err = (&shipv2alpha1.Cruiser{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser") + os.Exit(1) + } if err = (&seacreaturescontroller.KrakenReconciler{ Client: mgr.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("Kraken"), diff --git a/testdata/project-v2/api/v1/admiral_webhook.go b/testdata/project-v2/api/v1/admiral_webhook.go new file mode 100644 index 00000000000..8add0a90b92 --- /dev/null +++ b/testdata/project-v2/api/v1/admiral_webhook.go @@ -0,0 +1,45 @@ +/* +Copyright 2020 The Kubernetes authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" +) + +// log is for logging in this package. +var admirallog = logf.Log.WithName("admiral-resource") + +func (r *Admiral) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-admiral,mutating=true,failurePolicy=fail,groups=crew.testproject.org,resources=admirals,verbs=create;update,versions=v1,name=madmiral.kb.io + +var _ webhook.Defaulter = &Admiral{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Admiral) Default() { + admirallog.Info("default", "name", r.Name) + + // TODO(user): fill in your defaulting logic. +} diff --git a/testdata/project-v2/config/webhook/manifests.yaml b/testdata/project-v2/config/webhook/manifests.yaml index 07e89cfcf3b..387f0c3ea71 100644 --- a/testdata/project-v2/config/webhook/manifests.yaml +++ b/testdata/project-v2/config/webhook/manifests.yaml @@ -6,6 +6,24 @@ metadata: creationTimestamp: null name: mutating-webhook-configuration webhooks: +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /mutate-crew-testproject-org-v1-admiral + failurePolicy: Fail + name: madmiral.kb.io + rules: + - apiGroups: + - crew.testproject.org + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - admirals - clientConfig: caBundle: Cg== service: diff --git a/testdata/project-v2/main.go b/testdata/project-v2/main.go index 945d94b1a69..9f3a99aa5ce 100644 --- a/testdata/project-v2/main.go +++ b/testdata/project-v2/main.go @@ -99,6 +99,10 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Admiral") os.Exit(1) } + if err = (&crewv1.Admiral{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Admiral") + os.Exit(1) + } // +kubebuilder:scaffold:builder setupLog.Info("starting manager") diff --git a/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go b/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go new file mode 100644 index 00000000000..3fba6666a28 --- /dev/null +++ b/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go @@ -0,0 +1,45 @@ +/* +Copyright 2020 The Kubernetes authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" +) + +// log is for logging in this package. +var destroyerlog = logf.Log.WithName("destroyer-resource") + +func (r *Destroyer) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +// +kubebuilder:webhook:path=/mutate-ship-testproject-org-v1-destroyer,mutating=true,failurePolicy=fail,groups=ship.testproject.org,resources=destroyers,verbs=create;update,versions=v1,name=mdestroyer.kb.io + +var _ webhook.Defaulter = &Destroyer{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Destroyer) Default() { + destroyerlog.Info("default", "name", r.Name) + + // TODO(user): fill in your defaulting logic. +} diff --git a/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go b/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go new file mode 100644 index 00000000000..eeb241633e8 --- /dev/null +++ b/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go @@ -0,0 +1,64 @@ +/* +Copyright 2020 The Kubernetes authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2alpha1 + +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" +) + +// log is for logging in this package. +var cruiserlog = logf.Log.WithName("cruiser-resource") + +func (r *Cruiser) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. +// +kubebuilder:webhook:verbs=create;update,path=/validate-ship-testproject-org-v2alpha1-cruiser,mutating=false,failurePolicy=fail,groups=ship.testproject.org,resources=cruisers,versions=v2alpha1,name=vcruiser.kb.io + +var _ webhook.Validator = &Cruiser{} + +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type +func (r *Cruiser) ValidateCreate() error { + cruiserlog.Info("validate create", "name", r.Name) + + // TODO(user): fill in your validation logic upon object creation. + return nil +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type +func (r *Cruiser) ValidateUpdate(old runtime.Object) error { + cruiserlog.Info("validate update", "name", r.Name) + + // TODO(user): fill in your validation logic upon object update. + return nil +} + +// ValidateDelete implements webhook.Validator so a webhook will be registered for the type +func (r *Cruiser) ValidateDelete() error { + cruiserlog.Info("validate delete", "name", r.Name) + + // TODO(user): fill in your validation logic upon object deletion. + return nil +} diff --git a/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go index f730e043751..2aa29fbd0c5 100644 --- a/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v2alpha1 import ( - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/testdata/project-v3-multigroup/config/webhook/manifests.yaml b/testdata/project-v3-multigroup/config/webhook/manifests.yaml index 21523ecdf44..d3399b0658b 100644 --- a/testdata/project-v3-multigroup/config/webhook/manifests.yaml +++ b/testdata/project-v3-multigroup/config/webhook/manifests.yaml @@ -24,6 +24,24 @@ webhooks: - UPDATE resources: - captains +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /mutate-ship-testproject-org-v1-destroyer + failurePolicy: Fail + name: mdestroyer.kb.io + rules: + - apiGroups: + - ship.testproject.org + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - destroyers - clientConfig: caBundle: Cg== service: @@ -68,6 +86,24 @@ webhooks: - UPDATE resources: - captains +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /validate-ship-testproject-org-v2alpha1-cruiser + failurePolicy: Fail + name: vcruiser.kb.io + rules: + - apiGroups: + - ship.testproject.org + apiVersions: + - v2alpha1 + operations: + - CREATE + - UPDATE + resources: + - cruisers - clientConfig: caBundle: Cg== service: diff --git a/testdata/project-v3-multigroup/main.go b/testdata/project-v3-multigroup/main.go index ecfb05d3067..0e8f542e4cf 100644 --- a/testdata/project-v3-multigroup/main.go +++ b/testdata/project-v3-multigroup/main.go @@ -125,6 +125,10 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Destroyer") os.Exit(1) } + if err = (&shipv1.Destroyer{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Destroyer") + os.Exit(1) + } if err = (&shipcontrollers.CruiserReconciler{ Client: mgr.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("ship").WithName("Cruiser"), @@ -133,6 +137,10 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Cruiser") os.Exit(1) } + if err = (&shipv2alpha1.Cruiser{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser") + os.Exit(1) + } if err = (&seacreaturescontrollers.KrakenReconciler{ Client: mgr.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("sea-creatures").WithName("Kraken"), diff --git a/testdata/project-v3/api/v1/admiral_webhook.go b/testdata/project-v3/api/v1/admiral_webhook.go new file mode 100644 index 00000000000..8add0a90b92 --- /dev/null +++ b/testdata/project-v3/api/v1/admiral_webhook.go @@ -0,0 +1,45 @@ +/* +Copyright 2020 The Kubernetes authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" +) + +// log is for logging in this package. +var admirallog = logf.Log.WithName("admiral-resource") + +func (r *Admiral) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-admiral,mutating=true,failurePolicy=fail,groups=crew.testproject.org,resources=admirals,verbs=create;update,versions=v1,name=madmiral.kb.io + +var _ webhook.Defaulter = &Admiral{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Admiral) Default() { + admirallog.Info("default", "name", r.Name) + + // TODO(user): fill in your defaulting logic. +} diff --git a/testdata/project-v3/config/webhook/manifests.yaml b/testdata/project-v3/config/webhook/manifests.yaml index 07e89cfcf3b..387f0c3ea71 100644 --- a/testdata/project-v3/config/webhook/manifests.yaml +++ b/testdata/project-v3/config/webhook/manifests.yaml @@ -6,6 +6,24 @@ metadata: creationTimestamp: null name: mutating-webhook-configuration webhooks: +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /mutate-crew-testproject-org-v1-admiral + failurePolicy: Fail + name: madmiral.kb.io + rules: + - apiGroups: + - crew.testproject.org + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - admirals - clientConfig: caBundle: Cg== service: diff --git a/testdata/project-v3/main.go b/testdata/project-v3/main.go index de984c0bbff..99e4bfa9d41 100644 --- a/testdata/project-v3/main.go +++ b/testdata/project-v3/main.go @@ -107,6 +107,10 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Admiral") os.Exit(1) } + if err = (&crewv1.Admiral{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Admiral") + os.Exit(1) + } // +kubebuilder:scaffold:builder setupLog.Info("starting manager")