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 ¶
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 ¶
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 ¶
AutoscaledReplicas is a workload whose replicas a HorizontalPodAutoscaler picks.
type AutoscaledResources ¶
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 ¶
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 ¶
Autoscaler is the kind of autoscaler that scales the target.
type VolumeClaimTemplate ¶
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.