@@ -19,7 +19,7 @@ limitations under the License.
19
19
//
20
20
// The markers take the form:
21
21
//
22
- // +kubebuilder:webhook:failurePolicy=<string>,groups=<[]string>,resources=<[]string>,verbs=<[]string>,versions=<[]string>,name=<string>,path=<string>,mutating=<bool>
22
+ // +kubebuilder:webhook:failurePolicy=<string>,matchPolicy=<string>, groups=<[]string>,resources=<[]string>,verbs=<[]string>,versions=<[]string>,name=<string>,path=<string>,mutating=<bool>
23
23
package webhook
24
24
25
25
import (
@@ -57,6 +57,10 @@ type Config struct {
57
57
// It may be either "ignore" (to skip the webhook and continue on) or "fail" (to reject
58
58
// the object in question).
59
59
FailurePolicy string
60
+ // MatchPolicy defines how the "rules" list is used to match incoming requests.
61
+ // Allowed values are "Exact" (match only if it exactly matches the specified rule)
62
+ // or "Equivalent" (match a request if it modifies a resource listed in rules, even via another API group or version).
63
+ MatchPolicy string
60
64
61
65
// Groups specifies the API groups that this webhook receives requests for.
62
66
Groups []string
@@ -111,6 +115,7 @@ func (c Config) ToMutatingWebhook() (admissionreg.MutatingWebhook, error) {
111
115
Name : c .Name ,
112
116
Rules : c .rules (),
113
117
FailurePolicy : c .failurePolicy (),
118
+ MatchPolicy : c .matchPolicy (),
114
119
ClientConfig : c .clientConfig (),
115
120
}, nil
116
121
}
@@ -125,6 +130,7 @@ func (c Config) ToValidatingWebhook() (admissionreg.ValidatingWebhook, error) {
125
130
Name : c .Name ,
126
131
Rules : c .rules (),
127
132
FailurePolicy : c .failurePolicy (),
133
+ MatchPolicy : c .matchPolicy (),
128
134
ClientConfig : c .clientConfig (),
129
135
}, nil
130
136
}
@@ -170,6 +176,21 @@ func (c Config) failurePolicy() *admissionreg.FailurePolicyType {
170
176
return & failurePolicy
171
177
}
172
178
179
+ // matchPolicy converts the string value to the proper value for the API.
180
+ // Unrecognized values are passed through.
181
+ func (c Config ) matchPolicy () * admissionreg.MatchPolicyType {
182
+ var matchPolicy admissionreg.MatchPolicyType
183
+ switch strings .ToLower (c .MatchPolicy ) {
184
+ case strings .ToLower (string (admissionreg .Exact )):
185
+ matchPolicy = admissionreg .Exact
186
+ case strings .ToLower (string (admissionreg .Equivalent )):
187
+ matchPolicy = admissionreg .Equivalent
188
+ default :
189
+ matchPolicy = admissionreg .MatchPolicyType (c .MatchPolicy )
190
+ }
191
+ return & matchPolicy
192
+ }
193
+
173
194
// clientConfig returns the client config for a webhook.
174
195
func (c Config ) clientConfig () admissionreg.WebhookClientConfig {
175
196
path := c .Path
0 commit comments