@@ -223,6 +223,174 @@ To ensure compatibility and practicality, Resource Capsules will be selectively
223223 - Implement a Capsule Controller to manage capsule lifecycle within the cluster.
224224 - Integrate with Kubernetes APIs for seamless deployment and scaling.
225225
226+ ## System Architecture
227+
228+ ```
229+ ┌───────────────────────────────────────────────────────────────────────────┐
230+ │ Resource Capsules System │
231+ ├───────────────────────────────────────────────────────────────────────────┤
232+ │ │
233+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────┐ │
234+ │ │ Core Components │ │ Platform Drivers │ │ CLI & Management │ │
235+ │ ├─────────────────┤ ├─────────────────┤ ├─────────────────────┤ │
236+ │ │ │ │ │ │ │ │
237+ │ │ Capsule │ │ Docker │ │ CLI Interface │ │
238+ │ │ ├─ Metadata │ │ Driver │ │ │ │
239+ │ │ ├─ Content │◄───►│ │◄───►│ Management API │ │
240+ │ │ └─ Version │ │ Kubernetes │ │ │ │
241+ │ │ │ │ Driver │ │ Dependency │ │
242+ │ │ Dependencies │ │ │ │ Resolver │ │
243+ │ │ │ │ │ │ │ │
244+ │ └─────────────────┘ └─────────────────┘ └─────────────────────┘ │
245+ │ │
246+ └───────────────────────────────────────────────────────────────────────────┘
247+ ```
248+
249+ ## Class Diagram
250+
251+ ```
252+ ┌──────────────────────┐ ┌──────────────────────┐
253+ │ Capsule │ │ CapsuleManager │
254+ ├──────────────────────┤ ├──────────────────────┤
255+ │ +name: string │ │ +capsules: Map │
256+ │ +version: string │◄──────────┤ │
257+ │ +path: string │ │ +AddCapsule() │
258+ │ +metadata: Map │ │ +GetCapsule() │
259+ └──────────────────────┘ │ +ListCapsules() │
260+ │ +DeleteCapsule() │
261+ ┌──────────────────────┐ └──────────────────────┘
262+ │ CapsuleDependency │ ▲
263+ ├──────────────────────┤ │
264+ │ +sourceName: string │ │
265+ │ +sourceVersion: string│ ┌──────────────────────────┐
266+ │ +targetName: string │ │ │
267+ │ +targetVersion: string│ ┌─────┤ KubernetesCapsuleManager │
268+ │ +isOptional: bool │ │ │ │
269+ └──────────────────────┘ │ ├──────────────────────────┤
270+ ▲ │ │ +client: k8s.Interface │
271+ │ │ │ +namespace: string │
272+ ┌───────────────────────┐ │ │ │
273+ │CapsuleDependencyManager│ │ │ +CreateConfigMapCapsule()│
274+ ├───────────────────────┤ │ │ +GetConfigMapCapsule() │
275+ │ +manager: CapsuleManager│ │ │ +CreateSecretCapsule() │
276+ │ +dependencies: List │◄─┘ │ +GetSecretCapsule() │
277+ │ │ │ +DeleteCapsule() │
278+ │ +AddDependency() │ │ +ListCapsules() │
279+ │ +GetDependencies() │ │ +AttachCapsuleToDeployment()│
280+ │ +ResolveDependencies()│ └──────────────────────────┘
281+ └───────────────────────┘
282+ ```
283+
284+ ## Sequence Diagram: Attaching a Capsule to Kubernetes Deployment
285+
286+ ```
287+ ┌────────┐ ┌────────────────┐ ┌─────────────┐ ┌────────────┐
288+ │ Client │ │ KCapsuleManager│ │ Kubernetes │ │ Deployment │
289+ └───┬────┘ └───────┬────────┘ └──────┬──────┘ └──────┬─────┘
290+ │ │ │ │
291+ │ AttachCapsule │ │ │
292+ │───────────────────────> │ │
293+ │ │ │ │
294+ │ │ Get Deployment │ │
295+ │ │─────────────────────────>│ │
296+ │ │ │ │
297+ │ │ │ Get │
298+ │ │ │──────────────────────> │
299+ │ │ │ │
300+ │ │ │ Return Deployment │
301+ │ │ │<──────────────────────┐│
302+ │ │ │ │
303+ │ │ Return Deployment │ │
304+ │ │<─────────────────────────│ │
305+ │ │ │ │
306+ │ │ Add Volume & Mount │ │
307+ │ │─┐ │ │
308+ │ │ │ │ │
309+ │ │<┘ │ │
310+ │ │ │ │
311+ │ │ Update Deployment │ │
312+ │ │─────────────────────────>│ │
313+ │ │ │ │
314+ │ │ │ Update │
315+ │ │ │──────────────────────> │
316+ │ │ │ │
317+ │ │ │ Confirmation │
318+ │ │ │<──────────────────────┐│
319+ │ │ │ │
320+ │ │ Confirmation │ │
321+ │ │<─────────────────────────│ │
322+ │ │ │ │
323+ │ Success │ │ │
324+ │<─────────────────────── │ │
325+ │ │ │ │
326+ ```
327+
328+ ## Resource Access in Container
329+
330+ ```
331+ ┌─────────────────────────────────────────────────────────────────────┐
332+ │ Container │
333+ │ │
334+ │ ┌─────────────────────┐ ┌─────────────────────────┐ │
335+ │ │ Application │ │ /capsules/ │ │
336+ │ │ │ access │ │ │
337+ │ │ ┌─────────────┐ │◄──────────┤ /capsules/config/1.0/ │ │
338+ │ │ │ Application │ │ │ ├─ config.yaml │ │
339+ │ │ │ Code │ │ │ └─ secrets.yaml │ │
340+ │ │ └─────────────┘ │ │ │ │
341+ │ │ │ │ /capsules/api-keys/2.1/ │ │
342+ │ └─────────────────────┘ │ └─ credentials.json │ │
343+ │ └─────────────────────────┘ │
344+ │ │
345+ └─────────────────────────────────────────────────────────────────────┘
346+ ```
347+
348+ ## Kubernetes Implementation Details
349+
350+ When a Resource Capsule is created in Kubernetes, it's represented as either a ConfigMap or Secret:
351+
352+ ``` yaml
353+ apiVersion : v1
354+ kind : ConfigMap
355+ metadata :
356+ name : app-config-1.0
357+ labels :
358+ capsule.docker.io/name : app-config
359+ capsule.docker.io/version : " 1.0"
360+ data :
361+ config.yaml : |
362+ database:
363+ host: db.example.com
364+ port: 5432
365+ ` ` `
366+
367+ When attached to a Deployment, the following changes are made:
368+
369+ 1. **A volume is added**:
370+ ` ` ` yaml
371+ spec :
372+ template :
373+ spec :
374+ volumes :
375+ - name : capsule-app-config-1.0
376+ configMap :
377+ name : app-config-1.0
378+ ` ` `
379+
380+ 2. **Volume mounts are added to each container**:
381+ ` ` ` yaml
382+ spec :
383+ template :
384+ spec :
385+ containers :
386+ - name : app
387+ # ... other container config ...
388+ volumeMounts :
389+ - name : capsule-app-config-1.0
390+ mountPath : /capsules/app-config/1.0
391+ readOnly : true
392+ ` ` `
393+
226394#### Challenges
227395- **Compatibility**: Ensuring Resource Capsules work alongside existing storage solutions.
228396- **Performance**: Minimizing the performance impact of capsule management in high-load environments.
0 commit comments