Skip to content

Commit fdb744e

Browse files
committed
docs: add better documentation for webhooks
1 parent 6633845 commit fdb744e

File tree

9 files changed

+72
-29
lines changed

9 files changed

+72
-29
lines changed

docs/docfx.json

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
{
44
"src": [
55
{
6-
"files": ["**/*.csproj"],
6+
"files": [
7+
"**/*.csproj"
8+
],
79
"src": "../src/KubeOps"
810
}
911
],
@@ -12,7 +14,9 @@
1214
{
1315
"src": [
1416
{
15-
"files": ["**/*.csproj"],
17+
"files": [
18+
"**/*.csproj"
19+
],
1620
"src": "../src/KubeOps.Testing"
1721
}
1822
],
@@ -22,24 +26,47 @@
2226
"build": {
2327
"content": [
2428
{
25-
"files": ["kube-ops/**.yml", "kube-ops/index.md"]
29+
"files": [
30+
"kube-ops/**.yml",
31+
"kube-ops/index.md"
32+
]
2633
},
2734
{
28-
"files": ["kube-ops-testing/**.yml", "kube-ops-testing/index.md"]
35+
"files": [
36+
"kube-ops-testing/**.yml",
37+
"kube-ops-testing/index.md"
38+
]
2939
},
3040
{
31-
"files": ["docs/**.md", "docs/**/toc.yml", "toc.yml", "*.md"]
41+
"files": [
42+
"docs/**.md",
43+
"docs/**/toc.yml",
44+
"toc.yml",
45+
"*.md"
46+
]
3247
}
3348
],
3449
"resource": [
3550
{
36-
"files": ["images/**"]
51+
"files": [
52+
"images/**"
53+
]
3754
}
3855
],
56+
"xrefService": [
57+
"https://xref.docs.microsoft.com/query?uid={uid}"
58+
],
59+
"globalMetadata": {
60+
"_appTitle": "KubeOps Documentation",
61+
"_appFooter": "© Copyright 2021 Christoph Bühler",
62+
"_appFaviconPath": "images/favicon.png"
63+
},
3964
"dest": "public",
4065
"sitemap": {
4166
"baseUrl": "https://buehler.github.io/dotnet-operator-sdk/"
4267
},
43-
"template":["default","templates/discordfx"]
68+
"template": [
69+
"statictoc"
70+
]
4471
}
4572
}

docs/docs/commands.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ Here is a brief overview over the available commands:
2929
- `uninstall`: uninstall the CRDs for the solution from the cluster
3030
- `generator`: entry command for generator commands (i.e. has subcommands), all commands
3131
output their result to the stdout or the given output path
32-
- `crd`: Generate the CRDs
33-
- `docker`: Generate the dockerfile
34-
- `installer`: Generate the installer files (i.e. kustomization yaml) for the operator
35-
- `operator`: Generate the deployment for the operator
36-
- `rbac`: Generate the needed rbac roles / role bindings for the operator
32+
- `crd`: generate the CRDs
33+
- `docker`: generate the dockerfile
34+
- `installer`: generate the installer files (i.e. kustomization yaml) for the operator
35+
- `operator`: generate the deployment for the operator
36+
- `rbac`: generate the needed rbac roles / role bindings for the operator
37+
- `webhook`: entry command for webhook related operations
38+
- `install`: generate the server certificate and install the service / webhook registration
39+
- `register`: register the currently implemented webhooks to the currently selected cluster
3740

3841
## Code Generation
3942

docs/docs/features.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ As of now, the operator sdk supports - roughly - the following features:
1616
- Deleted
1717
- AddFinalizer
1818
- Finalizers for entities
19+
- Webhooks
20+
- Validation / validators
1921
- Prometheus metrics for queues / caches / watchers
2022
- Healthchecks, split up to "readiness" and "liveness" (or both)
2123
- Commands for the operator (for exact documentation run: `dotnet run -- --help`)

docs/docs/getting_started.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ public class Startup
105105

106106
When you completed this basic setup instructions, the next steps may or may not include:
107107

108-
- Writting entities: Find more under ["Entites"](./entities.md)
109-
- Writting controllers: Find more under ["Controller"](./controller.md)
110-
- Writting finalizer: Find more under ["Finalizer"](./finalizer.md)
108+
- Writing entities: Find more under ["Entites"](./entities.md)
109+
- Writing controllers: Find more under ["Controller"](./controller.md)
110+
- Writing finalizer: Find more under ["Finalizer"](./finalizer.md)
111+
- Writing webhooks: Find more under ["Webhooks"](./webhooks.md)
111112
- Customize the operator: Find more under ["Settings"](./settings.md)
112-
- Writting and using utilities: Find more under ["Utilities"](./utilities.md)
113+
- Writing and using utilities: Find more under ["Utilities"](./utilities.md)

docs/docs/ms_build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You'll find the configurations and targets here:
99

1010
An example of such a target is:
1111

12-
[!code-xml[KubeOps.targets](../../src/KubeOps/Build/KubeOps.targets?range=2-17&dedent=4&highlight=2-7)]
12+
[!code-xml[KubeOps.targets](../../src/KubeOps/Build/KubeOps.targets?range=45-53&dedent=4&highlight=2-7)]
1313

1414
They can be configured with the prop settings described below.
1515
The props file just defines the defaults.

docs/docs/testing.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ All methods do return `null` or the object that was passed
6060
into the mocked class. There are five different object
6161
references that can be set to return certain results upon calling the client.
6262

63-
[!code-csharp[TestStartup.cs](../../src/KubeOps.Testing/MockKubernetesClient.cs?range=13-14,17-25,88&highlight=3-11)]
64-
6563
> [!WARNING]
6664
> The mocked client is injected as singleton, this means
6765
> the used "result" references can vary. Be aware of that

docs/docs/webhooks.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ of the master api. Those are documented on the
1010
The following documentation should give the user an overview
1111
on how to implement a webhook what this implies to the written operator.
1212

13+
At the courtesy of the kubernetes website, here is a diagram of the
14+
process that runs for admission controllers and api requests:
15+
16+
![admission controller phases](https://d33wubrfki0l68.cloudfront.net/af21ecd38ec67b3d81c1b762221b4ac777fcf02d/7c60e/images/blog/2019-03-21-a-guide-to-kubernetes-admission-controllers/admission-controller-phases.png)
17+
1318
## General
1419

1520
In general, if your operator contains _any_ registered (registered in the
@@ -34,6 +39,11 @@ to the normal deployment of the operator will happen:
3439
When a webhook is registered, the specified operations will
3540
trigger a POST call to the operator.
3641

42+
> [!NOTE]
43+
> The certificates are generated with [cfssl](https://github.com/cloudflare/cfssl),
44+
> an amazing tool from cloudflare that helps with the general hassle
45+
> of creating CAs and certificates in general.
46+
3747
> [!NOTE]
3848
> Make sure you commit the `ca.pem` / `ca-key.pem` file.
3949
> During operator startup (init container) those files
@@ -74,11 +84,12 @@ before it is definitely created / updated or deleted.
7484

7585
The implementation of a webhook is fairly simple:
7686
- Create a class somewhere in your project.
77-
- Implement the `IValidationWebhook{TEntity}` interface.
78-
- Define the `Operations` (from the interface) that the validator
79-
is interested in.
87+
- Implement the @"KubeOps.Operator.Webhooks.IValidationWebhook`1" interface.
88+
- Define the @"KubeOps.Operator.Webhooks.IValidationWebhook.Operations"
89+
(from the interface) that the validator is interested in.
8090
- Overwrite the corresponding methods.
81-
- Register it in the `IOperatorBuilder` with `AddValidationWebhook`.
91+
- Register it in the @"KubeOps.Operator.Builder.IOperatorBuilder"
92+
with @"KubeOps.Operator.Builder.IOperatorBuilder.AddValidationWebhook``1".
8293

8394
> [!WARNING]
8495
> The interface contains default implementations for _ALL_ methods.
@@ -87,7 +98,8 @@ The implementation of a webhook is fairly simple:
8798
> result.
8899
> The async methods take precedence over the synchronous ones.
89100
90-
The return value of the validation methods are `ValidationResult`
101+
The return value of the validation methods are
102+
@"KubeOps.Operator.Webhooks.ValidationResult"
91103
objects. A result contains a boolean flag if the entity / operation
92104
is valid or not. It may contain additional warnings (if it is valid)
93105
that are presented to the user if the kubernetes api supports it.
@@ -97,21 +109,21 @@ as well as a custom error message that is presented to the user.
97109
### Example
98110

99111
```c#
100-
public class TestValidator : IValidationWebhook<V2TestEntity>
112+
public class TestValidator : IValidationWebhook<EntityClass>
101113
{
102114
public ValidatedOperations Operations => ValidatedOperations.Create | ValidatedOperations.Update;
103115

104-
public ValidationResult Create(V2TestEntity newEntity, bool dryRun) =>
116+
public ValidationResult Create(EntityClass newEntity, bool dryRun) =>
105117
CheckSpec(newEntity)
106118
? ValidationResult.Success("The username may not be foobar.")
107119
: ValidationResult.Fail(StatusCodes.Status400BadRequest, @"Username is ""foobar"".");
108120

109-
public ValidationResult Update(V2TestEntity _, V2TestEntity newEntity, bool dryRun) =>
121+
public ValidationResult Update(EntityClass _, EntityClass newEntity, bool dryRun) =>
110122
CheckSpec(newEntity)
111123
? ValidationResult.Success("The username may not be foobar.")
112124
: ValidationResult.Fail(StatusCodes.Status400BadRequest, @"Username is ""foobar"".");
113125

114-
private static bool CheckSpec(V2TestEntity entity) => entity.Spec.Username != "foobar";
126+
private static bool CheckSpec(EntityClass entity) => entity.Spec.Username != "foobar";
115127
}
116128
```
117129

docs/images/favicon.png

24 KB
Loading

docs/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
href: kube-ops-testing/
99
homepage: kube-ops-testing/index.md
1010
- name: Changelog
11-
href: CHANGELOG.md
11+
href: https://github.com/buehler/dotnet-operator-sdk/releases

0 commit comments

Comments
 (0)