@@ -10,7 +10,6 @@ import (
1010 "k8s.io/apimachinery/pkg/runtime"
1111 "sigs.k8s.io/controller-runtime/pkg/client"
1212 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
13- "sigs.k8s.io/controller-runtime/pkg/webhook"
1413)
1514
1615var (
@@ -66,11 +65,21 @@ func GenerateCertificate(ctx context.Context, c client.Client, options ...CertOp
6665 return err
6766}
6867
68+ // APITypes defines an API type along with whether it has a validator and/or defaulter webhook.
69+ type APITypes struct {
70+ // Obj is the API type object.
71+ Obj client.Object
72+ // Validator indicates whether the type has a validating webhook.
73+ Validator bool
74+ // Defaulter indicates whether the type has a mutating webhook.
75+ Defaulter bool
76+ }
77+
6978func Install (
7079 ctx context.Context ,
7180 c client.Client ,
7281 scheme * runtime.Scheme ,
73- apiTypes []client. Object ,
82+ apiTypes []APITypes ,
7483 options ... InstallOption ,
7584) error {
7685 opts := & installOptions {
@@ -104,16 +113,14 @@ func Install(
104113 }
105114 }
106115
107- for _ , o := range apiTypes {
108- _ , isCustomValidator := o .(webhook.CustomValidator )
109- if isCustomValidator {
110- if err := applyValidatingWebhook (ctx , opts , o ); err != nil {
116+ for _ , t := range apiTypes {
117+ if t .Validator {
118+ if err := applyValidatingWebhook (ctx , opts , t .Obj ); err != nil {
111119 return err
112120 }
113121 }
114- _ , isCustomDefaulter := o .(webhook.CustomDefaulter )
115- if isCustomDefaulter {
116- if err := applyMutatingWebhook (ctx , opts , o ); err != nil {
122+ if t .Defaulter {
123+ if err := applyMutatingWebhook (ctx , opts , t .Obj ); err != nil {
117124 return err
118125 }
119126 }
@@ -127,7 +134,7 @@ func Uninstall(
127134 ctx context.Context ,
128135 c client.Client ,
129136 scheme * runtime.Scheme ,
130- apiTypes []client. Object ,
137+ apiTypes []APITypes ,
131138 options ... InstallOption ,
132139) error {
133140 opts := & installOptions {
@@ -148,16 +155,14 @@ func Uninstall(
148155 }
149156 }
150157
151- for _ , o := range apiTypes {
152- _ , isCustomValidator := o .(webhook.CustomValidator )
153- if isCustomValidator {
154- if err := removeValidatingWebhook (ctx , opts , o ); err != nil {
158+ for _ , t := range apiTypes {
159+ if t .Validator {
160+ if err := removeValidatingWebhook (ctx , opts , t .Obj ); err != nil {
155161 return err
156162 }
157163 }
158- _ , isCustomDefaulter := o .(webhook.CustomDefaulter )
159- if isCustomDefaulter {
160- if err := removeMutatingWebhook (ctx , opts , o ); err != nil {
164+ if t .Defaulter {
165+ if err := removeMutatingWebhook (ctx , opts , t .Obj ); err != nil {
161166 return err
162167 }
163168 }
0 commit comments