@@ -176,47 +176,91 @@ internal static async Task Handler(IAnsiConsole console, InvocationContext ctx)
176
176
{ Exists : false } => throw new FileNotFoundException ( $ "The file { file . Name } does not exist.") ,
177
177
_ => throw new NotSupportedException ( "Only *.csproj and *.sln files are supported." ) ,
178
178
} ;
179
- var validatedEntities = parser . GetValidatedEntities ( ) . ToList ( ) ;
179
+
180
+ var caBundle = Encoding . ASCII . GetBytes ( Convert . ToBase64String ( Encoding . ASCII . GetBytes ( caCert . ToPem ( ) ) ) ) ;
181
+
182
+ var validationWebhooks = parser . GetValidatedEntities ( ) . ToList ( ) ;
180
183
var validatorConfig = new V1ValidatingWebhookConfiguration (
181
184
metadata : new V1ObjectMeta ( name : "validators" ) ,
182
185
webhooks : new List < V1ValidatingWebhook > ( ) ) . Initialize ( ) ;
183
186
184
- foreach ( var entity in validatedEntities )
187
+ foreach ( var hook in validationWebhooks )
185
188
{
186
189
validatorConfig . Webhooks . Add ( new V1ValidatingWebhook
187
190
{
188
- Name = $ "validate.{ entity . Metadata . SingularName } .{ entity . Metadata . Group } .{ entity . Metadata . Version } ",
191
+ Name = $ "validate.{ hook . Metadata . SingularName } .{ hook . Metadata . Group } .{ hook . Metadata . Version } ",
189
192
MatchPolicy = "Exact" ,
190
193
AdmissionReviewVersions = new [ ] { "v1" } ,
191
194
SideEffects = "None" ,
192
195
Rules = new [ ]
193
196
{
194
197
new V1RuleWithOperations
195
198
{
196
- Operations = entity . GetOperations ( ) ,
197
- Resources = new [ ] { entity . Metadata . PluralName } ,
198
- ApiGroups = new [ ] { entity . Metadata . Group } ,
199
- ApiVersions = new [ ] { entity . Metadata . Version } ,
199
+ Operations = hook . GetOperations ( ) ,
200
+ Resources = new [ ] { hook . Metadata . PluralName } ,
201
+ ApiGroups = new [ ] { hook . Metadata . Group } ,
202
+ ApiVersions = new [ ] { hook . Metadata . Version } ,
200
203
} ,
201
204
} ,
202
205
ClientConfig = new Admissionregistrationv1WebhookClientConfig
203
206
{
204
- CaBundle =
205
- Encoding . ASCII . GetBytes ( Convert . ToBase64String ( Encoding . ASCII . GetBytes ( caCert . ToPem ( ) ) ) ) ,
207
+ CaBundle = caBundle ,
206
208
Service = new Admissionregistrationv1ServiceReference
207
209
{
208
- Name = "operator" , Path = entity . ValidatorPath ,
210
+ Name = "operator" ,
211
+ Path = hook . WebhookPath ,
209
212
} ,
210
213
} ,
211
214
} ) ;
212
215
}
213
216
214
- if ( validatedEntities . Any ( ) )
217
+ if ( validationWebhooks . Any ( ) )
215
218
{
216
219
result . Add (
217
220
$ "validators.{ format . ToString ( ) . ToLowerInvariant ( ) } ", validatorConfig ) ;
218
221
}
219
222
223
+ var mutationWebhooks = parser . GetMutatedEntities ( ) . ToList ( ) ;
224
+ var mutatorConfig = new V1MutatingWebhookConfiguration (
225
+ metadata : new V1ObjectMeta ( name : "mutators" ) ,
226
+ webhooks : new List < V1MutatingWebhook > ( ) ) . Initialize ( ) ;
227
+
228
+ foreach ( var hook in mutationWebhooks )
229
+ {
230
+ mutatorConfig . Webhooks . Add ( new V1MutatingWebhook
231
+ {
232
+ Name = $ "mutate.{ hook . Metadata . SingularName } .{ hook . Metadata . Group } .{ hook . Metadata . Version } ",
233
+ MatchPolicy = "Exact" ,
234
+ AdmissionReviewVersions = new [ ] { "v1" } ,
235
+ SideEffects = "None" ,
236
+ Rules = new [ ]
237
+ {
238
+ new V1RuleWithOperations
239
+ {
240
+ Operations = hook . GetOperations ( ) ,
241
+ Resources = new [ ] { hook . Metadata . PluralName } ,
242
+ ApiGroups = new [ ] { hook . Metadata . Group } ,
243
+ ApiVersions = new [ ] { hook . Metadata . Version } ,
244
+ } ,
245
+ } ,
246
+ ClientConfig = new Admissionregistrationv1WebhookClientConfig
247
+ {
248
+ CaBundle = caBundle ,
249
+ Service = new Admissionregistrationv1ServiceReference
250
+ {
251
+ Name = "operator" ,
252
+ Path = hook . WebhookPath ,
253
+ } ,
254
+ } ,
255
+ } ) ;
256
+ }
257
+
258
+ if ( mutationWebhooks . Any ( ) )
259
+ {
260
+ result . Add (
261
+ $ "mutators.{ format . ToString ( ) . ToLowerInvariant ( ) } ", mutatorConfig ) ;
262
+ }
263
+
220
264
result . Add (
221
265
$ "kustomization.{ format . ToString ( ) . ToLowerInvariant ( ) } ",
222
266
new KustomizationConfig
@@ -229,6 +273,9 @@ internal static async Task Handler(IAnsiConsole console, InvocationContext ctx)
229
273
validatorConfig . Webhooks . Any ( )
230
274
? $ "validators.{ format . ToString ( ) . ToLowerInvariant ( ) } "
231
275
: string . Empty ,
276
+ mutatorConfig . Webhooks . Any ( )
277
+ ? $ "mutators.{ format . ToString ( ) . ToLowerInvariant ( ) } "
278
+ : string . Empty ,
232
279
} . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) . ToList ( ) ,
233
280
CommonLabels = new Dictionary < string , string > { { "operator-element" , "operator-instance" } , } ,
234
281
ConfigMapGenerator = new List < KustomizationConfigMapGenerator >
0 commit comments