instancegroup

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package instancegroup is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseHandler

type BaseHandler struct{}

BaseHandler configure the instance server create options with the instance group configuration.

func (*BaseHandler) Create

func (h *BaseHandler) Create(_ context.Context, _ *instanceGroup, instance *Instance) error

type CleanupHandler

type CleanupHandler interface {
	// Cleanup is run once per instance during a decrease and potentially an increase.
	// Any error during this phase will be stored and the instance will be passed to the
	// next handler.
	Cleanup(ctx context.Context, group *instanceGroup, instance *Instance) error
}

type Config

type Config struct {
	// Location is the Scaleway "Zone" name to create the server in.
	// Refer to https://www.scaleway.com/en/docs/account/reference-content/products-availability/ to list available zones.
	Zone string

	// ServerNamePrefix is the prefix of the server name. The server name will be
	// generated by appending a random suffix to this prefix.
	ServerNamePrefix string

	// ServerTypes is a list of Scaleway "Server Type" names or ids to create the server with.
	// Run `scw instance server-type list` to list available server types.
	// The system will check availability of each type and filter out types with shortage.
	// Then it will attempt to create a server with each available type in order until one succeeds.
	// Both "available" and "scarce" availability states are accepted; only "shortage" is filtered out.
	ServerTypes []string

	// PublicIPv4Disabled indicates whether the server should be created without a public IPv4 address.
	// If set to true, the server will not have a public IPv4 address.
	PublicIPv4Disabled bool

	// PublicIPv6Disabled indicates whether the server should be created without a public IPv6 address.
	// If set to true, the server will not have a public IPv6 address.
	PublicIPv6Disabled bool

	// PrivateNetworkIDs is a list of private networks IDs to attach the server to.
	// Run `scw vpc private-network list` to list available private networks.
	PrivateNetworkIDs []string

	// Image is the Scaleway "Image" (name or id) to create the server with. Run
	// `scw image list` to list available images.
	Image string

	// CloudInit is the data available to initialization framework that may run after the
	// server boot.
	CloudInit string

	// VolumeType is the type of volume to attach to the server. It must be either empty, 'l_ssd', 'b_ssd' or 'sbs_volume'.
	VolumeType string

	// VolumeSize is the size in GB of the volume that will be attached to the server.
	VolumeSize uint16

	// VolumeIops is the number of IOPS to allocate for the volume.
	VolumeIops uint16

	// Tags is a list of tags to apply to the server.
	Tags []string
}

type CreateHandler

type CreateHandler interface {
	// Create is run once per instance during an increase. Any error during this phase
	// will be stored and the instance will be marked as failed and will not be passed
	// to the next handler.
	Create(ctx context.Context, group *instanceGroup, instance *Instance) error
}

type Instance

type Instance struct {
	// Name of the instance, used for the underlying server and other attached resources.
	Name string
	// ID of the instance's underlying server.
	ID string
	// ServerType is the commercial type of the server (e.g., "GP1-XS", "DEV1-L").
	// This field is populated after server creation and is included in the IID for visibility.
	ServerType string

	// Server is the instance's underlying server, and must never be partially populated.
	Server *scwInstance.Server
	// contains filtered or unexported fields
}

func InstanceFromIID

func InstanceFromIID(value string) (*Instance, error)

func InstanceFromServer

func InstanceFromServer(server *scwInstance.Server) *Instance

func NewInstance

func NewInstance(name string) *Instance

func (*Instance) IID

func (i *Instance) IID() string

IID holds the data to identify the instance outside of the instance group.

Formats:

  • Legacy: "name:id" (no server type)
  • With server type: "name:id:server-type"

Example: "scaleway-dev1-l-80gb:abc123-server-id:gp1-xs"

The server type is included so users can see which SKU was actually provisioned, especially useful when fallback to alternative types occurs.

func (*Instance) Label

func (i *Instance) Label() string

type InstanceGroup

type InstanceGroup interface {
	Init(ctx context.Context) error

	Increase(ctx context.Context, delta int) ([]string, error)
	Decrease(ctx context.Context, iids []string) ([]string, error)

	List(ctx context.Context) ([]*Instance, error)
	Get(ctx context.Context, iid string) (*Instance, error)

	Sanity(ctx context.Context) error
}

