# manomanotech/kubernetes-node-specific-sizing architecture

> Architecture diagram of the GitHub repository manomanotech/kubernetes-node-specific-sizing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manomanotech/kubernetes-node-specific-sizing
- Repository: https://github.com/manomanotech/kubernetes-node-specific-sizing

## Overview

##### Main Components
- Kubernetes Cluster: Represent the cluster as the runtime environment.
- Webhook Server: The Go-based service that implements the admission webhook (see cmd/webhook.go and deployment manifests, e.g., deploy/mutatingadmissionwebhook.yaml).
- Pod Patcher or Sizer: A sub-component or mode (see cmd/pod_patcher.go) that applies the resource sizing algorithm.
- Configuration & Deployment: The manifests (in the deploy directory) that manage cluster-level resources (ClusterRole, Service, ServiceAccount, etc.).
- Utility/Dev Scripts: The bin directory includes scripts (like dev_toggle.sh, playground.sh) to facilitate development, testing in a K3D playground, and certificate extraction.
- Core Library: The pkg/resource_properties contains the core resource sizing logic and tests.

##### Relationships and Interactions
- Incoming Pod Creation: In the Kubernetes API server, when a pod is created (or updated) – especially for DaemonSets with the given label "node-specific-sizing.manomano.tech/enabled: 'true'" – the request is intercepted by the mutating admission webhook.
- Webhook Handling: The webhook (implemented in cmd/webhook.go) reads the pod’s annotations, computes the new resource values using the defined algorithm (detailed in the README and implemented in pkg/resource_properties), and patches the pod definition.
- Resource Sizing Algorithm: Show this as a processing block, with inputs (pod’s resource values and annotations, node allocatable resources) and outputs (updated container requests and limits).
- Deployment/Management: The deployment manifests in the deploy/ directory are used to deploy and manage the webhook in the cluster. They handle certificate management, ClusterRoles, and the webhook configuration.
- Developer Tools: The utility scripts and Makefile are used for building, local testing, Docker container creation, and cluster deployment.

##### Architectural Patterns and Important Design Principles
- Microservice Pattern: Although the project is not split into multiple microservices, the design does clearly separate concerns – the admission webhook for handling K8s events and the sizing algorithm as a self-contained module.
- Configuration Driven: As configuration occurs via Kubernetes annotations, the design uses declarative principles for pod customization.
- Extensibility: The modular structure (command packages, reusable library logic) makes it easy to extend or adapt the sizing algorithm.

##### Final Elements
- Be detailed yet clear: capture every essential part of the flow from a pod coming into the cluster, being processed (by the webhook, using the algorithm), and being patched accordingly.
- Clearly denote deployment boundaries (e.g., what runs inside the Kubernetes cluster vs. development scripts operating externally).
- Supporting elements such as logs or metrics if applicable (for example, if the project later integrates monitoring for sizing adjustments, even if not specified).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Event
    PCE("Pod Creation Event"):::external

    %% Kubernetes Cluster Components
    subgraph "Kubernetes Cluster"
        KAS("Kubernetes API Server"):::cluster
        DC("Deployment & Configuration (deploy/)"):::deploy
    end

    %% Developer Tools
    subgraph "Developer Tools"
        UDS("Utility/Dev Scripts (bin/)"):::dev
        BDT("Build & Dev Tools (Makefile)"):::dev
    end

    %% Admission Webhook Service Group
    subgraph "Admission Webhook Service"
        WS("Webhook Server (cmd/webhook.go)"):::service
        PRH("Pod Request Handler"):::service
        RSA("Resource Sizing Algorithm"):::module
        PPS("Pod Patcher / Sizer (cmd/pod_patcher.go)"):::module
    end

    %% Flow of Events
    PCE -->|"sends_request"| KAS
    KAS -->|"triggers"| WS
    WS -->|"handles_pod"| PRH
    PRH -->|"computes_resources"| RSA
    RSA -->|"patches_pod"| PPS
    PPS -->|"updates_pod"| KAS

    %% Developer Tools assisting deployment
    BDT -->|"builds_deploys"| DC
    UDS -->|"assists_deployment"| DC

    %% Click Events
    click KAS "https://github.com/manomanotech/kubernetes-node-specific-sizing/blob/main/deploy/mutatingadmissionwebhook.yaml"
    click DC "https://github.com/manomanotech/kubernetes-node-specific-sizing/tree/main/deploy/"
    click WS "https://github.com/manomanotech/kubernetes-node-specific-sizing/blob/main/cmd/webhook.go"
    click PPS "https://github.com/manomanotech/kubernetes-node-specific-sizing/blob/main/cmd/pod_patcher.go"
    click RSA "https://github.com/manomanotech/kubernetes-node-specific-sizing/blob/main/pkg/resource_properties/resource_properties.go"
    click UDS "https://github.com/manomanotech/kubernetes-node-specific-sizing/tree/main/bin/"
    click BDT "https://github.com/manomanotech/kubernetes-node-specific-sizing/tree/main/Makefile"

    %% Styles
    classDef cluster fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef service fill:#9de,stroke:#036,stroke-width:2px;
    classDef module fill:#cfc,stroke:#393,stroke-width:2px;
    classDef deploy fill:#fc9,stroke:#933,stroke-width:2px;
    classDef dev fill:#f99,stroke:#933,stroke-width:2px;
    classDef external fill:#eee,stroke:#666,stroke-dasharray: 5 5,stroke-width:2px;
```
