How trendyol/kink works
The “kink” project is a command-line tool written in Go that is designed to manage KinD clusters running inside Kubernetes pods. In essence, it acts as a wrapper around Docker images that provide the environment for running KinD clusters in Kubernetes. The tool creates, lists, and deletes these clusters by interfacing with Kubernetes (for creating pods and services) and by using pre-built Docker images tailored for different Kubernetes and Docker versions.
Main Components
• CLI Application Layer: This is the primary “kink” binary that users interact with. The files under the “cmd” directory (e.g., run.go, delete.go, list.go, etc.) illustrate that the project parses user commands and dispatches actions.
• Docker Images: Under the “docker-images” directory, you have various Dockerfiles and Makefiles for creating images (for dind, kind-cluster, systemd, webhook-executor, etc.). These images encapsulate the runtime environment for running KinD clusters as pods.
• Kubernetes Integration: The project uses Kubernetes API objects (pods and services) to create and manage KinD clusters. The package under “pkg/kubernetes” hints at Kubernetes interactions (e.g., setting up services, managing node IP addresses, applying labels for multi-tenancy).
• Supporting Libraries: The “pkg/types” provides custom types, likely to help define the structure of cluster configurations or other data passed between components.
• CI/CD and Deployment: The “.github” workflows and configuration files (like .golangci.yml, goreleaser configuration, Makefile, etc.) show that the project is developed with continuous integration, linting, testing, and release management in mind.
Relationships and Data Flow
• User Commands: The CLI layer (triggered based on commands such as “run”, “list”, “delete”) processes inputs and communicates with the core logic in the cmd/ directory.
• Command Processing: The application logic then determines which Docker image to use (as per the Docker images under the docker-images folder) and constructs the necessary Kubernetes objects (using helper functions within pkg/kubernetes).
• Kubernetes Operations: The system then makes API calls to the Kubernetes cluster to create pods (which run KinD clusters) and associated services, using labels to enable multi-tenancy and secure access.
• Docker Image Handling: Docker images are built, stored, and referenced during runtime based on the version or configuration chosen by the user. The repository also includes Docker configurations to support development and integration tests.
• CI/CD/Automation: The repository’s CI/CD configurations (under .github/workflows) indicate automated testing, code analysis (codeql), and release processes based on the Go code base.
Architectural Patterns and Design Principles
• Layered Architecture: There’s a clear separation between the CLI front-end (user interaction) and the underlying orchestration logic (Docker image management and Kubernetes API interactions).
• Modularity: Using directories like cmd, pkg, docker-images enables separation of concerns. This modularization simplifies testing, development, and maintenance.
• Containerization and Immutable Infrastructure: The project employs Docker images as reproducible, pre-packaged runtime environments, ensuring consistency across development, test, and production.
• Extensibility: With various Docker images supporting different environments (different Dockerfiles for Buster, CentOS7, etc.) and support for versioned Kubernetes clusters, the design anticipates evolving requirements and integration with continuous delivery pipelines.