|
1 |
| -using System.Linq; |
| 1 | +using System; |
| 2 | +using System.Linq; |
2 | 3 | using System.Reflection;
|
3 | 4 | using KubeOps.Operator.Builder;
|
4 |
| -using KubeOps.Operator.Services; |
5 | 5 | using KubeOps.Operator.Webhooks;
|
6 | 6 | using Microsoft.AspNetCore.Builder;
|
7 | 7 | using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
@@ -45,32 +45,39 @@ public static void UseKubernetesOperator(
|
45 | 45 | .CreateLogger("ApplicationStartup");
|
46 | 46 |
|
47 | 47 | using var scope = app.ApplicationServices.CreateScope();
|
48 |
| - var locator = scope.ServiceProvider.GetRequiredService<ResourceLocator>(); |
| 48 | + var componentRegistrar = scope.ServiceProvider.GetRequiredService<IComponentRegistrar>(); |
| 49 | + var webhookMetadataBuilder = scope.ServiceProvider.GetRequiredService<IWebhookMetadataBuilder>(); |
49 | 50 |
|
50 |
| - foreach (var (validatorType, resourceType) in locator.ValidatorTypes) |
| 51 | + foreach (var wh in componentRegistrar.ValidatorRegistrations) |
51 | 52 | {
|
| 53 | + (Type validatorType, Type entityType) = wh; |
| 54 | + |
52 | 55 | var validator = scope.ServiceProvider.GetRequiredService(validatorType);
|
53 | 56 | var registerMethod = typeof(IAdmissionWebhook<,>)
|
54 |
| - .MakeGenericType(resourceType, typeof(ValidationResult)) |
| 57 | + .MakeGenericType(entityType, typeof(ValidationResult)) |
55 | 58 | .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
|
56 | 59 | .First(m => m.Name == "Register");
|
57 | 60 | registerMethod.Invoke(validator, new object[] { endpoints });
|
58 |
| - var (name, endpoint) = Webhooks.Webhooks.Metadata<ValidationResult>(validator, resourceType); |
| 61 | + var (name, endpoint) = |
| 62 | + webhookMetadataBuilder.GetMetadata<ValidationResult>(validator, entityType); |
59 | 63 | logger.LogInformation(
|
60 | 64 | @"Registered validation webhook ""{name}"" under ""{endpoint}"".",
|
61 | 65 | name,
|
62 | 66 | endpoint);
|
63 | 67 | }
|
64 | 68 |
|
65 |
| - foreach (var (mutatorType, resourceType) in locator.MutatorTypes) |
| 69 | + foreach (var wh in componentRegistrar.MutatorRegistrations) |
66 | 70 | {
|
| 71 | + (Type mutatorType, Type entityType) = wh; |
| 72 | + |
67 | 73 | var mutator = scope.ServiceProvider.GetRequiredService(mutatorType);
|
68 | 74 | var registerMethod = typeof(IAdmissionWebhook<,>)
|
69 |
| - .MakeGenericType(resourceType, typeof(MutationResult)) |
| 75 | + .MakeGenericType(entityType, typeof(MutationResult)) |
70 | 76 | .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
|
71 | 77 | .First(m => m.Name == "Register");
|
72 | 78 | registerMethod.Invoke(mutator, new object[] { endpoints });
|
73 |
| - var (name, endpoint) = Webhooks.Webhooks.Metadata<MutationResult>(mutator, resourceType); |
| 79 | + var (name, endpoint) = |
| 80 | + webhookMetadataBuilder.GetMetadata<MutationResult>(mutator, entityType); |
74 | 81 | logger.LogInformation(
|
75 | 82 | @"Registered mutation webhook ""{name}"" under ""{endpoint}"".",
|
76 | 83 | name,
|
|
0 commit comments