routing

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package routing manages Kubernetes networking resources for environment traffic routing, with implementations for Gateway API and Istio.

Index

Constants

This section is empty.

Variables

View Source
var ErrHostnameTooLong = errors.New("derived hostname exceeds 253 characters")

ErrHostnameTooLong is returned when a derived subdomain hostname exceeds the DNS maximum of 253 characters.

View Source
var Providers = registry.New[Router]("router")

Providers is the registry of available Router implementations.

Functions

This section is empty.

Types

type AsyncProvider

type AsyncProvider interface {
	Name() string
	Reconcile(ctx context.Context, env *v1alpha1.Environment) error
	Teardown(ctx context.Context, env *v1alpha1.Environment) error
}

AsyncProvider routes asynchronous messages through preview environments.

type AsyncRouter

type AsyncRouter struct {
	Providers []AsyncProvider
}

AsyncRouter delegates to registered async providers.

func (*AsyncRouter) GetExternalURL

func (r *AsyncRouter) GetExternalURL(env *v1alpha1.Environment) string

GetExternalURL performs its designated operation.

func (*AsyncRouter) Reconcile

func (r *AsyncRouter) Reconcile(ctx context.Context, env *v1alpha1.Environment) error

Reconcile iterates over all AsyncProviders and returns a joined error if any fail.

func (*AsyncRouter) Teardown

func (r *AsyncRouter) Teardown(ctx context.Context, env *v1alpha1.Environment) error

Teardown performs its designated operation.

type CompositeRouter

type CompositeRouter struct {
	Routers map[string]Router // named routers: "sync", "async", etc.
}

CompositeRouter runs multiple routers.

func (*CompositeRouter) GetExternalURL

func (r *CompositeRouter) GetExternalURL(env *v1alpha1.Environment) string

GetExternalURL performs its designated operation.

func (*CompositeRouter) Reconcile

func (r *CompositeRouter) Reconcile(ctx context.Context, env *v1alpha1.Environment) error

Reconcile reconciles all sub-routers; partial success is possible, returns first error encountered.

func (*CompositeRouter) Teardown

func (r *CompositeRouter) Teardown(ctx context.Context, env *v1alpha1.Environment) error

Teardown performs its designated operation.

type GRPCRouter

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

GRPCRouter implements Router using Gateway API GRPCRoute resources.

func NewGRPCRouter

func NewGRPCRouter(c client.Client, namespace string) *GRPCRouter

NewGRPCRouter creates a Router that manages Gateway API GRPCRoute resources for header-based traffic routing to preview environment services.

func (*GRPCRouter) GetExternalURL

func (r *GRPCRouter) GetExternalURL(env *v1alpha1.Environment) string

GetExternalURL returns the environment's external URL by substituting {env} in the routing template, or an empty string if none is configured.

func (*GRPCRouter) Reconcile

func (r *GRPCRouter) Reconcile(ctx context.Context, env *v1alpha1.Environment) error

Reconcile creates or updates GRPCRoute resources for each changed service in the environment, configuring header-based routing rules.

func (*GRPCRouter) Teardown

func (r *GRPCRouter) Teardown(ctx context.Context, env *v1alpha1.Environment) error

Teardown deletes all GRPCRoute resources associated with the environment.

type GatewayRouter

type GatewayRouter struct {
	Client    client.Client
	Namespace string
}

GatewayRouter implements Router using Gateway API HTTPRoute resources. It creates HTTPRoute resources with header-based routing to direct traffic to preview environment services, mirroring the GRPCRouter pattern for HTTP traffic.

func (*GatewayRouter) GetExternalURL

func (r *GatewayRouter) GetExternalURL(env *v1alpha1.Environment) string

GetExternalURL returns the environment's external URL by substituting {env} in the routing template, or an empty string if none is configured.

func (*GatewayRouter) Reconcile

func (r *GatewayRouter) Reconcile(ctx context.Context, env *v1alpha1.Environment) error

Reconcile creates or updates routing resources for each changed service in the environment, configuring header-based routing rules. Supports both HTTPRoute (default) and GRPCRoute (when protocol=grpc). Also creates GAMMA mesh routes (parentRef=Service) for east-west traffic.

func (*GatewayRouter) Teardown

func (r *GatewayRouter) Teardown(ctx context.Context, env *v1alpha1.Environment) error

Teardown deletes all HTTPRoute and GRPCRoute resources associated with the environment by selecting on the diverge.io/environment label.

type InstrumentedRouter

type InstrumentedRouter struct {
	Inner Router
	Mode  string
}

InstrumentedRouter wraps a Router with Prometheus metrics.

func (*InstrumentedRouter) GetExternalURL

func (r *InstrumentedRouter) GetExternalURL(env *v1alpha1.Environment) string

GetExternalURL performs its designated operation.

func (*InstrumentedRouter) Reconcile

func (r *InstrumentedRouter) Reconcile(ctx context.Context, env *v1alpha1.Environment) error

Reconcile delegates to Inner and records routing duration and outcome metrics.

func (*InstrumentedRouter) Teardown

Teardown performs its designated operation.

type IstioRouter

type IstioRouter struct {
	Client client.Client
}

IstioRouter implements Router using Istio AuthorizationPolicy resources.

func (*IstioRouter) GetExternalURL

func (r *IstioRouter) GetExternalURL(env *v1alpha1.Environment) string

GetExternalURL returns the environment's external URL.

func (*IstioRouter) Reconcile

func (r *IstioRouter) Reconcile(ctx context.Context, env *v1alpha1.Environment) error

Reconcile creates or updates an AuthorizationPolicy for the environment.

func (*IstioRouter) Teardown

func (r *IstioRouter) Teardown(ctx context.Context, env *v1alpha1.Environment) error

Teardown deletes AuthorizationPolicy resources by label selector.

type NoopRouter

type NoopRouter struct{}

NoopRouter is a no-op Router implementation for testing and environments where routing reconciliation is disabled.

func (*NoopRouter) GetExternalURL

func (r *NoopRouter) GetExternalURL(_ *v1alpha1.Environment) string

GetExternalURL returns empty string.

func (*NoopRouter) Reconcile

func (r *NoopRouter) Reconcile(_ context.Context, _ *v1alpha1.Environment) error

Reconcile intentionally performs no routing; returns nil.

func (*NoopRouter) Teardown

func (r *NoopRouter) Teardown(_ context.Context, _ *v1alpha1.Environment) error

Teardown performs its designated operation.

type PartialFailureError

type PartialFailureError struct {
	Succeeded []string
	Failed    map[string]error
}

PartialFailureError indicates some routers succeeded but others failed.

func (*PartialFailureError) Error

func (e *PartialFailureError) Error() string

Error performs its designated operation.

type Router

type Router interface {
	Reconcile(ctx context.Context, env *v1alpha1.Environment) error
	Teardown(ctx context.Context, env *v1alpha1.Environment) error
	GetExternalURL(env *v1alpha1.Environment) string
}

Router reconciles and tears down Kubernetes networking resources for a preview environment and provides its external URL.

Jump to

Keyboard shortcuts

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