Skip to content

Commit 59b131b

Browse files
authored
Merge pull request #527 from hasheddan/examples-readme
📖 Examples README
2 parents c49d570 + 8030432 commit 59b131b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Examples
2+
3+
These two examples represent the usage of `controller-runtime` libraries for built-in Kubernetes resources as well as custom resources.
4+
5+
### builtins/
6+
7+
This example implements a custom controller and webhooks for the *existing* ReplicaSet resource.
8+
9+
* `controller.go`: implements a reconciler for ReplicaSets
10+
* `mutatingwebhook.go`: implements a mutating webhook that adds an annotation to every incoming Pod ("example-mutating-admission-webhook" = "foo")
11+
* `validatingwebhook.go`: implements a validating webhook that checks to see if a Pod has the aforementioned annotation
12+
* `main.go`
13+
1. Creates a new manager
14+
2. Creates a new controller that watches both ReplicaSets and Pods and reconciles the objects with the implemented reconciler
15+
3. Registers the mutating and validating webhooks with the manager
16+
4. Starts the manager
17+
18+
### crd/
19+
20+
This example implements a *new* Kubernetes resource, ChaosPod, and creates a custom controller that watches it and webhooks that mutate and validate.
21+
22+
* `pkg/`
23+
* `resource.go`: defines the schema for the ChaosPod API and implements validate and mutate webhooks
24+
* `groupversion_info.go`: specifies the Group and Version for the ChaosPod API
25+
* `zz_generated.deepcopy.go`: deep copy functions generated by kubebuilder
26+
* `main.go`
27+
1. Creates a new manager
28+
2. Adds ChaosPod resource to the manager's schema
29+
3. Implements a reconciler to execute the desired behavior of the ChaosPod API
30+
4. Creates a new controller that watches ChaosPods and reconciles the objects with the implemented reconciler
31+
5. Adds ChaosPod webhooks to manager
32+
6. Starts the manager
33+
34+
## Deploying and Running
35+
36+
To install and run the provided examples, see the Kubebuilder [Quick Start](https://book.kubebuilder.io/quick-start.html).

0 commit comments

Comments
 (0)