Skip to content

Commit

Permalink
feat(web-operator): Add validation webhooks. (#631)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This overhauls the way
webhooks worked. Webhooks now run
with normal ASP.net ApiControllers.
To use a webhook, refer to the documentation.
Basically, create a subclass of the validation
webhook class and decorate it with the
correct validation attribute. Then, the
webhook will run. Other elements
like automatic install will follow this
preview release.
  • Loading branch information
buehler committed Oct 11, 2023
1 parent 0ef92cf commit 31b2ab0
Show file tree
Hide file tree
Showing 78 changed files with 3,067 additions and 2,156 deletions.
4 changes: 0 additions & 4 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"docfx": {
"version": "2.71.0",
"commands": ["docfx"]
},
"kubeops.cli": {
"version": "8.0.0-pre.19",
"commands": ["kubeops"]
}
}
}
16 changes: 15 additions & 1 deletion .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ concurrency:
cancel-in-progress: true

jobs:
build:
name: Building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x

- name: Execute Tests
run: dotnet build --configuration Release

test:
name: Testing
runs-on: ubuntu-latest
Expand All @@ -25,4 +39,4 @@ jobs:
uses: helm/kind-action@v1.8.0

- name: Execute Tests
run: dotnet test --configuration Release
run: dotnet test
40 changes: 20 additions & 20 deletions KubeOps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.Operator.Web", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.Operator.Web.Test", "test\KubeOps.Operator.Web.Test\KubeOps.Operator.Web.Test.csproj", "{BC6E6D3C-6404-4B01-9D72-AA16FEEBFF5C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.Transpiler.Test", "test\KubeOps.Transpiler.Test\KubeOps.Transpiler.Test.csproj", "{47914451-147D-427E-B150-9C47DBF28F2C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.Transpiler", "src\KubeOps.Transpiler\KubeOps.Transpiler.csproj", "{A793FC08-E76C-448B-BE93-88C137D2C7AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.KubernetesClient", "src\KubeOps.KubernetesClient\KubeOps.KubernetesClient.csproj", "{C2C6FF06-2B9D-4FAC-A039-3DC1E007DE3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.KubernetesClient.Test", "test\KubeOps.KubernetesClient.Test\KubeOps.KubernetesClient.Test.csproj", "{25F767E5-7A74-459B-83CC-39519461F38B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserConfigOperator", "examples\UserConfigOperator\UserConfigOperator.csproj", "{032A7FE0-EDFD-4959-9618-B3A911B163F0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebhookOperator", "examples\WebhookOperator\WebhookOperator.csproj", "{4AD46831-1326-4711-83D0-6D7B4AF403DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.Transpiler", "src\KubeOps.Transpiler\KubeOps.Transpiler.csproj", "{7229B71C-C5A5-41E0-85DB-A331A945703C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubeOps.Transpiler.Test", "test\KubeOps.Transpiler.Test\KubeOps.Transpiler.Test.csproj", "{7F7744B2-CF3F-4309-9C2D-037278017D49}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -74,11 +74,11 @@ Global
{162EE2A9-F8BA-4D52-9D65-67CCDB76EAC9} = {C587731F-8191-4A19-8662-B89A60FE79A1}
{E5012C55-B34E-4672-AF4C-C233B45E8EA2} = {4DB01062-6DC5-4028-BB72-C0619C2F5F2E}
{BC6E6D3C-6404-4B01-9D72-AA16FEEBFF5C} = {C587731F-8191-4A19-8662-B89A60FE79A1}
{47914451-147D-427E-B150-9C47DBF28F2C} = {C587731F-8191-4A19-8662-B89A60FE79A1}
{A793FC08-E76C-448B-BE93-88C137D2C7AB} = {4DB01062-6DC5-4028-BB72-C0619C2F5F2E}
{C2C6FF06-2B9D-4FAC-A039-3DC1E007DE3B} = {4DB01062-6DC5-4028-BB72-C0619C2F5F2E}
{25F767E5-7A74-459B-83CC-39519461F38B} = {C587731F-8191-4A19-8662-B89A60FE79A1}
{032A7FE0-EDFD-4959-9618-B3A911B163F0} = {DC760E69-D0EA-417F-AE38-B12D0B04DE39}
{4AD46831-1326-4711-83D0-6D7B4AF403DB} = {DC760E69-D0EA-417F-AE38-B12D0B04DE39}
{7229B71C-C5A5-41E0-85DB-A331A945703C} = {4DB01062-6DC5-4028-BB72-C0619C2F5F2E}
{7F7744B2-CF3F-4309-9C2D-037278017D49} = {C587731F-8191-4A19-8662-B89A60FE79A1}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E9A0B04E-D90E-4B94-90E0-DD3666B098FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -121,14 +121,6 @@ Global
{BC6E6D3C-6404-4B01-9D72-AA16FEEBFF5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC6E6D3C-6404-4B01-9D72-AA16FEEBFF5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC6E6D3C-6404-4B01-9D72-AA16FEEBFF5C}.Release|Any CPU.Build.0 = Release|Any CPU
{47914451-147D-427E-B150-9C47DBF28F2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47914451-147D-427E-B150-9C47DBF28F2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47914451-147D-427E-B150-9C47DBF28F2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47914451-147D-427E-B150-9C47DBF28F2C}.Release|Any CPU.Build.0 = Release|Any CPU
{A793FC08-E76C-448B-BE93-88C137D2C7AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A793FC08-E76C-448B-BE93-88C137D2C7AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A793FC08-E76C-448B-BE93-88C137D2C7AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A793FC08-E76C-448B-BE93-88C137D2C7AB}.Release|Any CPU.Build.0 = Release|Any CPU
{C2C6FF06-2B9D-4FAC-A039-3DC1E007DE3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2C6FF06-2B9D-4FAC-A039-3DC1E007DE3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2C6FF06-2B9D-4FAC-A039-3DC1E007DE3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -137,9 +129,17 @@ Global
{25F767E5-7A74-459B-83CC-39519461F38B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25F767E5-7A74-459B-83CC-39519461F38B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25F767E5-7A74-459B-83CC-39519461F38B}.Release|Any CPU.Build.0 = Release|Any CPU
{032A7FE0-EDFD-4959-9618-B3A911B163F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{032A7FE0-EDFD-4959-9618-B3A911B163F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{032A7FE0-EDFD-4959-9618-B3A911B163F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{032A7FE0-EDFD-4959-9618-B3A911B163F0}.Release|Any CPU.Build.0 = Release|Any CPU
{4AD46831-1326-4711-83D0-6D7B4AF403DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AD46831-1326-4711-83D0-6D7B4AF403DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AD46831-1326-4711-83D0-6D7B4AF403DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AD46831-1326-4711-83D0-6D7B4AF403DB}.Release|Any CPU.Build.0 = Release|Any CPU
{7229B71C-C5A5-41E0-85DB-A331A945703C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7229B71C-C5A5-41E0-85DB-A331A945703C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7229B71C-C5A5-41E0-85DB-A331A945703C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7229B71C-C5A5-41E0-85DB-A331A945703C}.Release|Any CPU.Build.0 = Release|Any CPU
{7F7744B2-CF3F-4309-9C2D-037278017D49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F7744B2-CF3F-4309-9C2D-037278017D49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F7744B2-CF3F-4309-9C2D-037278017D49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F7744B2-CF3F-4309-9C2D-037278017D49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
7 changes: 1 addition & 6 deletions examples/Operator/Entities/V1TestEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Operator.Entities;

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
public partial class V1TestEntity : CustomKubernetesEntity<V1TestEntity.EntitySpec, V1TestEntity.EntityStatus>
public partial class V1TestEntity : CustomKubernetesEntity<V1TestEntity.EntitySpec>
{
public override string ToString() => $"Test Entity ({Metadata.Name}): {Spec.Username} ({Spec.Email})";

Expand All @@ -15,9 +15,4 @@ public class EntitySpec

public string Email { get; set; } = string.Empty;
}

public class EntityStatus
{
public string Status { get; set; } = string.Empty;
}
}
4 changes: 2 additions & 2 deletions examples/Operator/Operator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KubeOps.Operator\KubeOps.Operator.csproj"/>
<ProjectReference Include="..\..\src\KubeOps.Generator\KubeOps.Generator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\src\KubeOps.Operator\KubeOps.Operator.csproj" />
</ItemGroup>

</Project>
3 changes: 0 additions & 3 deletions examples/Operator/todos.txt

This file was deleted.

47 changes: 0 additions & 47 deletions examples/UserConfigOperator/Controller/V1UserConfigController.cs

This file was deleted.

16 changes: 0 additions & 16 deletions examples/UserConfigOperator/Entities/V1UserConfig.cs

This file was deleted.

23 changes: 0 additions & 23 deletions examples/UserConfigOperator/Program.cs

This file was deleted.

8 changes: 0 additions & 8 deletions examples/UserConfigOperator/Properties/launchSettings.json

This file was deleted.

39 changes: 0 additions & 39 deletions examples/UserConfigOperator/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions examples/UserConfigOperator/UserConfigOperator.csproj

This file was deleted.

6 changes: 0 additions & 6 deletions examples/UserConfigOperator/test_entity.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions examples/WebhookOperator/Controller/V1TestEntityController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using KubeOps.Abstractions.Controller;
using KubeOps.Abstractions.Rbac;

using WebhookOperator.Entities;

namespace WebhookOperator.Controller;

[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
public class V1TestEntityController : IEntityController<V1TestEntity>
{
private readonly ILogger<V1TestEntityController> _logger;

public V1TestEntityController(
ILogger<V1TestEntityController> logger)
{
_logger = logger;
}

public Task ReconcileAsync(V1TestEntity entity)
{
_logger.LogInformation("Reconciling entity {Entity}.", entity);
return Task.CompletedTask;
}

public Task DeletedAsync(V1TestEntity entity)
{
_logger.LogInformation("Deleted entity {Entity}.", entity);
return Task.CompletedTask;
}
}
16 changes: 16 additions & 0 deletions examples/WebhookOperator/Entities/V1TestEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using k8s.Models;

using KubeOps.Abstractions.Entities;

namespace WebhookOperator.Entities;

[KubernetesEntity(Group = "webhook.dev", ApiVersion = "v1", Kind = "TestEntity")]
public partial class V1TestEntity : CustomKubernetesEntity<V1TestEntity.EntitySpec>
{
public override string ToString() => $"Test Entity ({Metadata.Name}): {Spec.Username}";

public class EntitySpec
{
public string Username { get; set; } = string.Empty;
}
}
17 changes: 17 additions & 0 deletions examples/WebhookOperator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using KubeOps.Operator;

var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddKubernetesOperator()
.RegisterComponents();

builder.Services
.AddControllers();

var app = builder.Build();

app.UseRouting();
app.UseDeveloperExceptionPage();
app.MapControllers();

await app.RunAsync();
12 changes: 12 additions & 0 deletions examples/WebhookOperator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"WebhookOperator": {
"commandName": "Project",
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading

0 comments on commit 31b2ab0

Please sign in to comment.