Documentation
¶
Overview ¶
Package discovery implements a CoreDNS plugin for DNS-based service discovery.
Index ¶
- func RegisterSource(name string, factory SourceFactory)
- func RegisteredSources() []string
- type Handler
- type Instance
- type Service
- type Source
- type SourceFactory
- type Store
- func (s *Store) Deregister(svcName, namespace, instanceID string)
- func (s *Store) DeregisterBySource(source string)
- func (s *Store) GetInstance(svcName, namespace, instanceID string) (*Instance, bool)
- func (s *Store) GetInstances(svcName, namespace string) []*Instance
- func (s *Store) GetService(svcName, namespace string) (*Service, bool)
- func (s *Store) ListServices() []*Service
- func (s *Store) Register(svcName, namespace string, inst *Instance) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterSource ¶
func RegisterSource(name string, factory SourceFactory)
RegisterSource registers a source factory. Called from init() in each source_*.go file.
func RegisteredSources ¶
func RegisteredSources() []string
RegisteredSources returns the names of all registered sources.
Types ¶
type Instance ¶
type Instance struct {
ID string `json:"id"`
Address string `json:"address"`
Port int `json:"port"`
Protocol string `json:"protocol"`
Priority int `json:"priority"`
Weight int `json:"weight"`
Source string `json:"source"`
}
Instance represents a single instance of a discovered service.
type Service ¶
type Service struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Instances map[string]*Instance `json:"instances"`
}
Service represents a service with its instances.
type Source ¶
type Source interface {
// Name returns the source name (e.g., "podman", "qemu").
Name() string
// ParseConfig parses source-specific configuration from the Corefile.
// The controller cursor is positioned after the "{" token.
// ParseConfig should consume tokens using c.Next() until it
// encounters the closing "}" of the source sub-block.
ParseConfig(c *caddy.Controller) error
// Run starts the discovery loop. It populates the store and keeps
// it updated. Blocks until ctx is cancelled.
Run(ctx context.Context, store *Store) error
}
Source is a discovery source that populates the store. Each source (podman, qemu, etc.) implements this interface and registers itself via RegisterSource in its init() function.
type SourceFactory ¶
type SourceFactory func() Source
SourceFactory creates a new Source instance.
func GetSource ¶
func GetSource(name string) (SourceFactory, bool)
GetSource returns a source factory by name.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe in-memory store for discovered services.
func (*Store) Deregister ¶
Deregister removes an instance from a service.
func (*Store) DeregisterBySource ¶
DeregisterBySource removes all instances discovered by a specific source.
func (*Store) GetInstance ¶
GetInstance returns a specific instance of a service.
func (*Store) GetInstances ¶
GetInstances returns all instances of a service.
func (*Store) GetService ¶
GetService returns a service and all its instances.
func (*Store) ListServices ¶
ListServices returns all services in the store.