plugin

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// the LRU reduces the number of times the nomad server is queried to get detailed
	// information on each nomad client (which is required to identify the associated
	// droplet ID). In rare cases a droplet could become orphaned despite having registered
	// as a nomad client earlier. In such cases it won't be detected until the LRU evicts it.
	DropletMappingLRUSize   = 1024
	DropletMappingLRUExpiry = 6 * time.Hour
)

Variables

View Source
var (
	PluginConfig = &plugins.InternalPluginConfig{
		Factory: func(l hclog.Logger) interface{} {
			return NewDODropletsPlugin(context.Background(), l, Must(NewVault()))
		},
	}
)

Functions

func Must added in v0.0.5

func Must[T any](result T, err error) T

Must panics if it is given a non-nil error. Otherwise, it returns the first argument

func NewRateLimiter added in v0.0.5

func NewRateLimiter(
	burst uint32,
	rechargePeriod time.Duration,
	startFull bool,
	options ...rateLimiterOption,
) *rateLimiter

func NewVault added in v0.0.5

func NewVault() (*vaultProxy, error)

func PrependShellScriptToUserData added in v0.0.5

func PrependShellScriptToUserData(originalUserData, script string) (string, error)

PrependShellScriptToUserData will prepend a cloud-boothook section to the existing user data, which may be empty, a bare shell command, or using the cloud-config-archive format

func RetryOnTransientError added in v0.0.6

func RetryOnTransientError(
	ctx context.Context,
	logger hclog.Logger,
	f func(ctx context.Context, cancel context.CancelCauseFunc) error,
	extraCodes ...int,
) error

RetryOnTransientError will retry the provided callable if the error is one which is likely to indicate a transient error, which might just require some time to resolve. godo already handles rate-limiting, but HTTP 422s have been observed when trying to do things like conccurently assign multiple reserved IP addresses. If an unrecognise error is returned, this will exit as normal, immediately.

func Sleep added in v0.0.24

func Sleep(ctx context.Context, duration time.Duration) error

func Unarg added in v0.0.26

func Unarg[S any, T any](f func(context.Context, S, *godo.ListOptions) ([]T, *godo.Response, error), arg S) func(context.Context, *godo.ListOptions) ([]T, *godo.Response, error)

Unarg is passed a godo List* function which takes an argument prior to the ListOptions, along with the argument's value. It allows the Unpaginate generic function to be used. e.g.: Unpaginate(ctx, Unarg(dropletsService.ListByTag, template.name), godo.ListOptions{})

func Unpaginate added in v0.0.24

func Unpaginate[T any](ctx context.Context, f func(ctx context.Context, opt *godo.ListOptions) ([]T, *godo.Response, error), opt godo.ListOptions) iter.Seq2[T, error]

Unpaginate repeatedly calls a paginated List* function, returning an iterable of the returned object type.

func WithClient added in v0.0.5

func WithClient(
	reservedIPs ReservedIPs,
	reservedIPActions ReservedIPActions,
	reservedIPV6s ReservedIPV6s,
	reservedIPV6Actions ReservedIPV6Actions,
) reservedAddressesPoolOption

func WithClock added in v0.0.5

func WithClock(c quartz.Clock) reservedAddressesPoolOption

func WithDigitalOceanWrapper added in v0.0.5

func WithDigitalOceanWrapper(wrapper DigitalOceanWrapper) reservedAddressesPoolOption

func WithMockClock added in v0.0.5

func WithMockClock(m *quartz.Mock) rateLimiterOption

func WithRateLimiterOption added in v0.0.5

func WithRateLimiterOption(o rateLimiterOption) reservedAddressesPoolOption

Types

type CloudConfigArchive added in v0.0.16

type CloudConfigArchive struct {
	Parts []CloudConfigPart `json:"cloud-config-archive"`
}

func NewCloudConfigArchive added in v0.0.16

func NewCloudConfigArchive(parts ...CloudConfigPart) *CloudConfigArchive

func ParseCloudConfigArchive added in v0.0.16

func ParseCloudConfigArchive(data string) (*CloudConfigArchive, error)

func (*CloudConfigArchive) String added in v0.0.16

func (c *CloudConfigArchive) String() string

type CloudConfigPart added in v0.0.16

type CloudConfigPart struct {
	Type    string `json:"type"`
	Content string `json:"content"`
}

type DigitalOceanWrapper added in v0.0.5

type DigitalOceanWrapper interface {
	ReservedIPs() ReservedIPs
	ReservedIPV6s() ReservedIPV6s
	ReservedIPActions() ReservedIPActions
	ReservedIPV6Actions() ReservedIPV6Actions
	Droplets() Droplets
	DropletActions() DropletActions
	Tags() Tags
}

type DropletActions added in v0.0.5

type DropletActions interface {
	PowerOff(context.Context, int) (*godo.Action, *godo.Response, error)
}

type DropletIDs added in v0.0.26