func New

func New(client *scw.Client, log hclog.Logger, name string, config Config) InstanceGroup

type MockInstanceGroup

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

MockInstanceGroup is a mock of InstanceGroup interface.

func NewMockInstanceGroup

func NewMockInstanceGroup(ctrl *gomock.Controller) *MockInstanceGroup

NewMockInstanceGroup creates a new mock instance.

func (*MockInstanceGroup) Decrease

func (m *MockInstanceGroup) Decrease(ctx context.Context, iids []string) ([]string, error)

Decrease mocks base method.

func (*MockInstanceGroup) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockInstanceGroup) Get

func (m *MockInstanceGroup) Get(ctx context.Context, iid string) (*Instance, error)

Get mocks base method.

func (*MockInstanceGroup) Increase

func (m *MockInstanceGroup) Increase(ctx context.Context, delta int) ([]string, error)

Increase mocks base method.

func (*MockInstanceGroup) Init

func (m *MockInstanceGroup) Init(ctx context.Context) error

Init mocks base method.

func (*MockInstanceGroup) List

func (m *MockInstanceGroup) List(ctx context.Context) ([]*Instance, error)

List mocks base method.

func (*MockInstanceGroup) Sanity

func (m *MockInstanceGroup) Sanity(ctx context.Context) error

Sanity mocks base method.

type MockInstanceGroupMockRecorder

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

MockInstanceGroupMockRecorder is the mock recorder for MockInstanceGroup.

func (*MockInstanceGroupMockRecorder) Decrease

func (mr *MockInstanceGroupMockRecorder) Decrease(ctx, iids any) *gomock.Call

Decrease indicates an expected call of Decrease.

func (*MockInstanceGroupMockRecorder) Get

func (mr *MockInstanceGroupMockRecorder) Get(ctx, iid any) *gomock.Call

Get indicates an expected call of Get.

func (*MockInstanceGroupMockRecorder) Increase

func (mr *MockInstanceGroupMockRecorder) Increase(ctx, delta any) *gomock.Call

Increase indicates an expected call of Increase.

func (*MockInstanceGroupMockRecorder) Init

Init indicates an expected call of Init.

func (*MockInstanceGroupMockRecorder) List

List indicates an expected call of List.

func (*MockInstanceGroupMockRecorder) Sanity

func (mr *MockInstanceGroupMockRecorder) Sanity(ctx any) *gomock.Call

Sanity indicates an expected call of Sanity.

type PreDecreaseHandler

type PreDecreaseHandler interface {
	// PreDecrease is run before a decrease. Any error during this phase will stop the
	// decrease.
	PreDecrease(ctx context.Context, group *instanceGroup) error
}

type PreIncreaseHandler

type PreIncreaseHandler interface {
	// PreIncrease is run before an increase. Any error during this phase will stop the
	// increase.
	PreIncrease(ctx context.Context, group *instanceGroup) error
}

type SanityHandler

type SanityHandler interface {
	// Sanity is run once per sanity check. Any error during this phase will only be
	// logged.
	Sanity(ctx context.Context, group *instanceGroup) error
}

type ServerHandler

type ServerHandler struct{}

ServerHandler implements transactional instance creation with automatic rollback. If Create() fails at any step, all partially created resources are immediately cleaned up via a deferred Cleanup call. This ensures no orphaned resources remain.

func (*ServerHandler) Cleanup

func (h *ServerHandler) Cleanup(ctx context.Context, group *instanceGroup, instance *Instance) error

Cleanup is idempotent and safe to call multiple times on the same instance. It handles missing resources (404) gracefully and retries transient API errors. Resources are discovered both by direct server lookup and by tag-based search, ensuring orphaned resources from partial failures are also cleaned up.

func (*ServerHandler) Create

func (h *ServerHandler) Create(ctx context.Context, group *instanceGroup, instance *Instance) error

func (*ServerHandler) Sanity added in v0.5.0

func (h *ServerHandler) Sanity(ctx context.Context, group *instanceGroup) error

Jump to

Keyboard shortcuts

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