Skip to content

Commit 8bcdba1

Browse files
authored
Operator application approch (#6)
1 parent 07d71b4 commit 8bcdba1

File tree

59 files changed

+1767
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1767
-607
lines changed

K8sOperator.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "K8sOperator.NET", "src\K8sO
3030
EndProject
3131
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{ED5FF81E-F3EA-4BEF-9B72-31A24F9386E3}"
3232
EndProject
33-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleOperator", "examples\SimpleOperator\SimpleOperator.csproj", "{B7588B10-BDD2-4622-BB16-18EFFBE7BE25}"
33+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleOperator", "examples\SimpleOperator\SimpleOperator.csproj", "{B7588B10-BDD2-4622-BB16-18EFFBE7BE25}"
3434
EndProject
3535
Global
3636
GlobalSection(SolutionConfigurationPlatforms) = preSolution

examples/SimpleOperator/Program.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1+
using K8sOperator.NET;
12
using K8sOperator.NET.Extensions;
3+
using K8sOperator.NET.Generator.Builders;
24
using SimpleOperator.Projects;
35

4-
var builder = Host.CreateApplicationBuilder(args);
6+
var builder = OperatorHost.CreateOperatorApplicationBuilder(args);
57

6-
builder.Logging.SetMinimumLevel(LogLevel.Debug);
8+
//builder.WithName("sonarcube-operator");
9+
//builder.WithImage(
10+
// repository: "pmdevers",
11+
// name: "sonarcube-operator",
12+
// tag: "fc5d6122d6ff1057062e368214ddf4cfe34f5d6d"
13+
//);
714

8-
builder.Services.AddK8sOperators(o => {
9-
o.WithGroup("sonarcloud.io");
10-
o.WithVersion("v1alpha1");
11-
});
15+
builder.AddController<TestItemController>()
16+
.WithFinalizer("testitem.local.finalizer");
1217

13-
var app = builder.Build();
14-
15-
app.MapController<ProjectController>()
16-
.WithKind("Project")
17-
.WithPluralName("projects")
18+
builder.AddController<ProjectController>()
1819
.WithFinalizer("project.local.finalizer");
1920

21+
var app = builder.Build();
22+
2023
await app.RunAsync();
24+
25+
26+

examples/SimpleOperator/Projects/Project.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace SimpleOperator.Projects;
55

6+
[KubernetesEntity(Group = "sonarcloud.io", ApiVersion = "v1alpha1", Kind = "Project", PluralName = "projects")]
67
public class Project : CustomResource<Project.Specs, Project.ProjectStatus>
78
{
89
public class Specs

examples/SimpleOperator/Projects/ProjectController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using K8sOperator.NET;
1+
using k8s;
2+
using k8s.Models;
3+
using K8sOperator.NET;
24

35
namespace SimpleOperator.Projects;
46

5-
public class ProjectController(ILoggerFactory logger) : Controller<Project>
7+
8+
public class ProjectController(IKubernetes client, ILoggerFactory logger) : Controller<Project>
69
{
710
private readonly ILogger _logger = logger.CreateLogger<ProjectController>();
811

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using k8s.Models;
2+
using K8sOperator.NET.Generator.Builders;
3+
using K8sOperator.NET.Models;
4+
using static SimpleOperator.Projects.TestItem;
5+
6+
namespace SimpleOperator.Projects;
7+
8+
[KubernetesEntity(Group = "sonarcloud.io", ApiVersion = "v1alpha1", Kind = "TestItem", PluralName = "testitems")]
9+
public class TestItem : CustomResource<TestItemSpec, TestItemStatus>
10+
{
11+
public class TestItemSpec
12+
{
13+
public Scope Scope { get; set; }
14+
public string? String { get; set; }
15+
}
16+
17+
public class TestItemStatus
18+
{
19+
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using K8sOperator.NET;
2+
3+
namespace SimpleOperator.Projects;
4+
5+
public class TestItemController : Controller<TestItem>
6+
{
7+
public override Task AddOrModifyAsync(TestItem resource, CancellationToken cancellationToken)
8+
{
9+
return base.AddOrModifyAsync(resource, cancellationToken);
10+
}
11+
12+
public override Task BookmarkAsync(TestItem resource, CancellationToken cancellationToken)
13+
{
14+
return base.BookmarkAsync(resource, cancellationToken);
15+
}
16+
17+
public override Task DeleteAsync(TestItem resource, CancellationToken cancellationToken)
18+
{
19+
return base.DeleteAsync(resource, cancellationToken);
20+
}
21+
22+
public override Task ErrorAsync(TestItem resource, CancellationToken cancellationToken)
23+
{
24+
return base.ErrorAsync(resource, cancellationToken);
25+
}
26+
27+
public override Task FinalizeAsync(TestItem resource, CancellationToken cancellationToken)
28+
{
29+
return base.FinalizeAsync(resource, cancellationToken);
30+
}
31+
}
Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
1-
{
1+
{
2+
"profiles": {
3+
"Operator": {
4+
"commandName": "Project",
5+
"commandLineArgs": "operator",
6+
"launchBrowser": true,
7+
"environmentVariables": {
8+
"ASPNETCORE_ENVIRONMENT": "Development"
9+
},
10+
"dotnetRunMessages": true,
11+
"applicationUrl": "http://localhost:5276"
12+
},
13+
"install": {
14+
"commandName": "Project",
15+
"commandLineArgs": "install --export",
16+
"launchBrowser": true,
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
},
20+
"dotnetRunMessages": true,
21+
"applicationUrl": "http://localhost:5276"
22+
},
23+
"CLI": {
24+
"commandName": "Project",
25+
"commandLineArgs": "",
26+
"launchBrowser": true,
27+
"environmentVariables": {
28+
"ASPNETCORE_ENVIRONMENT": "Development"
29+
},
30+
"dotnetRunMessages": true,
31+
"applicationUrl": "http://localhost:5276"
32+
},
33+
"IIS Express": {
34+
"commandName": "IISExpress",
35+
"launchBrowser": true,
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
},
241
"$schema": "http://json.schemastore.org/launchsettings.json",
342
"iisSettings": {
443
"windowsAuthentication": false,
@@ -7,23 +46,5 @@
746
"applicationUrl": "http://localhost:36443",
847
"sslPort": 0
948
}
10-
},
11-
"profiles": {
12-
"http": {
13-
"commandName": "Project",
14-
"dotnetRunMessages": true,
15-
"launchBrowser": true,
16-
"applicationUrl": "http://localhost:5276",
17-
"environmentVariables": {
18-
"ASPNETCORE_ENVIRONMENT": "Development"
19-
}
20-
},
21-
"IIS Express": {
22-
"commandName": "IISExpress",
23-
"launchBrowser": true,
24-
"environmentVariables": {
25-
"ASPNETCORE_ENVIRONMENT": "Development"
26-
}
27-
}
2849
}
2950
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<Company>Pmdevers</Company>
8+
<Product>simple-operator</Product>
79
</PropertyGroup>
810

911
<ItemGroup>
1012
<ProjectReference Include="..\..\src\K8sOperator.NET\K8sOperator.NET.csproj" />
1113
</ItemGroup>
1214

15+
1316
</Project>

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
5+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<IsPackable>true</IsPackable>

src/Directory.Packages.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
55
</PropertyGroup>
66
<ItemGroup>
7+
<PackageVersion Include="DotMake.CommandLine" Version="1.8.8" />
78
<PackageVersion Include="KubernetesClient" Version="14.0.9" />
89
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
910
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.10.0" />
11+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
12+
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
1013
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
1114
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
1215
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
1316
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
1417
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
18+
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
19+
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
20+
<PackageVersion Include="SystemTextJsonPatch" Version="3.2.1" />
1521
</ItemGroup>
1622
<ItemGroup>
1723
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="all" />

0 commit comments

Comments
 (0)