resourcesize

package
v1.78.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 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 resourcesize translates the per-workload resource footprint declared in a package CR (spec.resourceRequests) - replicas, container resources and the disk sizes of volume claim templates - into nelm render patches, which nelm applies to the rendered manifests both when it renders the chart and when it installs the release.

The footprint goes into the workload and into the autoscalers of the release that target it: a HorizontalPodAutoscaler or a VerticalPodAutoscaler is pinned to the requested values, so it keeps them instead of overriding them. A requested range goes into the autoscalers alone, which keep scaling the workload within it; a range no autoscaler of the release applies falls back to fixed values in the workload instead (FallbackPatches).

It knows nothing of the CR types: callers hand it plain requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Patches

func Patches(requests []Request) ([]spec.Patch, error)

Patches translates the requests into nelm render patches: for each request, one for its workload when the request changes it, and one for each kind of autoscaler the request pins or bounds.

A request whose name holds a slash is left out: no Kubernetes object can be named that way, and nelm would read a name wrapped in slashes as a regexp, resizing every workload of the kind it matches.

func ScalingError

func ScalingError(err error) string

ScalingError returns the message of a replicas change the chart forbids, found anywhere in err's chain; "" for any other error.

Types

type Autoscaled

type Autoscaled struct {
	Replicas  []AutoscaledReplicas
	Resources []AutoscaledResources
}

Autoscaled is what the autoscalers of a release control: the replicas a HorizontalPodAutoscaler picks and the container resources a VerticalPodAutoscaler sets. A range of a request applies only through them.

type AutoscaledReplicas

type AutoscaledReplicas struct {
	Kind string
	Name string
}

AutoscaledReplicas is a workload whose replicas a HorizontalPodAutoscaler picks.

type AutoscaledResources

type AutoscaledResources struct {
	Kind      string
	Name      string
	Container string
	Resources []string
}

AutoscaledResources is a container of a workload whose Resources, cpu or memory, a VerticalPodAutoscaler sets.

type Container

type Container struct {
	Name     string            `json:"name"`
	Requests map[string]string `json:"requests,omitempty"`
	Limits   map[string]string `json:"limits,omitempty"`
	Min      map[string]string `json:"min,omitempty"`
	Max      map[string]string `json:"max,omitempty"`
}

Container pins the compute resources of one container inside a workload.

Keys are Kubernetes resource names (cpu, memory, ephemeral-storage) and values are quantities in string form, already validated by the CR schema. The maps are merged key by key into whatever the chart rendered, so setting only memory leaves the chart's cpu alone; there is no way to unset a resource the chart declares.

Min and Max bound the cpu and memory requests a VerticalPodAutoscaler of the workload picks for the container, keyed and valued the same way. They reach the autoscaler alone, unless none sizes the container: Min then becomes its request and Max its limit. They exclude cpu and memory in Requests and Limits.

type Request

type Request struct {
	// Kind of the workload, one of the kinds in podSpecPaths.
	Kind string `json:"kind"`
	// Name of the workload as the chart renders it.
	Name string `json:"name"`
	// Replicas to run, nil to keep what the chart renders. Only meaningful for
	// the kinds in replicaKinds.
	Replicas *int32 `json:"replicas,omitempty"`
	// MinReplicas and MaxReplicas bound the replicas a HorizontalPodAutoscaler
	// of the workload picks, nil to keep the autoscaler's own bound. They
	// exclude Replicas and leave the workload's replicas as the chart renders
	// them, unless no autoscaler scales the workload: it then runs MinReplicas.
	// Only meaningful for the kinds in replicaKinds.
	MinReplicas *int32 `json:"minReplicas,omitempty"`
	MaxReplicas *int32 `json:"maxReplicas,omitempty"`
	// Containers to resize, addressed by name.
	Containers []Container `json:"containers"`
	// VolumeClaimTemplates to resize, addressed by name. Only meaningful for a
	// StatefulSet.
	VolumeClaimTemplates []VolumeClaimTemplate `json:"volumeClaimTemplates,omitempty"`
}

Request pins or bounds the resource footprint of one workload a package deploys. Kind and Name address the workload; both are required and together they are unique, which the CR schema enforces with a keyed list.

The fields added for disks and ranges are omitted when empty, so a request that does not use them encodes as before and the settings checksum built from it does not change.

type Target

type Target struct {
	Kind string
	Name string
	// Container is empty for the replicas.
	Container string
	// Resource is "replicas", cpu or memory.
	Resource string
}

Target is what an autoscaler scales: the replicas of a workload, or the cpu or memory of one of its containers.

func FallbackPatches

func FallbackPatches(requests []Request, autoscaled Autoscaled) ([]Target, []spec.Patch, error)

FallbackPatches returns the targets whose range no autoscaler of the release applies, with the render patches that apply the ranges to their workloads as fixed values: the replicas as minReplicas, a resource as a request of its min and a limit of its max. A workload guards the replicas with its annotations as it does replicas asked for directly.

The patches add to the ones Patches builds for the same requests, which leave the workload alone for a range.

func Pins

func Pins(requests []Request, autoscaled Autoscaled) []Target

Pins returns the targets the requests fix by value although an autoscaler of the release scales them: the patches pin the autoscaler to the value, so it stops scaling. Zero replicas pin nothing, as they go to the workload alone.

func (Target) Autoscaler

func (t Target) Autoscaler() string

Autoscaler is the kind of autoscaler that scales the target.

type VolumeClaimTemplate

type VolumeClaimTemplate struct {
	Name    string `json:"name"`
	Storage string `json:"storage"`
}

VolumeClaimTemplate pins the storage one volume claim template of a StatefulSet requests, a quantity in string form already validated by the CR schema. It sizes only the claims the StatefulSet creates from now on: the claims it has already created are not in the release.

Jump to

Keyboard shortcuts

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