routing

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// the name of the ConfigMap that stores the routing table
	ConfigMapRoutingTableName = "keda-http-routing-table"
)

Variables

View Source
var ErrTargetNotFound = errors.New("Target not found")

ErrTargetNotFound is returned when a target is not found in the table.

Functions

func AddFetchRoute

func AddFetchRoute(
	lggr logr.Logger,
	mux *http.ServeMux,
	table *Table,
)

AddFetchRoute adds a route to mux that fetches the current state of table, encodes it as JSON, and returns it to the HTTP client

func AddPingRoute

func AddPingRoute(
	lggr logr.Logger,
	mux *http.ServeMux,
	getter k8s.ConfigMapGetter,
	table *Table,
	q queue.Counter,
)

AddPingRoute adds a route to mux that will accept an empty GET request, fetch the current state of the routing table from the standard routing table ConfigMap (ConfigMapRoutingTableName), save it to local memory, and return the contents of the routing table to the client.

func GetTable

func GetTable(
	ctx context.Context,
	lggr logr.Logger,
	getter k8s.ConfigMapGetter,
	table *Table,
	q queue.Counter,
) error

GetTable fetches the contents of the appropriate ConfigMap that stores the routing table, then tries to decode it into a temporary routing table data structure.

If that succeeds, it calls table.Replace(newTable), then ensures that every host in the routing table exists in the given queue, and no hosts exist in the queue that don't exist in the routing table. It uses q.Ensure() and q.Remove() to do those things, respectively.

func SaveTableToConfigMap

func SaveTableToConfigMap(table *Table, configMap *corev1.ConfigMap) error

SaveTableToConfigMap saves the contents of table to the Data field in configMap

func ServiceURL added in v0.3.0

func ServiceURL(t Target) (*url.URL, error)

ServiceURL returns the full URL for the Kubernetes service, port and namespace of t.

func StartConfigMapRoutingTableUpdater

func StartConfigMapRoutingTableUpdater(
	ctx context.Context,
	lggr logr.Logger,
	cmInformer *k8s.InformerConfigMapUpdater,
	ns string,
	table *Table,
	cbFunc func() error,
) error

StartConfigMapRoutingTableUpdater starts a loop that does the following:

  • Fetches a full version of the ConfigMap called ConfigMapRoutingTableName in the given namespace ns, and calls table.Replace(newTable) after it does so
  • Uses watcher to watch for all ADDED or CREATED events on the ConfigMap called ConfigMapRoutingTableName. On either of those events, decodes that ConfigMap into a routing table and stores the new table into table using table.Replace(newTable)
  • Execute the callback function, if one exists
  • Returns an appropriate non-nil error if ctx.Done() receives

Types

type ServiceURLFunc added in v0.3.0

type ServiceURLFunc func(Target) (*url.URL, error)

ServiceURLFunc is a function that returns the full in-cluster URL for the given Target.

ServiceURL is the production implementation of this function

type Table

type Table struct {
	fmt.Stringer
	// contains filtered or unexported fields
}

func FetchTableFromConfigMap

func FetchTableFromConfigMap(configMap *corev1.ConfigMap) (*Table, error)

FetchTableFromConfigMap fetches the Data field from configMap, converts it to a routing table, and returns it

func NewTable

func NewTable() *Table

func (*Table) AddTarget

func (t *Table) AddTarget(
	host string,
	target Target,
) error

AddTarget registers target for host in the routing table t if it didn't already exist.

returns a non-nil error if it did already exist

func (Table) Hosts added in v0.3.0

func (t Table) Hosts() []string

Hosts is the TableReader implementation for t. This function returns all hosts that are currently in t.

func (*Table) Lookup

func (t *Table) Lookup(host string) (Target, error)

func (*Table) MarshalJSON

func (t *Table) MarshalJSON() ([]byte, error)

func (*Table) RemoveTarget

func (t *Table) RemoveTarget(host string) error

RemoveTarget removes host, if it exists, and its corresponding Target entry in the routing table. If it does not exist, returns a non-nil error

func (*Table) Replace

func (t *Table) Replace(newTable *Table)

Replace replaces t's routing table with newTable's.

This function is concurrency safe for t, but not for newTable. The caller must ensure that no other goroutine is writing to newTable at the time at which they call this function.

func (*Table) String

func (t *Table) String() string

func (*Table) UnmarshalJSON

func (t *Table) UnmarshalJSON(data []byte) error

type TableReader

type TableReader interface {
	Lookup(string) (Target, error)
	Hosts() []string
}

type Target

type Target struct {
	Service               string
	Port                  int
	Deployment            string
	Namespace             string
	TargetPendingRequests int32
}

Target is a single target in the routing table.

func NewTarget

func NewTarget(
	namespace,
	svc string,
	port int,
	depl string,
	targetPendingReqs int32,
) Target

NewTarget creates a new Target from the given parameters.

Jump to

Keyboard shortcuts

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