nodescale

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nodescale finds cloud nodes that sit idle and could be scaled in. This release is dry run only: it reports would_destroy events and never destroys anything.

Index

Constants

View Source
const (
	// EventWouldDestroy is the only event kind; nothing is ever destroyed here.
	EventWouldDestroy = "would_destroy"
	// LabelAutoscale opts a node in when set to LabelAutoscaleOn.
	LabelAutoscale = "autoscale"
	// LabelAutoscaleOn is the opt-in value.
	LabelAutoscaleOn = "on"
	// DefaultPool names the pool of a node that matches no pool selector.
	DefaultPool = "default"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	NodeID       string   `json:"node_id"`
	NodeName     string   `json:"node_name"`
	Pool         string   `json:"pool"`
	IdleMinutes  int      `json:"idle_minutes"`
	MonthlyPrice *float64 `json:"monthly_price,omitempty"`
}

Candidate is a node a real scale-in would remove.

type Event

type Event struct {
	Kind         string    `json:"kind"`
	NodeID       string    `json:"node_id"`
	NodeName     string    `json:"node_name"`
	Pool         string    `json:"pool"`
	IdleMinutes  int       `json:"idle_minutes"`
	MonthlyPrice *float64  `json:"monthly_price,omitempty"`
	At           time.Time `json:"at"`
}

Event is one would_destroy finding.

type Node

type Node struct {
	ID   string
	Name string
	// Pools are the pools whose selector matches the node; empty means DefaultPool.
	Pools  []string
	Labels map[string]string
	// Provisioned is true when Levelrail created the node through cloud provisioning.
	Provisioned  bool
	ControlPlane bool
	// Workloads counts apps and databases placed on the node.
	Workloads int
	// HoldsVolumes is true when the node may hold the only copy of a volume,
	// for example while a volume move to or from it is running.
	HoldsVolumes bool
	// MonthlyPrice is zero when unknown.
	MonthlyPrice float64
}

Node is what the evaluator needs to know about one node.

type Preview

type Preview struct {
	Enabled           bool        `json:"enabled"`
	DryRunOnly        bool        `json:"dry_run_only"`
	IdleMinutes       int         `json:"idle_minutes"`
	Candidates        []Candidate `json:"candidates"`
	MonthlySaving     float64     `json:"monthly_saving"`
	UnpricedCandidate int         `json:"unpriced_candidates"`
}

Preview is the read-only answer for the API and CLI.

type Settings

type Settings interface {
	Enabled(ctx context.Context) bool
	IdleMinutes(ctx context.Context) int
}

Settings are the runtime tunables, read on every pass.

type Source

type Source interface {
	Nodes(ctx context.Context) ([]Node, error)
}

Source lists the nodes to evaluate.

type Worker

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

Worker evaluates nodes and emits events. It holds idle timers in memory, so a restart only delays a finding, never invents one.

func New

func New(src Source, settings Settings, interval time.Duration, emit func(Event)) *Worker

New builds a worker. emit may be nil. interval is the evaluation period.

func (*Worker) Preview

func (w *Worker) Preview(ctx context.Context, now time.Time) (Preview, error)

Preview reports the current candidates without emitting anything.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

Run evaluates until ctx ends.

func (*Worker) Tick

func (w *Worker) Tick(ctx context.Context, now time.Time) []Event

Tick runs one pass and returns the events it emitted. With scale_in off it does nothing.

Jump to

Keyboard shortcuts

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