router

package
v0.0.0-...-7255c58 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-3-Clause Imports: 21 Imported by: 14

Documentation

Overview

Package router provides interfaces that need to be satisfied in order to implement a new router on tsuru.

Index

Constants

View Source
const HttpScheme = "http"

Variables

View Source
var (
	ErrBackendExists         = errors.New("Backend already exists")
	ErrBackendNotFound       = errors.New("Backend not found")
	ErrBackendSwapped        = errors.New("Backend is swapped cannot remove")
	ErrRouteNotFound         = errors.New("Route not found")
	ErrCNameExists           = errors.New("CName already exists")
	ErrCNameNotFound         = errors.New("CName not found")
	ErrCNameNotAllowed       = errors.New("CName as router subdomain not allowed")
	ErrCertificateNotFound   = errors.New("Certificate not found")
	ErrDefaultRouterNotFound = errors.New("No default router found")

	ErrSwapAmongDifferentClusters = errors.New("Could not swap apps among different clusters")
)
View Source
var (
	BackendStatusReady    = BackendStatus("ready")
	BackendStatusNotReady = BackendStatus("not ready")
)
View Source
var ConfigGetterFromData = configGetterFromData

Functions

func BuildHealthCheck

func BuildHealthCheck(routerName string) func(ctx context.Context) error

BuildHealthCheck creates a healthcheck function for the given routerName.

