How monimesl/istio-virtualservice-merger works
Project Type and Purpose
• This is a single binary Kubernetes Operator written in Go.
• Purpose: watch custom resources (VirtualServiceMerge CRDs), merge their patches into existing Istio VirtualService resources, and update the target VirtualService in the cluster.
• It uses the controller-runtime (Kubebuilder style) reconciliation loop.
File Structure
Top-level files & directories:
• main.go – entry point, sets up manager & controllers
• api/… – Go types for the CRD (group: istiomerger.monime.sl, version: v1alpha1), VirtualServiceMergeSpec & status types, deep-copy boilerplate.
• controller/… – Controller implementation: watches CRs, reconciler logic, tests.
• manifest/… – YAML for CRD (crd.yaml) and Operator Deployment (operator.yaml).
• hack/… – license boilerplate.
• tests/… – unit tests and test data, mocks for k8s and Istio client interfaces.
• Dockerfile, Makefile, GitHub Actions workflow for build & push.
Extract Architectural Insights from README
• Single operator process deployed in-cluster.
• Installs a CRD, then listens for VirtualServiceMerge objects.
• On each reconcile: fetch target VirtualService, apply patch(s), update resource.
• Uses controller-runtime manager for leader election, caching, and event handling.
Main Components & Relationships
a. Kubernetes Cluster
– API Server & etcd storing built-in and custom resources.
– Istio Control Plane (already deployed separately) which reverberates VirtualService CRDs.
b. Custom Resource Definition (CRD)
– Defines VirtualServiceMerge kind.
c. Operator Deployment/Pod
– Container running the compiled Go binary.
– Contains:
• Manager (controller-runtime)
• VirtualServiceMerge Controller
• Reconciler Loop
d. Go Modules & Code
– api/v1alpha1: CRD types
– controller/: reconciliation logic & tests
– main.go: wire up the manager, register scheme, start controllers
e. External Clients & Tools
– kubectl (end user) to apply CRD, operator manifest, and create VirtualServiceMerge objects.
– Istio’s CRDs (VirtualService) which the operator merges into.
Interaction Flow:
1. User applies CRD YAML → Kubernetes API server stores CRD.
2. User deploys operator manifest → StatefulSet/Deployment Pod is scheduled.
3. Operator’s manager connects to API server, registers watches on VirtualServiceMerge & VirtualService.
4. User creates one or more VirtualServiceMerge CR instances.
5. Controller is triggered → Reconciler reads the CR spec, fetches the target VirtualService, applies patch logic, writes back the merged VirtualService update.
6. Kubernetes propagates the updated VirtualService to the Istio control plane, effecting new routing.
Architectural Patterns & Technologies
• Controller Pattern (Reconciliation Loop)
• Kubernetes Custom Resource Definitions (CRDs)
• Go & controller-runtime (Kubebuilder) Framework
• Testing with mock clientsets (unit tests under tests/mocks).
• Containerization (Dockerfile) & CI/CD via GitHub Actions.