scalewaygo

package
v0.0.0-...-148ffa3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

Scaleway REST API Client

This package implements a minimal REST API client for Scaleway Kapsule API.

It only implements endpoints used by the Scaleway Cloud Provider, it is intended to be a drop-in replacement for scaleway-sdk-go.

Documentation

Index

Constants

View Source
const (
	// NodeStatusCreating indicates that node is provisioning the underlying instance/BM
	NodeStatusCreating = NodeStatus("creating")
	// NodeStatusStarting indicates that node is being configured and/or booting
	NodeStatusStarting = NodeStatus("starting")
	// NodeStatusRegistering indicates that underlying node has booted and k8s services are starting
	NodeStatusRegistering = NodeStatus("registering")
	// NodeStatusNotReady indicates that k8s has marked this node as `NotReady`
	NodeStatusNotReady = NodeStatus("not_ready")
	// NodeStatusReady indicates that node is ready for use
	NodeStatusReady = NodeStatus("ready")
	// NodeStatusDeleting indicates that node is being deleted
	NodeStatusDeleting = NodeStatus("deleting")
	// NodeStatusDeleted indicates that node is deleted
	NodeStatusDeleted = NodeStatus("deleted")
	// NodeStatusLocked indicates that node has been locked for legal reasons
	NodeStatusLocked = NodeStatus("locked")
	// NodeStatusRebooting indicates that node is rebooting
	NodeStatusRebooting = NodeStatus("rebooting")
	// NodeStatusCreationError indicates that node failed to create
	NodeStatusCreationError = NodeStatus("creation_error")
	// NodeStatusUpgrading indicates that this node CP is currently upgrading k8s version
	NodeStatusUpgrading = NodeStatus("upgrading")
)
View Source
const (
	PoolStatusReady     = PoolStatus("ready")
	PoolStatusDeleting  = PoolStatus("deleting")
	PoolStatusDeleted   = PoolStatus("deleted")
	PoolStatusScaling   = PoolStatus("scaling")
	PoolStatusWarning   = PoolStatus("warning")
	PoolStatusLocked    = PoolStatus("locked")
	PoolStatusUpgrading = PoolStatus("upgrading")
)

These are possible statuses for a scaleway pool

Variables

View Source
var (
	// ErrMissingClusterID is returned when no cluster id has been found
	// either in env variables or in config file
	ErrMissingClusterID = errors.New("cluster ID is not provided")
	// ErrMissingSecretKey is returned  when no secret key has been found
	// either in env variables or in config file
	ErrMissingSecretKey = errors.New("scaleway secret key is not provided")
	// ErrMissingRegion is returned when no region has been found
	// either in env variables or in config file
	ErrMissingRegion = errors.New("region is not provided")

	// ErrClientSide indicates an error on user side
	ErrClientSide = errors.New("400 error type")
	// ErrServerSide indicates an error on server side
	ErrServerSide = errors.New("500 error type")
	// ErrOther indicates a generic HTTP error
	ErrOther = errors.New("generic error type")
)

Functions

func NewClient

func NewClient(cfg Config) (*client, error)

NewClient returns a new Client able to talk to Scaleway API

Types

type Client

type Client interface {
	GetPool(ctx context.Context, req *GetPoolRequest) (*Pool, error)
	ListPools(ctx context.Context, req *ListPoolsRequest) (*ListPoolsResponse, error)
	UpdatePool(ctx context.Context, req *UpdatePoolRequest) (*Pool, error)
	ListNodes(ctx context.Context, req *ListNodesRequest) (*ListNodesResponse, error)
	DeleteNode(ctx context.Context, req *DeleteNodeRequest) (*Node, error)
}

Client is used to talk to Scaleway Kapsule API

type Config

type Config struct {
	ClusterID string `json:"cluster_id"`
	SecretKey string `json:"secret_key"`
	Region    string `json:"region"`
	ApiUrl    string `json:"api_url"`
	UserAgent string
}

Config is used to deserialize config file passed with flag `cloud-config`

type DeleteNodeRequest

type DeleteNodeRequest struct {
	NodeID string `json:"-"`
}

DeleteNodeRequest is passed to `DeleteNode` method

type GenericNodeSpecs

type GenericNodeSpecs struct {
	NodePricePerHour        float32           `json:"node_price_per_hour"`
	MaxPods                 uint32            `json:"max_pods"`
	Gpu                     uint32            `json:"gpu"`
	CpuCapacity             uint32            `json:"cpu_capacity"`
	CpuAllocatable          uint32            `json:"cpu_allocatable"`
	MemoryCapacity          uint64            `json:"memory_capacity"`
	MemoryAllocatable       uint64            `json:"memory_allocatable"`
	LocalStorageCapacity    uint64            `json:"local_storage_capacity"`
	LocalStorageAllocatable uint64            `json:"local_storage_allocatable"`
	Labels                  map[string]string `json:"labels"`
	Taints                  map[string]string `json:"taints"`
}

