@@ -10,6 +10,11 @@ of the master api. Those are documented on the
10
10
The following documentation should give the user an overview
11
11
on how to implement a webhook what this implies to the written operator.
12
12
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
+
13
18
## General
14
19
15
20
In general, if your operator contains _ any_ registered (registered in the
@@ -34,6 +39,11 @@ to the normal deployment of the operator will happen:
34
39
When a webhook is registered, the specified operations will
35
40
trigger a POST call to the operator.
36
41
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
+
37
47
> [ !NOTE]
38
48
> Make sure you commit the ` ca.pem ` / ` ca-key.pem ` file.
39
49
> During operator startup (init container) those files
@@ -74,11 +84,12 @@ before it is definitely created / updated or deleted.
74
84
75
85
The implementation of a webhook is fairly simple:
76
86
- 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.
80
90
- 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".
82
93
83
94
> [ !WARNING]
84
95
> The interface contains default implementations for _ ALL_ methods.
@@ -87,7 +98,8 @@ The implementation of a webhook is fairly simple:
87
98
> result.
88
99
> The async methods take precedence over the synchronous ones.
89
100
90
- The return value of the validation methods are ` ValidationResult `
101
+ The return value of the validation methods are
102
+ @"KubeOps.Operator.Webhooks.ValidationResult"
91
103
objects. A result contains a boolean flag if the entity / operation
92
104
is valid or not. It may contain additional warnings (if it is valid)
93
105
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.
97
109
### Example
98
110
99
111
``` c#
100
- public class TestValidator : IValidationWebhook <V2TestEntity >
112
+ public class TestValidator : IValidationWebhook <EntityClass >
101
113
{
102
114
public ValidatedOperations Operations => ValidatedOperations .Create | ValidatedOperations .Update ;
103
115
104
- public ValidationResult Create (V2TestEntity newEntity , bool dryRun ) =>
116
+ public ValidationResult Create (EntityClass newEntity , bool dryRun ) =>
105
117
CheckSpec (newEntity )
106
118
? ValidationResult .Success (" The username may not be foobar." )
107
119
: ValidationResult .Fail (StatusCodes .Status400BadRequest , @" Username is "" foobar"" ." );
108
120
109
- public ValidationResult Update (V2TestEntity _ , V2TestEntity newEntity , bool dryRun ) =>
121
+ public ValidationResult Update (EntityClass _ , EntityClass newEntity , bool dryRun ) =>
110
122
CheckSpec (newEntity )
111
123
? ValidationResult .Success (" The username may not be foobar." )
112
124
: ValidationResult .Fail (StatusCodes .Status400BadRequest , @" Username is "" foobar"" ." );
113
125
114
- private static bool CheckSpec (V2TestEntity entity ) => entity .Spec .Username != " foobar" ;
126
+ private static bool CheckSpec (EntityClass entity ) => entity .Spec .Username != " foobar" ;
115
127
}
116
128
```
117
129
0 commit comments