ingress

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package ingress provides conversion from Gateway API HTTPRoute resources to Cloudflare Tunnel ingress configuration.

Overview

The Builder type converts a list of HTTPRoute resources into Cloudflare tunnel ingress rules. It handles:

  • Hostname extraction from HTTPRoute.spec.hostnames
  • Path matching (Exact and PathPrefix types)
  • Backend service resolution to cluster-internal URLs
  • Rule ordering by priority and path specificity

Diff-based Synchronization

The package provides diff-based synchronization functions to minimize changes when updating tunnel configuration:

  • DiffRules: Computes rules to add and remove
  • ApplyDiff: Applies the diff to current rules
  • EnsureCatchAll: Ensures catch-all rule exists at the end

This approach only adds new rules and removes orphaned rules, rather than replacing the entire configuration.

Path Matching

The builder supports two path match types as defined by Gateway API:

  • PathMatchExact: Matches the path exactly (priority 1)
  • PathMatchPathPrefix: Matches paths with the given prefix (priority 0)

Rules are sorted by hostname, then by priority (exact matches first), then by path length (longer paths first for prefix matches).

Service Resolution

Backend references are resolved to fully-qualified cluster DNS names:

http://<service>.<namespace>.svc.<cluster-domain>:<port>

Port 443 automatically uses HTTPS scheme.

Catch-All Rule

A catch-all rule returning HTTP 404 is always appended as the last rule, as required by Cloudflare Tunnel configuration.

Index

Constants

View Source
const (
	// CatchAllService is the Cloudflare Tunnel service that returns HTTP 404.
	// It is always added as the last rule in the ingress configuration.
	CatchAllService = "http_status:404"

	// DefaultHTTPPort is the default port for HTTP backend services.
	DefaultHTTPPort = 80

	// DefaultHTTPSPort is the default port for HTTPS backend services.
	DefaultHTTPSPort = 443
)

Variables

This section is empty.

Functions

func ApplyDiff added in v0.7.0

ApplyDiff applies the diff to current rules, returning the final rule set. Removes orphaned rules, keeps existing rules, adds new rules.

func EnsureCatchAll added in v0.7.0

EnsureCatchAll ensures a catch-all rule exists at the end of the rules.

func IsCatchAll added in v0.7.0

func IsCatchAll(r Rule) bool

IsCatchAll returns true if the rule is a catch-all rule (no hostname).

func RulesEqual added in v0.7.0

func RulesEqual(a, b Rule) bool

RulesEqual compares two rules for equality.

Types

type Builder

type Builder struct {
	// ClusterDomain is the Kubernetes cluster domain suffix for service DNS.
	// Typically "cluster.local".
	ClusterDomain string
}

Builder converts Gateway API HTTPRoute resources to Cloudflare Tunnel ingress configuration rules.

func NewBuilder

func NewBuilder(clusterDomain string) *Builder

NewBuilder creates a new Builder with the specified cluster domain.

func (*Builder) Build

Build converts a list of HTTPRoute resources to Cloudflare Tunnel ingress rules.

Rules are sorted by:

  1. Hostname (alphabetically)
  2. Priority (exact matches before prefix matches)
  3. Path length (longer paths first for specificity)

A catch-all rule returning HTTP 404 is always appended as the last rule.

type Rule added in v0.7.0

type Rule struct {
	Hostname string
	Path     string
	Service  string
}

Rule represents a simplified ingress rule for comparison.

func DiffRules added in v0.7.0

DiffRules computes the difference between current and desired rules. Returns rules to add (in desired but not in current) and rules to remove (in current but not in desired). Catch-all rules are excluded from comparison.

func RuleFromGet added in v0.7.0

RuleFromGet converts a get response ingress rule to a Rule for comparison.

func RuleFromUpdate added in v0.7.0

RuleFromUpdate converts an update params ingress rule to a Rule for comparison.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL