Architecture
Control plane versus data plane
Section titled “Control plane versus data plane”This project is a control plane: it watches your Gateway API objects (GatewayClass,
Gateway, and the Route kinds) and its own CRDs, decides what Cloudflare-side state should
exist, and writes that state through the Cloudflare API. It never carries your application’s
traffic itself.
The data plane — the thing your requests actually pass through — differs by mode:
- In Tunnel Mode, the data plane is
cloudflared, an outbound-only connector Cloudflare itself manages remotely. - In DNS Mode, the data plane is Envoy Gateway, a separate, unmodified installation this project does not run traffic through at all.
The diagram below shows both: solid arrows are the traffic path, dotted arrows are this
project’s control-plane calls (watching Gateway API objects, writing to the Cloudflare API,
managing cloudflared).
In short: you apply Gateway API objects; the controller watches them and talks to the
Cloudflare API to create tunnels, DNS records, and certificates; and your actual traffic
flows through cloudflared or Envoy Gateway, never through the controller itself.
Tunnel Mode
Section titled “Tunnel Mode”cloudflared is remotely managed by Cloudflare, not by this project. The controller
creates one Kubernetes Deployment per tunnel and gives cloudflared a tunnel token; from
that point on, Cloudflare’s own control plane pushes ingress configuration to it over the
tunnel’s outbound connection. This project never SSHes into a cloudflared pod or pushes a
local config file — it PUTs the desired ingress configuration to the Cloudflare API and
Cloudflare propagates it to the running connectors.
Because the connection is outbound-only, a Tunnel Mode cluster needs no inbound port
exposed to the internet at all — no LoadBalancer Service, no public IP, no firewall hole.
cloudflared dials out to the Cloudflare edge, and the edge terminates all inbound traffic on
Cloudflare’s own network before forwarding it down that same outbound connection.
DNS Mode: the companion pattern
Section titled “DNS Mode: the companion pattern”DNS Mode does not run its own data plane — it composes with one. A separate Envoy Gateway
installation, which you deploy and this project does not manage, owns the DNS-mode
GatewayClass and does all of the actual traffic handling: terminating connections, routing
to backend Services, everything a data plane normally does.
This project’s controller only reconciles the Cloudflare-facing side of that same
Gateway: watching it for the address Envoy Gateway assigns it, creating a DNS record that
points at that address, and issuing a certificate for it through cert-manager. It never
touches Envoy Gateway’s own configuration and never carries traffic itself in this mode
either — Envoy Gateway does that entirely on its own, using the ordinary Kubernetes Gateway
API mechanisms it already implements.
Because two independent controllers are both watching the same Gateway object, only Envoy
Gateway ever writes to Gateway.status in this mode. This project’s own readiness signal for
DNS Mode lives on a separate object instead — see
Status and Conditions for where.
The translate/actuate split
Section titled “The translate/actuate split”This project’s controllers are split into layers, and that split is visible directly in the source layout, not just a design principle:
- A pure translate step reads Gateway API objects and this project’s own CRDs and computes
a desired-state document. It never calls the Cloudflare API, never writes to Kubernetes, and
never does anything non-deterministic — it’s an ordinary Go function, testable with plain
structs. Some controllers keep this in their own
translator.go(internal/controller/ tunnel/translator.go,internal/controller/gateway/translator.go, and similarly fordnsgatewayanddnsrecord); Route and Access translation instead live in shared packages (internal/route/translate.go,internal/access/translate.go) rather than a per-controller file, since that logic is shared across several Route kinds and reconcilers. Not every reconciler needs a separate translate file — some (GatewayClass,CloudflareGatewayConfiguration) have little enough pure logic that it lives inline instead;CloudflareTunnelPolicy’s pure logic lives in the same sharedinternal/policypackage that resolves attachment and precedence for both policy kinds. - An actuate step, in each
internal/controller/*_controller.goreconciler, takes that desired state and turns it into real writes: Cloudflare API calls, but also Kubernetes writes such ascloudflaredDeployments, generated CRs, and cert-managerCertificateobjects. Reconcilers never import the Cloudflare API client directly — they call throughinternal/cfapi’s plain Go interfaces.internal/cfapi/cloudflareis the only package in the project allowed to import the underlying Cloudflare API client, so credentials and Cloudflare API semantics are dealt with in exactly one place, however many reconcilers end up calling into it.
The practical effect: the logic that decides what Cloudflare state a Gateway or Route should produce is unit-testable without a live cluster, a fake API server, or network access at all — and the code that actually talks to Cloudflare is small, isolated, and shared by every reconciler that needs it, in both modes.
Choosing a mode
Section titled “Choosing a mode”Choose Tunnel Mode when you don’t want to expose any inbound port on your cluster’s network at
all. It’s the simpler operational story — no data-plane installation to run yourself, no
public LoadBalancer address to provision or protect — at the cost of routing every request
through Cloudflare’s tunnel infrastructure.
Choose DNS Mode when you want a standards-based Envoy data plane you control directly — for
example, to use an Envoy Gateway feature this project doesn’t wrap, or because your traffic
already needs to reach a public LoadBalancer address for other reasons. It costs you running
and upgrading that companion Envoy Gateway installation yourself.
Resource Model covers the actual object hierarchy — GatewayClass,
CloudflareGatewayConfiguration, Gateway, and Routes — and which of this project’s CRDs you
author versus which it generates for you.