type DropletIDs map[int]struct{}

type Droplets added in v0.0.5

type GodoWrapper added in v0.0.5

type GodoWrapper struct {
	Client *godo.Client
}

func (*GodoWrapper) DropletActions added in v0.0.5

func (g *GodoWrapper) DropletActions() DropletActions

func (*GodoWrapper) Droplets added in v0.0.5

func (g *GodoWrapper) Droplets() Droplets

func (*GodoWrapper) ReservedIPActions added in v0.0.5

func (g *GodoWrapper) ReservedIPActions() ReservedIPActions

func (*GodoWrapper) ReservedIPV6Actions added in v0.0.5

func (g *GodoWrapper) ReservedIPV6Actions() ReservedIPV6Actions

func (*GodoWrapper) ReservedIPV6s added in v0.0.5

func (g *GodoWrapper) ReservedIPV6s() ReservedIPV6s

func (*GodoWrapper) ReservedIPs added in v0.0.5

func (g *GodoWrapper) ReservedIPs() ReservedIPs

func (*GodoWrapper) Tags added in v0.0.5

func (g *GodoWrapper) Tags() Tags

type PrereservedIP added in v0.0.5

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

func (*PrereservedIP) String added in v0.0.5

func (p *PrereservedIP) String() string

type PrereservedIPV6 added in v0.0.5

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

type ReservedAddressesPool added in v0.0.5

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

func CreateReservedAddressesPool added in v0.0.5

func CreateReservedAddressesPool(
	logger hclog.Logger,
	options ...reservedAddressesPoolOption,
) *ReservedAddressesPool

func (*ReservedAddressesPool) AssignIPv4 added in v0.0.5

func (r *ReservedAddressesPool) AssignIPv4(
	ctx context.Context,
	dropletID int,
	ipv4 string,
) error

func (*ReservedAddressesPool) AssignIPv6 added in v0.0.5

func (r *ReservedAddressesPool) AssignIPv6(
	ctx context.Context,
	dropletID int,
	ipv6 string,
) error

func (*ReservedAddressesPool) PrereserveIPV6s added in v0.0.5

func (r *ReservedAddressesPool) PrereserveIPV6s(
	ctx context.Context,
	count int,
	region string,
	createIfRequired bool,
	expiry time.Duration,
) ([]string, error)

PrereserveIPV6s will find and return the specified number of reserved IP addresses. They will be provisionally reserved, meaning subsequent calls to this function will not return the same addresses until the expiry period has elapsed

func (*ReservedAddressesPool) PrereserveIPs added in v0.0.5

func (r *ReservedAddressesPool) PrereserveIPs(
	ctx context.Context,
	count int,
	region string,
	createIfRequired bool,
	expiry time.Duration,
) ([]string, error)

PrereserveIPs will find and return the specified number of reserved IP addresses. They will be provisionally reserved, meaning subsequent calls to this function will not return the same addresses until the expiry period has elapsed

type ReservedIPActions added in v0.0.5

type ReservedIPActions interface {
	Assign(context.Context, string, int) (*godo.Action, *godo.Response, error)
}

type ReservedIPV6Actions added in v0.0.5

type ReservedIPV6Actions interface {
	Assign(context.Context, string, int) (*godo.Action, *godo.Response, error)
}

type ReservedIPV6s added in v0.0.5

type ReservedIPs added in v0.0.5

type TargetPlugin

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

TargetPlugin is the DigitalOcean implementation of the target.Target interface.

func NewDODropletsPlugin

func NewDODropletsPlugin(ctx context.Context, log hclog.Logger, vault VaultProxy) *TargetPlugin

NewDODropletsPlugin returns the DO Droplets implementation of the target.Target interface.

func (*TargetPlugin) PluginInfo

func (t *TargetPlugin) PluginInfo() (*base.PluginInfo, error)

PluginInfo satisfies the PluginInfo function on the base.Base interface.

func (*TargetPlugin) Scale

func (t *TargetPlugin) Scale(action sdk.ScalingAction, config map[string]string) error

Scale satisfies the Scale function on the target.Target interface.

func (*TargetPlugin) SetConfig

func (t *TargetPlugin) SetConfig(config map[string]string) error

SetConfig satisfies the SetConfig function on the base.Base interface.

func (*TargetPlugin) Status

func (t *TargetPlugin) Status(config map[string]string) (*sdk.TargetStatus, error)

Status satisfies the Status function on the target.Target interface.

type VaultProxy added in v0.0.5

type VaultProxy interface {
	// GenerateSecretId creates a new vault secretID for the approle which can only be accessed from the specified IP addresses.
	// Returns the wrapping token to be used to retrieve the SecretID
	GenerateSecretId(
		ctx context.Context,
		appRole string,
		allowedIPv4, allowedIPv6 string,
		secretValidity, wrapperValidity time.Duration,
	) (string, error)
}

Jump to

Keyboard shortcuts

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