provider

package
v0.0.0-...-c7dd6ca Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const Cloudflare = "cloudflare"

Cloudflare is the provider identifier used to identify the Cloudflare provider.

View Source
const (
	// DigitalOcean is an identifier which can be used to select the godo provider.
	DigitalOcean = "digitalocean"
)
View Source
const Mock = "mock"

Mock is the provider name for the MockProvider.

Variables

View Source
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)
)
View Source
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) CreateIP

func (m *MockIPProvider) CreateIP(ctx context.Context, region string) (string, error)

CreateIP creates a new floating IP.

func (*MockIPProvider) GetProviderName

func (m *MockIPProvider) GetProviderName() string

GetProviderName returns an identifier for the provider which can be used in resources.

func (*MockIPProvider) IPToProviderID

func (m *MockIPProvider) IPToProviderID(ctx context.Context, ip string) (string, error)

IPToProviderID loads the current assignment (as Kubernetes listed in Kubernetes core v1 NodeSpec.ProviderID for a floating IP.

func (*MockIPProvider) NodeToIP

func (m *MockIPProvider) NodeToIP(ctx context.Context, providerID string) (string, error)

NodeToIP attempts to find any floating IPs bound to the specified node.

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

func (r *Registry) Init() error

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

type RetrySchedule []time.Duration

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.

func (RetrySchedule) Next

func (r RetrySchedule) Next(retries int) (int, time.Time)

Next returns the next retry for the schedule.

Directories

Path Synopsis
Package mock_godo is a generated GoMock package.
Package mock_godo is a generated GoMock package.

Jump to

Keyboard shortcuts

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