Skip to content

Commit bcab6a3

Browse files
Christoph Bühlerbuehler
authored andcommitted
docs: adjust readme to reflect new setup
1 parent f8f9cce commit bcab6a3

File tree

1 file changed

+75
-13
lines changed

1 file changed

+75
-13
lines changed

README.md

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,47 @@ custom operator yourself.
1111

1212
- `Entity`: A model - an entity - that is used in kubernetes. An entity defines the CRD.
1313
- `Resource`: An instance of an entity.
14+
- `Controller` or `ResourceController`: An instance of a resource manager
15+
that is responsible for the reconciliation of an entity.
16+
- `Finalizer`: A special resource manager that is attached to the entity
17+
via identifier. The finalizers are called when an entity is deleted
18+
on kubernetes.
19+
- `CRD`: CustomResourceDefinition of kubernetes.
20+
21+
## Features
22+
23+
As of now, the operator sdk supports - roughly - the following features:
24+
25+
- Controller with all operations of an entity
26+
- Created
27+
- Updated
28+
- NotModified
29+
- StatusModified
30+
- Deleted
31+
- Finalizers for entities
32+
- Prometheus metrics for queues / caches / watchers
33+
- Healthchecks, split up to "readiness" and "liveness" (or both)
34+
- Commands for the operator (for exact documentation run: `dotnet run -- --help`)
35+
- `Run`: Start the operator and run the asp.net application
36+
- `Install`: Install the found CRD's into the actual configured
37+
cluster in your kubeconfig
38+
- `Uninstall`: Remove the CRDs from your cluster
39+
- `Generate CRD`: Generate the yaml for your CRDs
40+
- `Generate Docker`: Generate a dockerfile for your operator
41+
- `Generate Installer`: Generate a kustomization yaml for your operator
42+
- `Generate Operator`: Generate the yaml for your operator (rbac / role / etc)
43+
- `Generate RBAC`: Generate rbac roles for your CRDs
44+
45+
Other features and ideas are listed in the repositories "issues".
1446

1547
## How To Use
1648

1749
Using this sdk is pretty simple:
1850

51+
- Create a new asp.net core application
1952
- Install the package
20-
- Map the main function
53+
- Replace the `Run` function in `Program.ch`
54+
- Add the operator to `Startup.cs`
2155
- Write entities / controllers / finalizers
2256
- Go.
2357

@@ -29,27 +63,54 @@ dotnet add package KubeOps
2963

3064
That's it.
3165

32-
### Map the main function
66+
### Replace the Run function
3367

34-
In your `Program.cs` file, map the main function to a kubernetes operator:
68+
In your `Program.cs` file, replace `Build().Run()` with `Build().RunOperator(args)`:
3569

3670
```csharp
3771
public static class Program
3872
{
39-
public static Task<int> Main(string[] args) =>
40-
new KubernetesOperator()
41-
.ConfigureServices(
42-
services =>
43-
{
44-
// add resource controllers here
45-
// add finalizers here
46-
})
47-
.Run(args);
73+
public static Task<int> Main(string[] args) => CreateHostBuilder(args).Build().RunOperator(args);
74+
75+
private static IHostBuilder CreateHostBuilder(string[] args) =>
76+
Host.CreateDefaultBuilder(args)
77+
.ConfigureWebHostDefaults(webBuilder =>
78+
{
79+
webBuilder.UseStartup<Startup>();
80+
});
4881
}
4982
```
5083

5184
This adds the default commands (like run and the code generators) to your app.
5285

86+
### Add to Startup.cs
87+
88+
```csharp
89+
public class Startup
90+
{
91+
/* snip... */
92+
public void ConfigureServices(IServiceCollection services)
93+
{
94+
services
95+
.AddKubernetesOperator(s => s.Name = "test-operator") // config / settings here
96+
.AddFinalizer<TestEntityFinalizer>()
97+
.AddController<TestController>(); // Add controllers / finalizers / ... here
98+
99+
// your own dependencies
100+
services.AddTransient<IManager, TestManager.TestManager>();
101+
}
102+
103+
public void Configure(IApplicationBuilder app)
104+
{
105+
// fire up the mappings for the operator
106+
// this is technically not needed, but if you don't call this
107+
// function, the healthchecks and mappings are not
108+
// mapped to endpoints (therefore not callable)
109+
app.UseKubernetesOperator();
110+
}
111+
}
112+
```
113+
53114
### Write Entities
54115

55116
A custom entity could be:
@@ -129,7 +190,8 @@ public class FooFinalizer : ResourceFinalizerBase<Foo>
129190
And can be added to a resource with:
130191

131192
```csharp
132-
await resource.RegisterFinalizer<FooFinalizer, Foo>();
193+
// in a resource controller
194+
await AttachFinalizer<TestEntityFinalizer>(resource);
133195
```
134196

135197
After the finalizer ran successfully on a resource, it is unregistered

0 commit comments

Comments
 (0)