GenericNodeSpecs represents NodeType specs used for scale-up simulations. it is used to select the appropriate pool to scale-up.

type GetPoolRequest

type GetPoolRequest struct {
	// PoolID: the ID of the requested pool
	PoolID string `json:"-"`
}

GetPoolRequest is passed to `GetPool` method

type ListNodesRequest

type ListNodesRequest struct {
	// ClusterID: the cluster ID from which the nodes will be listed from
	ClusterID string `json:"-"`
	// PoolID: the pool ID on which to filter the returned nodes
	PoolID *string `json:"-"`
	// Page: the page number for the returned nodes
	Page *int32 `json:"-"`
	// PageSize: the maximum number of nodes per page
	PageSize *uint32 `json:"-"`
}

ListNodesRequest is passed to `ListNodes` method

type ListNodesResponse

type ListNodesResponse struct {
	// TotalCount: the total number of nodes
	TotalCount uint32 `json:"total_count"`
	// Nodes: the paginated returned nodes
	Nodes []*Node `json:"nodes"`
}

ListNodesResponse is returned from `ListNodes` method

type ListPoolsRequest

type ListPoolsRequest struct {
	// the ID of the cluster from which the pools will be listed from
	ClusterID string `json:"-"`
	// Page: the page number for the returned pools
	Page *int32 `json:"-"`
	// PageSize: the maximum number of pools per page
	PageSize *uint32 `json:"-"`
}

ListPoolsRequest is passed to `ListPools` method it can be used for optional pagination

type ListPoolsResponse

type ListPoolsResponse struct {
	// TotalCount: the total number of pools that exists for the cluster
	TotalCount uint32 `json:"total_count"`
	// Pools: the paginated returned pools
	Pools []*PoolWithGenericNodeSpecs `json:"pools"`
}

ListPoolsResponse is returned from `ListPools` method

type Node

type Node struct {
	// ID: the ID of the node
	ID string `json:"id"`
	// PoolID: the pool ID of the node
	PoolID string `json:"pool_id"`
	// ClusterID: the cluster ID of the node
	ClusterID string `json:"cluster_id"`
	// ProviderID: the underlying instance ID
	ProviderID string `json:"provider_id"`
	// Name: the name of the node
	Name string `json:"name"`
	// Status: the status of the node
	Status NodeStatus `json:"status"`
	// CreatedAt: the date at which the node was created
	CreatedAt *time.Time `json:"created_at"`
	// UpdatedAt: the date at which the node was last updated
	UpdatedAt *time.Time `json:"updated_at"`
}

Node represents an instance running in a scaleway pool

type NodeStatus

type NodeStatus string

NodeStatus is the state in which a node might be

type Pool

type Pool struct {
	// ID: the ID of the pool
	ID string `json:"id"`
	// ClusterID: the cluster ID of the pool
	ClusterID string `json:"cluster_id"`
	// CreatedAt: the date at which the pool was created
	CreatedAt *time.Time `json:"created_at"`
	// UpdatedAt: the date at which the pool was last updated
	UpdatedAt *time.Time `json:"updated_at"`
	// Name: the name of the pool
	Name string `json:"name"`
	// Status: the status of the pool
	Status PoolStatus `json:"status"`
	// Version: the version of the pool
	Version string `json:"version"`
	// NodeType: the node type is the type of Scaleway Instance wanted for the pool
	NodeType string `json:"node_type"`
	// Autoscaling: the enablement of the autoscaling feature for the pool
	Autoscaling bool `json:"autoscaling"`
	// Size: the size (number of nodes) of the pool
	Size uint32 `json:"size"`
	// MinSize: the minimum size of the pool
	MinSize uint32 `json:"min_size"`
	// MaxSize: the maximum size of the pool
	MaxSize uint32 `json:"max_size"`
	// Zone: the zone where the nodes will be spawn in
	Zone string `json:"zone"`
}

Pool is the abstraction used to gather nodes with the same specs

type PoolStatus

type PoolStatus string

PoolStatus is the state in which a pool might be (unused)

type PoolWithGenericNodeSpecs

type PoolWithGenericNodeSpecs struct {
	Pool  *Pool            `json:"pool"`
	Specs GenericNodeSpecs `json:"specs"`
}

PoolWithGenericNodeSpecs contains the requested `Pool` with additional `Specs` information

type UpdatePoolRequest

type UpdatePoolRequest struct {
	// PoolID: the ID of the pool to update
	PoolID string `json:"-"`
	// Size: the new size for the pool
	Size *uint32 `json:"size"`
}

UpdatePoolRequest is passed to `UpdatePool` method

Jump to

Keyboard shortcuts

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