It will call the HealthCheck() method in the router (only if it's also a HealthChecker), for each instance of it (including the "main" instance and all custom routers).

func Default

func Default(ctx context.Context) (string, error)

Default returns the default router

func DynamicRouterService

func DynamicRouterService() (routerTypes.DynamicRouterService, error)

func Initialize

func Initialize() error

func InstrumentRequest

func InstrumentRequest(routerName string) func(error)

func IsSwapped

func IsSwapped(name string) (bool, string, error)

func List

func List(ctx context.Context) ([]router.PlanRouter, error)

func ListWithInfo

func ListWithInfo(ctx context.Context) ([]router.PlanRouter, error)

func MigrateUniqueCollection

func MigrateUniqueCollection() error

MigrateUniqueCollection only exists because old versions of tsuru (<1.2.0) allowed the insertion of incorrect duplicated entries in the db.routers collection. This migration tries its best to fix the inconsistencies in this collection and fails if that's not possible.

func Register

func Register(name string, r routerFactory)

Register registers a new router.

func Remove

func Remove(appName string) error

func Retrieve

func Retrieve(appName string) (string, error)

func Store

func Store(appName, routerName, kind string) error

Store stores the app name related with the router name.

func Swap

func Swap(ctx context.Context, r Router, backend1, backend2 App, cnameOnly bool) error

func Unregister

func Unregister(name string)

func ValidCName

func ValidCName(cname, domain string) bool

validCName returns true if the cname is not a subdomain of the router current domain, false otherwise.

Types

type App

type App interface {
	GetName() string
	GetPool() string
	GetTeamOwner() string
	GetTeamsName() []string
}

App is the interface implemented by routable applications.

type AsyncRouter

type AsyncRouter interface {
	AddBackendAsync(ctx context.Context, app App) error
	SetCNameAsync(ctx context.Context, cname string, app App) error
	AddRoutesAsync(ctx context.Context, app App, address []*url.URL) error
	RemoveRoutesAsync(ctx context.Context, app App, addresses []*url.URL) error
}

type BackendPrefix

type BackendPrefix struct {
	Prefix string            `json:"prefix"`
	Target map[string]string `json:"target"` // in kubernetes cluster be like {serviceName: "", namespace: ""}
}

type BackendStatus

type BackendStatus string

type CNameMoveRouter

type CNameMoveRouter interface {
	MoveCName(ctx context.Context, cname string, orgBackend, dstBackend App) error
}

type CNameRouter

type CNameRouter interface {
	SetCName(ctx context.Context, cname string, app App) error
	UnsetCName(ctx context.Context, cname string, app App) error
	CNames(ctx context.Context, app App) ([]*url.URL, error)
}

type ConfigGetter

type ConfigGetter interface {
	GetString(string) (string, error)
	GetList(string) ([]string, error)
	GetInt(string) (int, error)
	GetFloat(string) (float64, error)
	GetBool(string) (bool, error)
	Get(string) (interface{}, error)
	Hash() (string, error)
}

func ConfigGetterFromPrefix

func ConfigGetterFromPrefix(prefix string) ConfigGetter

type CustomHealthcheckRouter

type CustomHealthcheckRouter interface {
	SetHealthcheck(ctx context.Context, app App, data router.HealthcheckData) error
}

type EnsureBackendOpts

type EnsureBackendOpts struct {
	Opts        map[string]interface{} `json:"opts"`
	CNames      []string               `json:"cnames"`
	Prefixes    []BackendPrefix        `json:"prefixes"`
	Healthcheck router.HealthcheckData `json:"healthcheck"`

	PreserveOldCNames bool `json:"preserveOldCNames,omitempty"`
}

type ErrRouterNotFound

type ErrRouterNotFound struct {
	Name string
}

func (*ErrRouterNotFound) Error

func (e *ErrRouterNotFound) Error() string

type HealthChecker

type HealthChecker interface {
	HealthCheck(ctx context.Context) error
}

type InfoRouter

type InfoRouter interface {
	GetInfo(ctx context.Context) (map[string]string, error)
}

type MessageRouter

type MessageRouter interface {
	StartupMessage() (string, error)
}

type OptsRouter

type OptsRouter interface {
	AddBackendOpts(ctx context.Context, app App, opts map[string]string) error
	UpdateBackendOpts(ctx context.Context, app App, opts map[string]string) error
}

type PrefixRouter

type PrefixRouter interface {
	RoutesPrefix(ctx context.Context, app App) ([]appTypes.RoutableAddresses, error)
	Addresses(ctx context.Context, app App) ([]string, error)
	AddRoutesPrefix(ctx context.Context, app App, addresses appTypes.RoutableAddresses, sync bool) error
	RemoveRoutesPrefix(ctx context.Context, app App, addresses appTypes.RoutableAddresses, sync bool) error
}

type Router

type Router interface {
	GetName() string
	GetType() string

	AddBackend(ctx context.Context, app App) error
	RemoveBackend(ctx context.Context, app App) error
	AddRoutes(ctx context.Context, app App, address []*url.URL) error
	RemoveRoutes(ctx context.Context, app App, addresses []*url.URL) error
	Addr(ctx context.Context, app App) (string, error)

	// Swap change the router between two backends.
	Swap(ctx context.Context, app1 App, app2 App, cnameOnly bool) error

	// Routes returns a list of routes of a backend.
	Routes(ctx context.Context, app App) ([]*url.URL, error)
}

Router is the basic interface of this package. It provides methods for managing backends and routes. Each backend can have multiple routes.

func Get

func Get(ctx context.Context, name string) (Router, error)

Get gets the named router from the registry.

func GetWithPlanRouter

func GetWithPlanRouter(ctx context.Context, name string) (Router, router.PlanRouter, error)

type RouterBackendStatus

type RouterBackendStatus struct {
	Status BackendStatus `json:"status"`
	Detail string        `json:"detail"`
	Checks []URLCheck    `json:"checks,omitempty"`
}

type RouterError

type RouterError struct {
	Op  string
	Err error
}

func (*RouterError) Error

func (e *RouterError) Error() string

type RouterV2

type RouterV2 interface {
	EnsureBackend(ctx context.Context, app App, o EnsureBackendOpts) error
}

RouterV2 is specialized in clustered router environments like kubernetes after deprecation of previous router, we could just use the interface bellow

type StatusRouter

type StatusRouter interface {
	GetBackendStatus(ctx context.Context, app App, path string) (status RouterBackendStatus, err error)
}

type TLSRouter

type TLSRouter interface {
	AddCertificate(ctx context.Context, app App, cname, certificate, key string) error
	RemoveCertificate(ctx context.Context, app App, cname string) error
	GetCertificate(ctx context.Context, app App, cname string) (string, error)
}

TLSRouter is a router that supports adding and removing certificates for a given cname

type URLCheck

type URLCheck struct {
	Address string `json:"address"`
	Status  int    `json:"status"`
	Error   string `json:"error"`
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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