Documentation ¶
Index ¶
- Constants
- Variables
- func NewRetryError(err error, s RetrySchedule) error
- type BaseProvider
- type CloudflareOption
- type DNSProvider
- type DigitalOceanOption
- type IPProvider
- type MockDNSProvider
- type MockIPProvider
- func (m *MockIPProvider) AssignIP(ctx context.Context, ip, providerID string) error
- func (m *MockIPProvider) CreateIP(ctx context.Context, region string) (string, error)
- func (m *MockIPProvider) GetProviderName() string
- func (m *MockIPProvider) IPToProviderID(ctx context.Context, ip string) (string, error)
- func (m *MockIPProvider) NodeToIP(ctx context.Context, providerID string) (string, error)
- type MockProvider
- type Registry
- func (r *Registry) Collect(ch chan<- prometheus.Metric)
- func (r *Registry) Describe(ch chan<- *prometheus.Desc)
- func (r *Registry) Get(name string) BaseProvider
- func (r *Registry) Init() error
- func (r *Registry) Register(name string, p BaseProvider)
- func (r *Registry) RegisterCloudflare(opts ...CloudflareOption) error
- func (r *Registry) RegisterDigitalOcean(opts ...DigitalOceanOption) error
- type RegistryOption
- type RetrySchedule
Constants ¶
const Cloudflare = "cloudflare"
Cloudflare is the provider identifier used to identify the Cloudflare provider.
const (
// DigitalOcean is an identifier which can be used to select the godo provider.
DigitalOcean = "digitalocean"
)
const Mock = "mock"
Mock is the provider name for the MockProvider.
Variables ¶
var ( // ErrNotFound wraps provider specific not found errors. ErrNotFound = NewRetryError(errors.New("not found"), RetrySlow) // ErrInProgress is returned if the action is in-progress, but otherwise unerrored. ErrInProgress = NewRetryError(errors.New("action in progress"), RetryFast) // ErrNodeInUse is returned when the action cannot be completed because the IP already // has an IP. ErrNodeInUse = NewRetryError(errors.New("node in use"), RetrySlow) )
var ( // RetryFast should be used for error which are likely to resolve themselves quickly. RetryFast = RetrySchedule{ 1 * time.Second, 1 * time.Second, 5 * time.Second, 5 * time.Second, 10 * time.Second, 10 * time.Second, 10 * time.Second, 1 * time.Minute, 1 * time.Minute, 1 * time.Minute, 1 * time.Minute, 1 * time.Minute, 5 * time.Minute, } // RetrySlow is used for errors which are unlikely to resolve themselves without other interactions. RetrySlow = RetrySchedule{ 1 * time.Minute, 5 * time.Minute, 10 * time.Minute, } )
Functions ¶
func NewRetryError ¶
func NewRetryError(err error, s RetrySchedule) error
NewRetryError creates a new retry error with the provided schedule. It's not recommended for use outside of provider, but is exported for testing via the mock provider interface.
Types ¶
type BaseProvider ¶
type BaseProvider interface { // GetProviderName returns an identifier for the provider which can be used in resources. GetProviderName() string }
BaseProvider describes all providers.
func NewDigitalOcean ¶
func NewDigitalOcean(opts ...DigitalOceanOption) (BaseProvider, error)
NewDigitalOcean returns a new provider for DigitalOcean.
type CloudflareOption ¶
type CloudflareOption func(c *cloudflareDNS)
CloudflareOption defines a create option for the Cloudflare provider.
func CloudflareWithLog ¶
func CloudflareWithLog(ll logrus.FieldLogger) CloudflareOption
CloudflareWithLog sets a logrus.FieldLogger on the Cloudflare provider.
type DNSProvider ¶
type DNSProvider interface { BaseProvider // EnsureDNSARecordSet ensures that the record set w/ name `recordName` contains all IPs listed in `ips` // and no others. EnsureDNSARecordSet(ctx context.Context, zone, recordName string, ips []string, ttl int) error // RecordNameAndZoneToFQDN translates a zone+recordName into a fully-qualified domain name. RecordNameAndZoneToFQDN(zone, recordName string) string }
DNSProvider defines a service which can register and serve DNS records.
func NewCloudflare ¶
func NewCloudflare(opts ...CloudflareOption) (DNSProvider, error)
NewCloudflare creates a new Cloudflare DNS provider.
type DigitalOceanOption ¶
type DigitalOceanOption func(d *digitalOcean)
DigitalOceanOption defines a create option for the DigitalOcean provider.
func DigitalOceanWithLog ¶
func DigitalOceanWithLog(ll logrus.FieldLogger) DigitalOceanOption
DigitalOceanWithLog sets a logrus.FieldLogger on the DigitalOcean provider.
type IPProvider ¶
type IPProvider interface { BaseProvider // IPToProviderID loads the current assignment (as Kubernetes listed in Kubernetes core v1 // NodeSpec.ProviderID for a floating IP. IPToProviderID(ctx context.Context, ip string) (string, error) // AssignIP assigns a floating IP to the specified node. AssignIP(ctx context.Context, ip, providerID string) error // NodeToIP attempts to find any floating IPs bound to the specified node. NodeToIP(ctx context.Context, providerID string) (string, error) // CreateIP creates a new floating IP. CreateIP(ctx context.Context, region string) (string, error) }
IPProvider defines a platform which offers kubernetes VMs and floating ips.
type MockDNSProvider ¶
type MockDNSProvider struct { EnsureDNSARecordSetFunc func(ctx context.Context, zone, recordName string, ips []string, ttl int) error RecordNameAndZoneToFQDNFunc func(zone, recordName string) string }
MockDNSProvider implements the DNSProvider interface for testing.
func (*MockDNSProvider) EnsureDNSARecordSet ¶
func (m *MockDNSProvider) EnsureDNSARecordSet(ctx context.Context, zone, recordName string, ips []string, ttl int) error
EnsureDNSARecordSet ensures that the record set w/ name `recordName` contains all IPs listed in `ips` and no others.
func (*MockDNSProvider) GetProviderName ¶
func (m *MockDNSProvider) GetProviderName() string
GetProviderName returns an identifier for the provider which can be used in resources.
func (*MockDNSProvider) RecordNameAndZoneToFQDN ¶
func (m *MockDNSProvider) RecordNameAndZoneToFQDN(zone, recordName string) string
RecordNameAndZoneToFQDN translates a zone+recordName into a fully-qualified domain name.
type MockIPProvider ¶
type MockIPProvider struct { IPToProviderIDFunc func(ctx context.Context, ip string) (string, error) AssignIPFunc func(ctx context.Context, ip, providerID string) error NodeToIPFunc func(ctx context.Context, providerID string) (string, error) CreateIPFunc func(ctx context.Context, region string) (string, error) }
MockIPProvider implements the IPProvider interface for testing.
func (*MockIPProvider) AssignIP ¶
func (m *MockIPProvider) AssignIP(ctx context.Context, ip, providerID string) error
AssignIP assigns a floating IP to the specified node.
func (*MockIPProvider) GetProviderName ¶
func (m *MockIPProvider) GetProviderName() string
GetProviderName returns an identifier for the provider which can be used in resources.
func (*MockIPProvider) IPToProviderID ¶
IPToProviderID loads the current assignment (as Kubernetes listed in Kubernetes core v1 NodeSpec.ProviderID for a floating IP.
type MockProvider ¶
type MockProvider struct { *MockIPProvider *MockDNSProvider }
MockProvider implements the full provider interface for testing.
func (*MockProvider) GetProviderName ¶
func (m *MockProvider) GetProviderName() string
GetProviderName returns an identifier for the provider which can be used in resources.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds active providers and the material to initialize them.
func NewRegistry ¶
func NewRegistry(opts ...RegistryOption) *Registry
NewRegistry creates a new registry with the provided options.
func (*Registry) Collect ¶
func (r *Registry) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector
func (*Registry) Describe ¶
func (r *Registry) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector
func (*Registry) Get ¶
func (r *Registry) Get(name string) BaseProvider
Get returns the named provider.
func (*Registry) Init ¶
Init attempts to initialize all registries with credentials loaded from the environment.
func (*Registry) Register ¶
func (r *Registry) Register(name string, p BaseProvider)
Register adds a provider to the registry.
func (*Registry) RegisterCloudflare ¶
func (r *Registry) RegisterCloudflare(opts ...CloudflareOption) error
RegisterCloudflare creates the Cloudflare DNS provider and registers it in the registry.
func (*Registry) RegisterDigitalOcean ¶
func (r *Registry) RegisterDigitalOcean(opts ...DigitalOceanOption) error
RegisterDigitalOcean creates the DigitalOcean provider and registers it in the registry.
type RegistryOption ¶
type RegistryOption func(*Registry)
RegistryOption describes an option function for Registry.
func WithLogger ¶
func WithLogger(log logrus.FieldLogger) RegistryOption
WithLogger sets a logger on the registry which can be used when initializing providers.
func WithProvider ¶
func WithProvider(p BaseProvider) RegistryOption
WithProvider initializes the registry with the specified provider.
type RetrySchedule ¶
RetrySchedule defines a schedule for retrying on errors.
func ErrorToRetrySchedule ¶
func ErrorToRetrySchedule(err error) RetrySchedule
ErrorToRetrySchedule returns a retry schedule appropriate for the given error type, or a default slow retry if the error is unknown.
func (RetrySchedule) After ¶
func (r RetrySchedule) After(retries int) time.Duration
After returns the duration we should wait before our next attempt.
func (RetrySchedule) Equal ¶
func (r RetrySchedule) Equal(o RetrySchedule) bool
Equal returns true if o is equal to this retry schedule, false otherwise.