-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathCrdGenerator.cs
More file actions
48 lines (42 loc) · 1.69 KB
/
Copy pathCrdGenerator.cs
File metadata and controls
48 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System.Reflection;
using KubeOps.Cli.Output;
using KubeOps.Cli.Transpilation;
using KubeOps.Transpiler;
namespace KubeOps.Cli.Generators;
internal sealed class CrdGenerator(MetadataLoadContext parser, byte[] caBundle,
OutputFormat outputFormat) : IConfigGenerator
{
public void Generate(ResultOutput output)
{
var crds = parser.Transpile(parser.GetEntities(), parser.GetInheritedAttributeResolver()).ToList();
var conversionWebhooks = parser.GetConvertedEntities().ToList();
foreach (var crd in crds)
{
if (conversionWebhooks
.Find(wh => crd.Spec.Group == wh.Group && crd.Spec.Names.Kind == wh.Kind) is not null)
{
crd.Spec.Conversion = new()
{
Strategy = "Webhook",
Webhook = new()
{
ConversionReviewVersions = new[] { "v1" },
ClientConfig = new()
{
CaBundle = caBundle,
Service = new()
{
Path = $"/convert/{crd.Spec.Group}/{crd.Spec.Names.Plural}",
Name = "service",
},
},
},
};
}
output.Add($"{crd.Metadata.Name.Replace('.', '_')}.{outputFormat.GetFileExtension()}", crd);
}
}
}