@@ -60,7 +60,7 @@ type Config struct {
60
60
// MatchPolicy defines how the "rules" list is used to match incoming requests.
61
61
// Allowed values are "Exact" (match only if it exactly matches the specified rule)
62
62
// or "Equivalent" (match a request if it modifies a resource listed in rules, even via another API group or version).
63
- MatchPolicy string
63
+ MatchPolicy string `marker:",optional"`
64
64
65
65
// Groups specifies the API groups that this webhook receives requests for.
66
66
Groups []string
@@ -111,11 +111,16 @@ func (c Config) ToMutatingWebhook() (admissionreg.MutatingWebhook, error) {
111
111
return admissionreg.MutatingWebhook {}, fmt .Errorf ("%s is a validating webhook" , c .Name )
112
112
}
113
113
114
+ matchPolicy , err := c .matchPolicy ()
115
+ if err != nil {
116
+ return admissionreg.MutatingWebhook {}, err
117
+ }
118
+
114
119
return admissionreg.MutatingWebhook {
115
120
Name : c .Name ,
116
121
Rules : c .rules (),
117
122
FailurePolicy : c .failurePolicy (),
118
- MatchPolicy : c . matchPolicy () ,
123
+ MatchPolicy : matchPolicy ,
119
124
ClientConfig : c .clientConfig (),
120
125
}, nil
121
126
}
@@ -126,11 +131,16 @@ func (c Config) ToValidatingWebhook() (admissionreg.ValidatingWebhook, error) {
126
131
return admissionreg.ValidatingWebhook {}, fmt .Errorf ("%s is a mutating webhook" , c .Name )
127
132
}
128
133
134
+ matchPolicy , err := c .matchPolicy ()
135
+ if err != nil {
136
+ return admissionreg.ValidatingWebhook {}, err
137
+ }
138
+
129
139
return admissionreg.ValidatingWebhook {
130
140
Name : c .Name ,
131
141
Rules : c .rules (),
132
142
FailurePolicy : c .failurePolicy (),
133
- MatchPolicy : c . matchPolicy () ,
143
+ MatchPolicy : matchPolicy ,
134
144
ClientConfig : c .clientConfig (),
135
145
}, nil
136
146
}
@@ -177,18 +187,17 @@ func (c Config) failurePolicy() *admissionreg.FailurePolicyType {
177
187
}
178
188
179
189
// 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 {
190
+ func (c Config ) matchPolicy () (* admissionreg.MatchPolicyType , error ) {
182
191
var matchPolicy admissionreg.MatchPolicyType
183
192
switch strings .ToLower (c .MatchPolicy ) {
184
193
case strings .ToLower (string (admissionreg .Exact )):
185
194
matchPolicy = admissionreg .Exact
186
195
case strings .ToLower (string (admissionreg .Equivalent )):
187
196
matchPolicy = admissionreg .Equivalent
188
197
default :
189
- matchPolicy = admissionreg . MatchPolicyType ( c .MatchPolicy )
198
+ return nil , fmt . Errorf ( "unknown value %q for matchPolicy" , c .MatchPolicy )
190
199
}
191
- return & matchPolicy
200
+ return & matchPolicy , nil
192
201
}
193
202
194
203
// clientConfig returns the client config for a webhook.
0 commit comments