Skip to content

Commit 58571c8

Browse files
feat: switch to CompositeResourceDefinition v2 (#75)
* feat: switch to CompositeResourceDefinition v2 * feat: test webhook
1 parent 1c2828f commit 58571c8

File tree

27 files changed

+2646
-1501
lines changed

27 files changed

+2646
-1501
lines changed

.github/workflows/cicd.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ jobs:
4343
- name: .NET Test
4444
run: dotnet test -c Release --collect:"XPlat Code Coverage" --logger "trx;LogFileName=test-results.trx"
4545

46+
- name: .NET Test SDK
47+
working-directory: tests/Function.SDK.CSharp.Tests
48+
run: dotnet run -c Release -- --report-xunit-trx --report-xunit-trx-filename test-results.trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml
49+
50+
- name: .NET Test Sample
51+
working-directory: tests/Function.SDK.CSharp.Sample.Tests
52+
run: dotnet run -c Release -- --report-xunit-trx --report-xunit-trx-filename test-results.trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml
53+
4654
- name: Coverage
4755
uses: codecov/codecov-action@v5
4856
with:

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Sample",
6+
"type": "coreclr",
7+
"request": "launch",
8+
"preLaunchTask": "build",
9+
"program": "${workspaceFolder}/src/Function.SDK.CSharp.Sample/bin/Debug/net9.0/Function.SDK.CSharp.Sample.dll",
10+
"args": [],
11+
"cwd": "${workspaceFolder}",
12+
"stopAtEntry": false,
13+
"console": "internalConsole"
14+
}
15+
]
16+
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"dotnet.defaultSolution": "Function.SDK.CSharp.sln"
2+
"dotnet.defaultSolution": "Function.SDK.CSharp.sln",
3+
"dotnet.testWindow.useTestingPlatformProtocol": true
34
}

.vscode/tasks.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"/consoleloggerparameters:NoSummary"
11+
],
12+
"problemMatcher": "$msCompile"
13+
},
14+
{
15+
"label": "crossplane",
16+
"command": "crossplane",
17+
"type": "process",
18+
"args": [
19+
"render",
20+
"example/xr.yaml",
21+
"example/composition.yaml",
22+
"example/functions.yaml"
23+
],
24+
"problemMatcher": "$msCompile"
25+
}
26+
]
27+
}

example/functions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: pkg.crossplane.io/v1beta1
1+
apiVersion: pkg.crossplane.io/v1
22
kind: Function
33
metadata:
44
name: function-sdk-csharp-sample
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Function.SDK.CSharp.Sample
2+
{
3+
public class ConversionEndpoint
4+
{
5+
}
6+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Function.SDK.CSharp.Models;
2+
using Function.SDK.CSharp.SourceGenerator.Models.platform.example.com;
3+
using k8s;
4+
using System.Text.Json;
5+
6+
namespace Function.SDK.CSharp.Sample
7+
{
8+
public static class ConversionWebhook
9+
{
10+
public static V1ConversionReview Convert(V1ConversionReview conversion)
11+
{
12+
if (conversion.Kind == V1alpha2XStorageBucket.KubeKind
13+
&& conversion.ApiVersion == V1alpha2XStorageBucket.KubeApiVersion
14+
&& conversion.Request?.DesiredApiVersion == V1alpha1XStorageBucket.KubeApiVersion
15+
)
16+
{
17+
foreach (var item in conversion.Request.Objects)
18+
{
19+
var source = KubernetesJson.Deserialize<V1alpha2XStorageBucket>(item.GetRawText());
20+
source.ApiVersion = V1alpha1XStorageBucket.KubeApiVersion;
21+
22+
var converted = JsonSerializer.Deserialize<JsonElement>(KubernetesJson.Serialize(source));
23+
24+
conversion.Response.ConvertedObjects.Add(converted);
25+
}
26+
27+
conversion.Response.Uid = conversion.Request.Uid;
28+
}
29+
else
30+
{
31+
conversion.Response.Result.Status = V1ConversionReviewResponseStatusEnum.Failure;
32+
conversion.Response.Result.Message = "Unknown Version";
33+
}
34+
35+
return conversion;
36+
}
37+
}
38+
}

src/Function.SDK.CSharp.Sample/Function.SDK.CSharp.Sample.csproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,36 @@
99
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
1010
<IsPackable>false</IsPackable>
1111
<DockerfileRunArguments>-p 9443:9443</DockerfileRunArguments>
12+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
13+
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
1214
</PropertyGroup>
1315

16+
<ItemGroup>
17+
<!-- Exclude the output of source generators from the compilation, show it in the IDE -->
18+
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
19+
<None Include="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
20+
</ItemGroup>
21+
1422
<ItemGroup>
1523
<AdditionalFiles Include="*.yaml" />
16-
<None Include="xrd.schema.json" />
24+
<Content Remove="apiextensions.schema.json" />
1725
<Content Remove="xrd.schema.json" />
1826
</ItemGroup>
1927

2028
<ItemGroup>
2129
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
22-
<PackageReference Include="KubernetesCRDModelGen.Models.crossplane.io" Version="1.0.0-alpha.591" />
23-
<PackageReference Include="KubernetesCRDModelGen.Models.azure.upbound.io" Version="1.0.0-alpha.591" />
24-
<PackageReference Include="KubernetesCRDModelGen.SourceGenerator" Version="1.0.0-alpha.591" />
30+
<PackageReference Include="KubernetesCRDModelGen.Models.crossplane.io" Version="1.0.0-alpha.592" />
31+
<PackageReference Include="KubernetesCRDModelGen.Models.azure.upbound.io" Version="1.0.0-alpha.592" />
32+
<PackageReference Include="KubernetesCRDModelGen.SourceGenerator" Version="1.0.0-alpha.592" />
2533
</ItemGroup>
2634

2735
<ItemGroup>
2836
<ProjectReference Include="..\Function.SDK.CSharp.SourceGenerator\Function.SDK.CSharp.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
2937
<ProjectReference Include="..\Function.SDK.CSharp\Function.SDK.CSharp.csproj" />
3038
</ItemGroup>
3139

40+
<ItemGroup>
41+
<Folder Include="Generated\Function.SDK.CSharp.SourceGenerator\Function.SDK.CSharp.SourceGenerator.SourceGenerator\" />
42+
</ItemGroup>
43+
3244
</Project>

0 commit comments

Comments
 (0)