@@ -11,13 +11,47 @@ custom operator yourself.
11
11
12
12
- ` Entity ` : A model - an entity - that is used in kubernetes. An entity defines the CRD.
13
13
- ` 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".
14
46
15
47
## How To Use
16
48
17
49
Using this sdk is pretty simple:
18
50
51
+ - Create a new asp.net core application
19
52
- Install the package
20
- - Map the main function
53
+ - Replace the ` Run ` function in ` Program.ch `
54
+ - Add the operator to ` Startup.cs `
21
55
- Write entities / controllers / finalizers
22
56
- Go.
23
57
@@ -29,27 +63,54 @@ dotnet add package KubeOps
29
63
30
64
That's it.
31
65
32
- ### Map the main function
66
+ ### Replace the Run function
33
67
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) ` :
35
69
36
70
``` csharp
37
71
public static class Program
38
72
{
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
+ });
48
81
}
49
82
```
50
83
51
84
This adds the default commands (like run and the code generators) to your app.
52
85
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
+
53
114
### Write Entities
54
115
55
116
A custom entity could be:
@@ -129,7 +190,8 @@ public class FooFinalizer : ResourceFinalizerBase<Foo>
129
190
And can be added to a resource with:
130
191
131
192
``` csharp
132
- await resource .RegisterFinalizer <FooFinalizer , Foo >();
193
+ // in a resource controller
194
+ await AttachFinalizer <TestEntityFinalizer >(resource );
133
195
```
134
196
135
197
After the finalizer ran successfully on a resource, it is unregistered
0 commit comments