router

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultAPIKeyHeader is the default value for the header used to identify the API Key (X-ROUTING-API-KEY)
	DefaultAPIKeyHeader = "X-ROUTING-API-KEY"
	// DefaultAPIKeySecret is the default value for the first portion of the DefaultAPIKeySecretLocation (routing)
	DefaultAPIKeySecret = "routing"
	// DefaultAPIKeySecretDataField is the default value for the second portion of the DefaultAPIKeySecretDataField (api-key)
	DefaultAPIKeySecretDataField = "api-key"
	// DefaultAPIKeySecretLocation is the default value for the EnvVarAPIKeySecretLocation (routing:api-key)
	DefaultAPIKeySecretLocation = DefaultAPIKeySecret + ":" + DefaultAPIKeySecretDataField
	// DefaultHostsAnnotation is the default value for EnvVarHostsAnnotation (routingHosts)
	DefaultHostsAnnotation = "routingHosts"
	// DefaultPathsAnnotation is the default value for the EnvVarHostsAnnotation (routingPaths)
	DefaultPathsAnnotation = "routingPaths"
	// DefaultPort is the default value for the EnvVarPort (80)
	DefaultPort = 80
	// DefaultRoutableLabelSelector is the default value for EnvVarRoutableLabelSelector (routable=true)
	DefaultRoutableLabelSelector = "routable=true"
	// Default ClientMaxBodySize for nginx max client request size. Default 100mb
	DefaultClientMaxBodySize = "100m"
	// EnvVarAPIKeyHeader Environment variable name for providing the header name used to identify the API Key header
	EnvVarAPIKeyHeader = "API_KEY_HEADER"
	// EnvVarAPIKeySecretLocation Environment variable name for providing the location of the secret (name:field) to identify API Key secrets
	EnvVarAPIKeySecretLocation = "API_KEY_SECRET_LOCATION"
	// EnvVarHostsAnnotation Environment variable name for providing the name of the hosts annotation
	EnvVarHostsAnnotation = "HOSTS_ANNOTATION"
	// EnvVarPathsAnnotation Environment variable name for providing the the name of the paths annotation
	EnvVarPathsAnnotation = "PATHS_ANNOTATION"
	// EnvVarPort Environment variable for providing the port nginx should listen on
	EnvVarPort = "PORT"
	// EnvClientMaxBodySize Environment variable for max client request body size
	EnvClientMaxBodySize = "CLIENT_MAX_BODY_SIZE"
	// EnvVarRoutableLabelSelector Environment variable name for providing the label selector for identifying routable objects
	EnvVarRoutableLabelSelector = "ROUTABLE_LABEL_SELECTOR"
	// ErrMsgTmplInvalidAnnotationName is the error message template for an invalid annotation name
	ErrMsgTmplInvalidAnnotationName = "%s has an invalid annotation name: %s"
	// ErrMsgTmplInvalidAPIKeySecretLocation is the error message template for invalid API Key Secret location environment variable values
	ErrMsgTmplInvalidAPIKeySecretLocation = "%s is not in the format of {API_KEY_SECRET_NAME}:{API_KEY_SECRET_DATA_FIELD_NAME}"
	// ErrMsgTmplInvalidLabelSelector is the error message template for an invalid label selector
	ErrMsgTmplInvalidLabelSelector = "%s has an invalid label selector: %s\n"
	// ErrMsgTmplInvalidPort is the error message template for an invalid port
	ErrMsgTmplInvalidPort = "%s is an invalid port: %s\n"
)

Variables

This section is empty.

Functions

func ConvertSecretToModel

func ConvertSecretToModel(config *Config, secret *api.Secret) []byte

func GetRoutablePodList

func GetRoutablePodList(config *Config, kubeClient *client.Client) (*api.PodList, error)

GetRoutablePodList returns the routable pods list.

func GetRouterSecretList

func GetRouterSecretList(config *Config, kubeClient *client.Client) (*api.SecretList, error)

GetRouterSecretList returns the router secrets.

func UpdatePodCacheForEvents

func UpdatePodCacheForEvents(config *Config, cache map[string]*PodWithRoutes, events []watch.Event) bool

UpdatePodCacheForEvents updates the cache based on the pod events and returns if the changes warrant an nginx restart.

func UpdateSecretCacheForEvents

func UpdateSecretCacheForEvents(config *Config, cache map[string][]byte, events []watch.Event) bool

UpdateSecretCacheForEvents updates the cache based on the secret events and returns if the changes warrant an nginx restart.

Types

type Cache

type Cache struct {
	Pods    map[string]*PodWithRoutes
	Secrets map[string][]byte
}

Cache is the structure containing the router API Keys and the routable pods cache

type Config

type Config struct {
	// The header name used to identify the API Key
	APIKeyHeader string
	// The secret name used to store the API Key for the namespace
	APIKeySecret string
	// The secret data field name to store the API Key for the namespace
	APIKeySecretDataField string
	// The name of the annotation used to find hosts to route
	HostsAnnotation string
	// The name of the annotation used to find paths to route
	PathsAnnotation string
	// The port that nginx will listen on
	Port int
	// The label selector used to identify routable objects
	RoutableLabelSelector labels.Selector
	// Max client request body size. nginx config: client_max_body_size. eg 10m
	ClientMaxBodySize string
}

Config is the structure containing the configuration

func ConfigFromEnv

func ConfigFromEnv() (*Config, error)

ConfigFromEnv returns the configuration based on the environment variables and validates the values

type Incoming

type Incoming struct {
	Host string
	Path string
}

Incoming describes the information required to route an incoming request

type Outgoing

type Outgoing struct {
	IP   string
	Port string
}

Outgoing describes the information required to proxy to a backend

type PodWithRoutes

type PodWithRoutes struct {
	Name           string
	Namespace      string
	Status         api.PodPhase
	AnnotationHash uint64
	Routes         []*Route
}

PodWithRoutes contains a pod and its routes

func ConvertPodToModel

func ConvertPodToModel(config *Config, pod *api.Pod) *PodWithRoutes

Converts a Kubernetes pod model to our model

type Route

type Route struct {
	Incoming *Incoming
	Outgoing *Outgoing
}

Route describes the incoming route matching details and the outgoing proxy backend details

func GetRoutes

func GetRoutes(config *Config, pod *api.Pod) []*Route

GetRoutes returns an array of routes defined within the provided pod

func (*Route) String

func (r *Route) String() string

String implements the Stringer interface

Jump to

Keyboard shortcuts

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