How angelabad/node-safe-drainer works
Project Type and Purpose
• The project is an experimental CLI tool that interacts with Kubernetes to safely drain nodes. Its primary function is to cordon nodes and perform a rollout restart of deployments so that even environments with a single pod won’t experience downtime.
• Since this tool directly interacts with Kubernetes (using kubeconfig, performing cordon actions, and rollouts), it essentially serves as an automation/safe-operations utility.
Analyzing the File Structure
• Top-level files: The root has main.go, which is clearly the entry point of the application.
• Directories:
• “client”: Contains client.go and deployment management modules (deployment.go). This part encapsulates the logic that communicates with the Kubernetes API. Test files are present to verify this functionality.
• “utils”: Holds modules for parsing (parse.go, usage.go) and managing job queues (queue.go). These aid in handling command line input, usage information, and potentially controlling concurrency (e.g., limiting maximum concurrent rollouts).
• Other files: The presence of CI/CD configuration files (.github/workflows, .goreleaser.yml, etc.) and changelog/config files – while not directly part of the runtime architecture – indicate that the project follows good DevOps practices.
For this application’s architecture, you want to divide the system into several logical components:
a. Main / Entry Point:
b. Client Component:
• Subdivisions for:
• “Deployment Manager”: Handling deployment operations (client/deployment.go).
• Test modules (client_test.go, deployment_test.go) validate the client functionality.
c. Utilities:
• Parsing and usage (from parse.go and usage.go)
• Queue management for controlling concurrent rollouts (from queue.go)
• These utilities support the main application and client behavior.
d. Kubernetes API (External Service):
Relationships and Interactions
• The main application calls into the Utilities module for parsing/validating command-line options.
• Based on user inputs, main orchestrates a call to the Client module, which handles all interactions with the Kubernetes API.
• The Client module may coordinate multiple asynchronous operations (managed by the queue utility) to limit the number of concurrent rollouts.
• From the CLI (main) to the Utility parsers.
• From the main/control flow to the Client module.
• From the Client module to external Kubernetes API calls.
• It might also be useful to indicate error-handling or logging paths if these are part of the client/utility implementations.
Architectural Patterns/Design Principles
• Separation of concerns is key: The main entry point is kept simple and delegates responsibilities to specialized modules (client and utils).
• The architecture leverages modular design making testing easier (as seen by the several _test.go files).
• Concurrency control is likely used (given the queue utility and a max concurrent jobs option) which is critical for performance when rolling out changes across multiple deployments.