How cybozu-go/fin works
Project type and purpose
• This is a Kubernetes “operator” written in Go (using Kubebuilder). It defines Custom Resources (FinBackup, FinRestore, FinBackupConfig), watches them, and spins up Jobs to do backups, restores, clean-up, deletion, and verification. It also provides a validating/mutating webhook for CR admission.
File structure
• Top-level “api/v1” holds the CRD Go types and generated deepcopy code.
• “cmd” contains the CLI entry points for the operator binary (main.go + subcommands).
• “internal/controller” implements the reconcile loops for each CR type.
• “internal/job” is the library for constructing Kubernetes Job specs for backup/restore/etc.
• “internal/infrastructure” contains adapters to external storage (Ceph RBD, NLV, DB) and fake implementations for testing.
• “internal/webhook” hosts the admission logic.
• “config” holds Kustomize overlays: CRD manifests, RBAC, manager deployment, webhook Service, Prometheus monitors, network policies.
• “test/e2e” and “test/utils” support end-to-end testing with real or simulated KVM/ceph clusters.
Additional insights
• CRDs → RBAC → Manager Deployment (with leader election, metrics) → Webhook Service → Prometheus monitors.
• Controllers reconcile loops that react to CR changes and update status.
• “API Server + etcd”
• “Job Pod” for each job type
• “Ceph RBD Cluster” and “NLV Service”
• “etcd (CRD storage)”
• CR creation → API Server → controllers
• Controller → Job creation
• Job Pod → external storage
• Job Pod → status update → API Server → Controller
• Data Plane components (Job Pods, Ceph) in another
• Test/E2E harness in a third