Documentation
¶
Overview ¶
Package discovery exposes the per-service workload endpoint shape returned by the HA orchestrator contract's `active_provider_endpoints` query, plus formatters that turn that shape into outputs convenient for external consumers (init-containers, traffic sidecars, /etc/hosts writers, Mongo connection-string builders).
The types intentionally mirror the JSON shape produced by `ha-orchestrator/src/lib.rs` so callers can `json.Unmarshal` the contract response directly without an intermediate marshalling step.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
func Render(resp *ActiveProviderEndpointsResponse, format Format, opts FormatOptions) (string, error)
Render formats the response according to format + opts.
func SanitizeEnvKey ¶
SanitizeEnvKey converts an arbitrary label like "primary" / "secondary-1" / "mongo.replica.0" into an uppercase shell-safe env-var stem. Non `[A-Z0-9_]` characters become `_`; leading digits are prefixed with `_` so the result is a valid POSIX identifier.
Types ¶
type ActiveProviderEndpoint ¶
type ActiveProviderEndpoint struct {
Owner string `json:"owner"`
DSeq uint64 `json:"dseq"`
GSeq uint32 `json:"gseq"`
OSeq uint32 `json:"oseq"`
Provider string `json:"provider"`
LeaseState string `json:"lease_state"`
Price string `json:"price"`
HostURI string `json:"host_uri"`
Scheme *string `json:"scheme,omitempty"`
Host *string `json:"host,omitempty"`
Port *string `json:"port,omitempty"`
ServiceURL *string `json:"service_url,omitempty"`
Label *string `json:"label,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
ProviderFound bool `json:"provider_found"`
WorkloadForwardedPorts []WorkloadForwardedPort `json:"workload_forwarded_ports,omitempty"`
Services []ServiceEndpoint `json:"services,omitempty"`
}
ActiveProviderEndpoint mirrors the contract's response struct. Only the fields consumed by the discovery formatters are mandatory; the rest are kept for callers that want to display them.
type ActiveProviderEndpointsResponse ¶
type ActiveProviderEndpointsResponse struct {
Owner string `json:"owner"`
DSeq *uint64 `json:"dseq,omitempty"`
RoutingLabel *string `json:"routing_label,omitempty"`
Endpoints []ActiveProviderEndpoint `json:"endpoints"`
Count uint32 `json:"count"`
}
ActiveProviderEndpointsResponse mirrors the wasm contract response.
type Format ¶
type Format int
Format is the requested output shape for the discovery CLI helper.
const ( // FormatJSON pretty-prints the full ActiveProviderEndpointsResponse. FormatJSON Format = iota // FormatHosts emits "label\thost port" lines, one per labeled // service. Intended for /etc/hosts-style consumers. FormatHosts // FormatKV emits "label=host:port" lines, one per labeled service. FormatKV // FormatEnv emits shell-quoted "<UPPER_LABEL>_HOST" / // "<UPPER_LABEL>_PORT" exports, one pair per labeled service. FormatEnv // FormatMongoConnStr emits a single "mongodb://h1:p1,h2:p2,..." // connection string built from the labeled mongo services. FormatMongoConnStr )
func ParseFormat ¶
ParseFormat maps a CLI flag value to a Format.
Recognized values: "json", "hosts", "kv", "env", "connstr=mongo".
type FormatOptions ¶
type FormatOptions struct {
// MongoReplicaSet, when non-empty, is appended as
// `?replicaSet=<value>` to the Mongo connection string.
MongoReplicaSet string
// ServiceFilter, when non-empty, restricts the output to
// ServiceEndpoint rows whose Service name matches.
ServiceFilter string
// IncludeUnlabeled, when true, includes ServiceEndpoint rows
// whose Label is nil (host:port still printed; label slot empty
// or fallback derived from the SDL service name).
IncludeUnlabeled bool
}
FormatOptions tunes the formatters that take parameters.
type ServiceEndpoint ¶
type ServiceEndpoint struct {
Service string `json:"service"`
Label *string `json:"label,omitempty"`
Host string `json:"host"`
NodePort uint32 `json:"nodeport"`
ContainerPort uint32 `json:"container_port"`
Protocol string `json:"protocol"`
}
ServiceEndpoint is the per-service projection of one workload's reachability for one lease. It joins the runtime NodePort + cluster public hostname (sourced from the provider's `health_response` `forwarded_ports` payload) with an owner-defined label set on the HA contract via `service_labels` / `dseq_service_labels`.
type WorkloadForwardedPort ¶
type WorkloadForwardedPort struct {
Service string `json:"service"`
ExternalPort uint32 `json:"external_port"`
InternalPort uint32 `json:"internal_port"`
Protocol string `json:"protocol"`
Host string `json:"host"`
}
WorkloadForwardedPort mirrors the legacy `workload_forwarded_ports` field on the contract response. Kept so callers that want the raw row can use it; new consumers should prefer ServiceEndpoint.