How manomanotech/kubernetes-node-specific-sizing works
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).