Documentation
¶
Overview ¶
Package static implements onexmesh registry.Discovery over a fixed address list, so a client can talk to a known ip:port without a service registry.
Why this exists ¶
Every other backend answers "where is service X" by asking something — Polaris, etcd, the Kubernetes API. The other half of that question is "I already know where it is", and until this package there was no backend for it: pkg/client.Dial (gRPC) has an isHostPort branch that dials a literal address, but pkg/client/rest has only the discovery path, and the registry backends shipped are all external systems. So a REST client could not be pointed at 127.0.0.1:8182 at all — with `registry.type: none` the round tripper had no discovery and failed with "registry discovery \"none\" is not registered".
Where it is meant to be used ¶
Client side. A service that calls another at a known address builds its transport with this backend:
cfg, _ := meshrest.NewForMeshConfig("edu.onex.commerce-apiserver",
meshrest.WithRegistry("static", static.Options{
Endpoints: map[string][]string{
"edu.onex.commerce-apiserver": {"http://127.0.0.1:8182"},
},
}))
It is a development and single-host-deployment facility, not a production service mesh. It has no health checking, no failover and no watching: the list is whatever the operator wrote, and a dead address stays in it.
Registration is a deliberate no-op ¶
NewRegistrar returns a Registrar that does nothing but say so. Setting the registry type to "static" means "do not register me anywhere", which is a coherent instruction from an operator running a one-host deployment — and the failure mode to avoid is the opposite one, where the service believes it is registered and no client can find it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDiscovery ¶
NewDiscovery creates a Discovery that answers from endpoints.
The map is copied, so a caller that keeps a handle and mutates it does not change what is served. A watcher would be the other way to change it, and this backend does not have one; see Watch.
func ParseBindings ¶
ParseBindings turns the flag form into the map form.
The flag form exists because pflag has no map-of-lists type, so a backend that wants to be configurable from the command line as well as from a YAML file needs a flat encoding. Each element names the service it belongs to and may be repeated to give a service more than one address:
--registry.static.endpoints=edu.onex.commerce-apiserver=http://127.0.0.1:8182 --registry.static.endpoints=edu.onex.commerce-apiserver=http://127.0.0.1:8183
A `service=address` entry with an empty side is refused rather than ignored: `=http://a:1` cannot be routed to anything, and `svc=` would register a service with no address, which a client would then fail to reach with a message about instances rather than about configuration.
Types ¶
type Options ¶
type Options struct {
// Endpoints maps a logical service name to the addresses it is reachable at.
//
// An address is "host:port", optionally with a scheme: "http://127.0.0.1:8182".
// Without a scheme the REST transport assumes http, which is what a bare
// "127.0.0.1:8182" should mean — nobody writes that intending TLS.
//
// A service name with no entry here is an error at lookup rather than an
// empty instance list. The two are different facts — "nobody configured this
// service" and "the service is configured and has no healthy instances" —
// and collapsing them would make a typo in a service name look like an
// outage.
Endpoints map[string][]string
}
Options configures the static backend.