Documentation
¶
Index ¶
- Constants
- Variables
- func AddFetchRoute(lggr logr.Logger, mux *http.ServeMux, table *Table)
- func AddPingRoute(lggr logr.Logger, mux *http.ServeMux, getter k8s.ConfigMapGetter, table *Table, ...)
- func GetTable(ctx context.Context, lggr logr.Logger, getter k8s.ConfigMapGetter, ...) error
- func SaveTableToConfigMap(table *Table, configMap *corev1.ConfigMap) error
- func ServiceURL(t Target) (*url.URL, error)
- func StartConfigMapRoutingTableUpdater(ctx context.Context, lggr logr.Logger, ...) error
- type ServiceURLFunc
- type Table
- func (t *Table) AddTarget(host string, target Target) error
- func (t Table) Hosts() []string
- func (t *Table) Lookup(host string) (Target, error)
- func (t *Table) MarshalJSON() ([]byte, error)
- func (t *Table) RemoveTarget(host string) error
- func (t *Table) Replace(newTable *Table)
- func (t *Table) String() string
- func (t *Table) UnmarshalJSON(data []byte) error
- type TableReader
- type Target
Constants ¶
const (
// the name of the ConfigMap that stores the routing table
ConfigMapRoutingTableName = "keda-http-routing-table"
)
Variables ¶
var ErrTargetNotFound = errors.New("Target not found")
ErrTargetNotFound is returned when a target is not found in the table.
Functions ¶
func AddFetchRoute ¶
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 ¶
SaveTableToConfigMap saves the contents of table to the Data field in configMap
func ServiceURL ¶ added in v0.3.0
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
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 ¶
func FetchTableFromConfigMap ¶
FetchTableFromConfigMap fetches the Data field from configMap, converts it to a routing table, and returns it
func (*Table) AddTarget ¶
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
Hosts is the TableReader implementation for t. This function returns all hosts that are currently in t.
func (*Table) MarshalJSON ¶
func (*Table) RemoveTarget ¶
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 ¶
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.