dns

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package dns manages DNS entries for the cluster

Index

Constants

View Source
const (
	// CloudflareAPIToken is the environment variable
	// containing the API Token
	CloudflareAPIToken = "CLOUDFLARE_DNS_API_TOKEN"
)

Variables

View Source
var (
	// ErrNoDNSProvider indicates a [libdns.Provider] wasn't assigned
	// to the [Manager]
	ErrNoDNSProvider = errors.New("dns provider not specified")

	// ErrNoDomain indicates a domain wasn't specified
	ErrNoDomain = errors.New("domain not specified")
)

Functions

func DefaultDNSProvider

func DefaultDNSProvider() (*cloudflare.Provider, error)

DefaultDNSProvider returns a cloudflare DNS provider using an API Token from env CloudflareAPIToken

func SortAddrSlice

func SortAddrSlice(s []netip.Addr) []netip.Addr

SortAddrSlice sorts a slice of netip.Addr

func SortRecords added in v0.6.10

func SortRecords(s []libdns.Record) []libdns.Record

SortRecords sorts a slice of libdns.Record, by Name, Type and Value

Types

type AddrRecord

type AddrRecord struct {
	Name string
	Addr []netip.Addr
}

AddrRecord represents an A or AAAA record

func SortAddrRecords

func SortAddrRecords(s []AddrRecord) []AddrRecord

SortAddrRecords sorts a slice of AddrRecord by Name and Address

func (*AddrRecord) Export

func (rr *AddrRecord) Export() []libdns.Record

Export converts the record into libdns.Record

func (*AddrRecord) Sort

func (rr *AddrRecord) Sort()

Sort sorts the addresses of the record

func (*AddrRecord) String

func (rr *AddrRecord) String() string

String converts the record into BIND entries

func (*AddrRecord) WriteTo

func (rr *AddrRecord) WriteTo(w io.Writer) (int64, error)

WriteTo writes the record in BIND notation

type Host

type Host struct {
	ID     int
	Active bool
	Addrs  []netip.Addr
	// contains filtered or unexported fields
}

Host represents a member of the cluster

func (*Host) String

func (p *Host) String() string

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is a DNS Manager instance

func NewManager

func NewManager(opts ...ManagerOption) (*Manager, error)

NewManager creates a DNS manager with the

func (*Manager) Add added in v0.6.10

func (mgr *Manager) Add(ctx context.Context, name string, addrs ...netip.Addr) error

Add adds a machine to the DNS records

func (*Manager) AddHost

func (mgr *Manager) AddHost(_ context.Context, zone string, id int,
	active bool, addrs ...netip.Addr) error

AddHost registers a host

func (*Manager) AddRegion

func (mgr *Manager) AddRegion(_ context.Context, region string, zones ...string) error

AddRegion specifies a new region and the zones it contains

func (*Manager) AsSyncAddr added in v0.6.7

func (mgr *Manager) AsSyncAddr(rr libdns.Record) (SyncAddr, bool, error)

AsSyncAddr converts a A or AAAA libdns.Record into a SyncAddr

func (*Manager) GetRecords added in v0.6.7

func (mgr *Manager) GetRecords(ctx context.Context, names ...string) ([]libdns.Record, error)

GetRecords pulls all the address records on DNS for our domain, optionally only those matching the given names.

func (*Manager) GetSyncRecords added in v0.6.9

func (mgr *Manager) GetSyncRecords(ctx context.Context) ([]SyncAddrRecord, error)

GetSyncRecords pulls all the address records on DNS for our domain

func (*Manager) Show added in v0.6.9

func (mgr *Manager) Show(ctx context.Context, names ...string) error

Show shows current DNS entries

func (*Manager) Sync added in v0.6.7

func (mgr *Manager) Sync(ctx context.Context) error

Sync updates all the address records on DNS for our domain

func (*Manager) WriteTo

func (mgr *Manager) WriteTo(w io.Writer) (int64, error)

WriteTo writes the DNS data for the cluster

type ManagerOption

type ManagerOption func(*Manager) error

ManagerOption configures a Manager

func WithDomain

func WithDomain(domain string) ManagerOption

WithDomain specifies where the manager operates

func WithLogger

func WithLogger(log slog.Logger) ManagerOption

WithLogger attaches a logger to the Manager

func WithProvider

func WithProvider(p Provider) ManagerOption

WithProvider attaches a libdns Provider to the Manager

type Provider

Provider manages DNS entries

type SyncAddr added in v0.6.7

type SyncAddr struct {
	ID   string
	Addr netip.Addr
	TTL  time.Duration
}

SyncAddr extends netip.Addr with ID and TTL fetched from the Provider

func AppendSyncAddr added in v0.6.10

func AppendSyncAddr(s []SyncAddr, addr netip.Addr) []SyncAddr

AppendSyncAddr appends a netip.Addr to a SyncAddr slice if the address is new.

func SortSyncAddrSlice added in v0.6.7

func SortSyncAddrSlice(s []SyncAddr) []SyncAddr

SortSyncAddrSlice sorts a slice of SyncAddr by its address

func (*SyncAddr) Export added in v0.6.7

func (rec *SyncAddr) Export(name string) libdns.Record

Export assembles a libdns.Record

type SyncAddrRecord added in v0.6.7

type SyncAddrRecord struct {
	Name  string
	Addrs []SyncAddr
}

SyncAddrRecord is similar to AddrRecord but include libdns.Record details fetched from the Provider

type Zone

type Zone struct {
	Name string

	Hosts map[int]*Host
}

Zone represents a set of hosts with high affinity

func (*Zone) String

func (z *Zone) String() string

Jump to

Keyboard shortcuts

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