How kong/gateway-operator works
Main Components
• Users & DevOps: apply YAML manifests (ControlPlane, DataPlane, AIGateway, GatewayClass, etc.) via kubectl/helm.
• Kubernetes Cluster:
– API Server & etcd (holds CRs, native resources).
– Admission Webhooks (validating/mutating) served by the operator.
– Controller Manager (the operator’s “manager” binary).
• Operator Binary (cmd/main.go, built by modules/manager):
– Controllers/Reconciler modules (controller/…): ControlPlane, DataPlane, Gateway, GatewayClass, KongPluginInstallation, KonnectExtension, AIGateway, etc.
– Admission Server (modules/admission): webhook endpoints for CR validation/mutation.
– Metrics & Telemetry (internal/metrics, internal/telemetry): Prometheus metrics endpoint.
– Konnect SDK client (controller/konnect/ops/sdk): communicates with Kong Konnect or Kong Cloud API.
• Child Kubernetes Resources:
– Deployments, StatefulSets, Services, ConfigMaps, RBAC (generated via kustomize under config/).
– ValidatingAdmissionWebhookConfiguration, MutatingWebhookConfiguration.
• External Services:
– Kong Gateway Data Plane instances (sidecars, pods).
– Kong Ingress Controller (pods managed by ControlPlane).
– Kong Konnect cloud API (for hybrid mode, KonnectExtension).
– Prometheus server (scrapes operator metrics).
Relationships & Data Flows
1. User → kubectl/helm → Kubernetes API Server: apply CRs & native resources.
2. API Server → Admission Webhook → Operator’s webhook server: validate/mutate CRs.
3. API Server → Operator Manager (controller-runtime): watch CRD events & native resources.
4. Reconciler Loop: Operator reads desired state, uses internal/pkg and controller/… logic to:
a. Create/update child resources (Deployments, ConfigMaps, Services, RBAC) via Kubernetes API.
b. When KonnectExtension is enabled, call Kong Konnect API via SDK to provision cloud gateways.
5. Kubernetes Scheduler → Pods (ControlPlane, DataPlane) launch Kong binaries sidecar.
6. Operator Metrics/Telemetry endpoint → scraped by Prometheus.
Architectural Patterns & Principles
• Operator Pattern / Controller‐Runtime: separate reconcilers per API kind.
• Kubernetes CRD-driven declarative config.
• Self‐managed admission webhooks.
• Modular code organization:
– controller/… for reconcilers and business logic.
– modules/manager for manager setup.
– modules/admission for webhook server.
– controller/konnect/ops/sdk isolates external API calls.
• Kustomize-based manifest generation (config/ folder).
• Extensive testing: unit tests next to each package, envtest integration tests.
Technologies & Frameworks
• Go & controller-runtime (sigs.k8s.io/controller-runtime)
• Kubernetes CRD, client-go
• Kustomize (config/…/kustomization.yaml)
• Docker (Dockerfile for operator image)
• Prometheus (metrics)
• Kong Konnect SDK for cloud integration
• Make, Go modules, GitHub Actions, hack scripts