Skip to content

Commit 6a2f1a2

Browse files
wip: updated the readme with some introduction and images
1 parent b731c59 commit 6a2f1a2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Readme.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## The Architecture of Controllers
2+
Since controllers are in charge of meeting the desired state of the resources in Kubernetes, they somehow need to be informed about the changes on the resources and perform certain operations if needed. For this, controllers follow a special architecture to
3+
4+
1) observe the resources,
5+
2) inform any events (updating, deleting, adding) done on the resources,
6+
3) keep a local cache to decrease the load on API Server,
7+
4) keep a work queue to pick up events,
8+
5) run workers to perform reconciliation on resources picked up from work queue.
9+
10+
<a href="https://www.nakamasato.com/kubernetes-training/kubernetes-operator/client-go/informer/" >
11+
<h4 class="text-yellow-300 text-lg">Ref: Official Docs</h4>
12+
</a>
13+
<a href="https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md">
14+
<h4 class="text-yellow-300 text-lg">Writing Controllers (Imp)</h4>
15+
</a>
16+
17+
# Factory & Informers
18+
19+
![image](https://github.com/user-attachments/assets/bb09fdaf-a1d8-4f9b-bfd4-a7914ebe6eba)
20+
21+
# Single Informer
22+
23+
![image](https://github.com/user-attachments/assets/bfc1720a-aab4-4595-bb4b-9559a3e98d74)
24+
25+
![image](https://github.com/user-attachments/assets/1af2d969-5b93-40f4-b375-219342c16041)
26+
27+
28+
[//]: # (https://github.com/user-attachments/assets/851d2b2b-d268-4894-a15a-dbe8b501b3cc)
29+
30+
## Definition : Informer
31+
32+
Informer monitors the changes of target resource. An informer is created for each of the target resources if you need to handle multiple resources (e.g. podInformer, deploymentInformer).
33+
34+
35+
36+
```md
37+
1) Initialize the Controller
38+
* The NewController function sets up the Kubernetes controller with a work queue, informer, and WebSocket connection.
39+
* It listens for Deployment events (Add, Update, Delete) and enqueues them.
40+
41+
2) Run the Controller
42+
* The Run method waits for cache synchronization and starts the worker loop.
43+
* It continuously processes events from the work queue.
44+
45+
3) Process Deployment Events
46+
* The processItem method retrieves Deployment events from the queue and determines the necessary action.
47+
* It fetches the Deployment details and handles errors, deletions, and updates.
48+
49+
4) Handle Deployment Changes
50+
* `handleAdd`, `handleUpdate`, and `handleDel` respond to Deployment changes.
51+
* Updates track Replica count and Image changes and send logs via WebSocket.
52+
53+
5) Send Updates via WebSocket
54+
* The updateLogs function logs and sends JSON messages about Deployment changes.
55+
* The WebSocket connection ensures real-time updates for external systems.

0 commit comments

Comments
 (0)