Skip to content

Commit a516e36

Browse files
committed
🌱 Use client.Object interface in WebhookInstallOptions
This is a follow-up from an earlier PR that introduced the client.Object interface. While working in Cluster API downstream, noticed that this was missing from the webhook installation options. Signed-off-by: Vince Prignano <[email protected]>
1 parent df9195b commit a516e36

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/envtest/envtest_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
admissionv1 "k8s.io/api/admissionregistration/v1"
2525
admissionv1beta1 "k8s.io/api/admissionregistration/v1beta1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
"k8s.io/apimachinery/pkg/runtime"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
2828
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
2929
logf "sigs.k8s.io/controller-runtime/pkg/log"
3030
"sigs.k8s.io/controller-runtime/pkg/log/zap"
@@ -61,7 +61,7 @@ func initializeWebhookInEnvironment() {
6161
webhookPathV1 := "/failing"
6262

6363
env.WebhookInstallOptions = WebhookInstallOptions{
64-
ValidatingWebhooks: []runtime.Object{
64+
ValidatingWebhooks: []client.Object{
6565
&admissionv1beta1.ValidatingWebhookConfiguration{
6666
ObjectMeta: metav1.ObjectMeta{
6767
Name: "deployment-validation-webhook-config",

pkg/envtest/webhook.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ type WebhookInstallOptions struct {
4444
Paths []string
4545

4646
// MutatingWebhooks is a list of MutatingWebhookConfigurations to install
47-
MutatingWebhooks []runtime.Object
47+
MutatingWebhooks []client.Object
4848

4949
// ValidatingWebhooks is a list of ValidatingWebhookConfigurations to install
50-
ValidatingWebhooks []runtime.Object
50+
ValidatingWebhooks []client.Object
5151

5252
// IgnoreErrorIfPathMissing will ignore an error if a DirectoryPath does not exist when set to true
5353
IgnoreErrorIfPathMissing bool
@@ -195,8 +195,8 @@ func (o *WebhookInstallOptions) Cleanup() error {
195195

196196
// WaitForWebhooks waits for the Webhooks to be available through API server
197197
func WaitForWebhooks(config *rest.Config,
198-
mutatingWebhooks []runtime.Object,
199-
validatingWebhooks []runtime.Object,
198+
mutatingWebhooks []client.Object,
199+
validatingWebhooks []client.Object,
200200
options WebhookInstallOptions) error {
201201

202202
waitingFor := map[schema.GroupVersionKind]*sets.String{}
@@ -293,7 +293,7 @@ func (o *WebhookInstallOptions) setupCA() ([]byte, error) {
293293
return certData, nil
294294
}
295295

296-
func createWebhooks(config *rest.Config, mutHooks []runtime.Object, valHooks []runtime.Object) error {
296+
func createWebhooks(config *rest.Config, mutHooks []client.Object, valHooks []client.Object) error {
297297
cs, err := client.New(config, client.Options{})
298298
if err != nil {
299299
return err
@@ -360,7 +360,7 @@ func parseWebhook(options *WebhookInstallOptions) error {
360360

361361
// readWebhooks reads the Webhooks from files and Unmarshals them into structs
362362
// returns slice of mutating and validating webhook configurations
363-
func readWebhooks(path string) ([]runtime.Object, []runtime.Object, error) {
363+
func readWebhooks(path string) ([]client.Object, []client.Object, error) {
364364
// Get the webhook files
365365
var files []os.FileInfo
366366
var err error
@@ -380,8 +380,8 @@ func readWebhooks(path string) ([]runtime.Object, []runtime.Object, error) {
380380
// file extensions that may contain Webhooks
381381
resourceExtensions := sets.NewString(".json", ".yaml", ".yml")
382382

383-
var mutHooks []runtime.Object
384-
var valHooks []runtime.Object
383+
var mutHooks []client.Object
384+
var valHooks []client.Object
385385
for _, file := range files {
386386
// Only parse allowlisted file types
387387
if !resourceExtensions.Has(filepath.Ext(file.Name())) {
@@ -433,7 +433,7 @@ func readWebhooks(path string) ([]runtime.Object, []runtime.Object, error) {
433433
return mutHooks, valHooks, nil
434434
}
435435

436-
func runtimeListToUnstructured(l []runtime.Object) []*unstructured.Unstructured {
436+
func runtimeListToUnstructured(l []client.Object) []*unstructured.Unstructured {
437437
res := []*unstructured.Unstructured{}
438438
for _, obj := range l {
439439
m, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj.DeepCopyObject())

0 commit comments

Comments
 (0)