route

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package route provides shared utilities for building cloudflared ingress rules from various Kubernetes resources (Ingress, Gateway API routes, TunnelBinding).

Index

Constants

View Source
const (
	ProtocolHTTP  = "http"
	ProtocolHTTPS = "https"
	ProtocolTCP   = "tcp"
	ProtocolUDP   = "udp"
	ProtocolSSH   = "ssh"
	ProtocolRDP   = "rdp"
	ProtocolSMB   = "smb"
)

Protocol constants

Variables

This section is empty.

Functions

func BuildServiceURL

func BuildServiceURL(protocol, serviceName, namespace, port string) string

BuildServiceURL constructs a service URL for cloudflared ingress rules. Parameters:

  • protocol: the protocol (http, https, tcp, udp, ssh, rdp, smb)
  • serviceName: the Kubernetes service name
  • namespace: the Kubernetes namespace
  • port: the port number as string

func BuildServiceURLFromPort

func BuildServiceURLFromPort(protocol, serviceName, namespace string, port int32) string

BuildServiceURLFromPort constructs a service URL using a numeric port.

func ConvertGatewayPathType

func ConvertGatewayPathType(path string, pathType *gatewayv1.PathMatchType) string

ConvertGatewayPathType converts Gateway API PathMatchType to cloudflared path regex. This supports the Gateway API's path matching semantics.

func ConvertIngressPathType

func ConvertIngressPathType(path string, pathType *networkingv1.PathType) string

ConvertIngressPathType converts Kubernetes Ingress PathType to cloudflared path regex. Cloudflared uses regex for path matching, so we need to convert the Kubernetes path types. nolint:revive // Cognitive complexity for path conversion logic

func InferProtocolFromPort

func InferProtocolFromPort(port string) string

InferProtocolFromPort determines the protocol based on port number. This is used when no explicit protocol annotation is provided.

func InferProtocolFromPortNumber

func InferProtocolFromPortNumber(port int32) string

InferProtocolFromPortNumber determines the protocol based on numeric port.

func ProtocolFromGatewayProtocol

func ProtocolFromGatewayProtocol(protocol gatewayv1.ProtocolType) string

ProtocolFromGatewayProtocol converts Gateway API ProtocolType to cloudflared protocol.

Types

type Aggregator

type Aggregator struct {
	// Builders are the rule builders to aggregate
	Builders []Builder
	// FallbackTarget is the target for the catch-all fallback rule
	// Default is "http_status:404"
	FallbackTarget string
}

Aggregator aggregates rules from multiple builders and adds a fallback rule.

func NewAggregator

func NewAggregator(fallbackTarget string) *Aggregator

NewAggregator creates a new rule aggregator with the given fallback target.

func (*Aggregator) Add

func (a *Aggregator) Add(b Builder)

Add adds a builder to the aggregator.

func (*Aggregator) AddAll

func (a *Aggregator) AddAll(builders ...Builder)

AddAll adds multiple builders to the aggregator.

func (*Aggregator) Build

Build aggregates rules from all builders, sorts them, and adds a fallback rule. Rules are sorted by hostname, then by path for deterministic configuration.

func (*Aggregator) BuildWithoutFallback

func (a *Aggregator) BuildWithoutFallback(ctx context.Context) ([]cf.UnvalidatedIngressRule, error)

BuildWithoutFallback aggregates rules from all builders without adding a fallback rule. This is useful when the caller wants to add a custom fallback or combine with other rules.

type Builder

type Builder interface {
	// Build generates cloudflared ingress rules from the resource.
	// Returns a slice of rules (can be empty if resource has no routes).
	Build(ctx context.Context) ([]cf.UnvalidatedIngressRule, error)
}

Builder is an interface for building cloudflared ingress rules. Different resource types (Ingress, HTTPRoute, TCPRoute, TunnelBinding) implement this interface to convert their rules to cloudflared format.

type OriginRequestBuilder

type OriginRequestBuilder struct {
	// contains filtered or unexported fields
}

OriginRequestBuilder helps build OriginRequestConfig from various sources.

func NewOriginRequestBuilder

func NewOriginRequestBuilder() *OriginRequestBuilder

NewOriginRequestBuilder creates a new OriginRequestBuilder.

func (*OriginRequestBuilder) Build

Build returns the constructed OriginRequestConfig.

func (*OriginRequestBuilder) SetBastionMode

func (b *OriginRequestBuilder) SetBastionMode(v *bool) *OriginRequestBuilder

SetBastionMode sets the BastionMode option.

func (*OriginRequestBuilder) SetCAPool

func (b *OriginRequestBuilder) SetCAPool(caPool string) *OriginRequestBuilder

SetCAPool sets the CAPool option (converts to path).

func (*OriginRequestBuilder) SetConnectTimeout

func (b *OriginRequestBuilder) SetConnectTimeout(d *time.Duration) *OriginRequestBuilder

SetConnectTimeout sets the ConnectTimeout option.

func (*OriginRequestBuilder) SetDisableChunkedEncoding

func (b *OriginRequestBuilder) SetDisableChunkedEncoding(v *bool) *OriginRequestBuilder

SetDisableChunkedEncoding sets the DisableChunkedEncoding option.

func (*OriginRequestBuilder) SetHTTP2Origin

func (b *OriginRequestBuilder) SetHTTP2Origin(v *bool) *OriginRequestBuilder

SetHTTP2Origin sets the HTTP2Origin option.

func (*OriginRequestBuilder) SetHTTPHostHeader

func (b *OriginRequestBuilder) SetHTTPHostHeader(v string) *OriginRequestBuilder

SetHTTPHostHeader sets the HTTPHostHeader option.

func (*OriginRequestBuilder) SetKeepAliveConnections

func (b *OriginRequestBuilder) SetKeepAliveConnections(n *int) *OriginRequestBuilder

SetKeepAliveConnections sets the KeepAliveConnections option.

func (*OriginRequestBuilder) SetKeepAliveTimeout

func (b *OriginRequestBuilder) SetKeepAliveTimeout(d *time.Duration) *OriginRequestBuilder

SetKeepAliveTimeout sets the KeepAliveTimeout option.

func (*OriginRequestBuilder) SetNoTLSVerify

func (b *OriginRequestBuilder) SetNoTLSVerify(v *bool) *OriginRequestBuilder

SetNoTLSVerify sets the NoTLSVerify option.

func (*OriginRequestBuilder) SetOriginServerName

func (b *OriginRequestBuilder) SetOriginServerName(v string) *OriginRequestBuilder

SetOriginServerName sets the OriginServerName option.

func (*OriginRequestBuilder) SetProxyAddress

func (b *OriginRequestBuilder) SetProxyAddress(v string) *OriginRequestBuilder

SetProxyAddress sets the ProxyAddress option.

func (*OriginRequestBuilder) SetProxyPort

func (b *OriginRequestBuilder) SetProxyPort(port uint) *OriginRequestBuilder

SetProxyPort sets the ProxyPort option.

func (*OriginRequestBuilder) SetProxyType

func (b *OriginRequestBuilder) SetProxyType(v string) *OriginRequestBuilder

SetProxyType sets the ProxyType option.

func (*OriginRequestBuilder) SetTLSTimeout

SetTLSTimeout sets the TLSTimeout option.

func (*OriginRequestBuilder) WithDefaults

WithDefaults applies defaults from OriginRequestSpec. nolint:revive // Cognitive complexity is expected for mapping all fields

Jump to

Keyboard shortcuts

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