Help us shape the future of Go! Take the 2026 Go Developer Survey

nodeagentautoscaler

package
v0.2.204 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ManagedByLabel is the label used to identify DaemonSets managed by the autoscaler
	ManagedByLabel = "kubescape.io/managed-by"
	// ManagedByValue is the value for the managed-by label
	ManagedByValue = "operator-autoscaler"
	// NodeGroupLabel is the label used to identify which node group a DaemonSet targets
	NodeGroupLabelKey = "kubescape.io/node-group"

	// ArgoCD annotations to prevent pruning of operator-managed resources
	ArgoCDCompareOptionsAnnotation = "argocd.argoproj.io/compare-options"
	ArgoCDSyncOptionsAnnotation    = "argocd.argoproj.io/sync-options"
)
View Source
const (
	EventReasonCreated = "Created"
	EventReasonDeleted = "Deleted"
	EventReasonFailed  = "Failed"
)

Event reasons for Kubernetes events

Variables

This section is empty.

Functions

func GenerateDaemonSetName

func GenerateDaemonSetName(group NodeGroup) string

GenerateDaemonSetName generates a DaemonSet name for a node group

Types

type Autoscaler

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

Autoscaler manages node-agent DaemonSets based on node groups

func NewAutoscaler

func NewAutoscaler(client kubernetes.Interface, cfg config.NodeAgentAutoscalerConfig, namespace string, operatorDeploymentName string) (*Autoscaler, error)

NewAutoscaler creates a new Autoscaler instance

func (*Autoscaler) Reconcile

func (a *Autoscaler) Reconcile(ctx context.Context) (err error)

Reconcile performs a single reconciliation cycle

func (*Autoscaler) Start

func (a *Autoscaler) Start(ctx context.Context)

Start coalesces node events and periodic recovery into one reconciliation queue. Only this goroutine mutates DaemonSets; informer callbacks never block on API writes, and transient errors retry with bounded exponential backoff.

func (*Autoscaler) Stop

func (a *Autoscaler) Stop()

Stop is safe to call repeatedly and cancels an in-flight reconciliation.

type CalculatedResources

type CalculatedResources struct {
	Requests ResourcePair
	Limits   ResourcePair
}

CalculatedResources represents the calculated resource requests and limits

type NodeGroup

type NodeGroup struct {
	// LabelValue is the value of the grouping label (e.g., "m5.large")
	LabelValue string
	// SanitizedName is a DNS-safe name derived from LabelValue
	SanitizedName string
	// AllocatableCPU is the representative allocatable CPU from nodes in this group
	AllocatableCPU resource.Quantity
	// AllocatableMemory is the representative allocatable memory from nodes in this group
	AllocatableMemory resource.Quantity
	// NodeCount is the number of nodes in this group
	NodeCount int
	// ReadyNodeCount counts members eligible for resource sizing. An inventory
	// group with no ready member is retained without creating or updating its DS.
	ReadyNodeCount int
	// IsDefault is true when this group was formed from nodes missing the
	// NodeGroupLabel. Such a group cannot be targeted by a nodeSelector on the
	// (absent) label, so its DaemonSet uses a "DoesNotExist" node affinity instead.
	IsDefault bool
	// HasBottlerocket is true when at least one ready node in this group runs AWS
	// Bottlerocket OS. Such groups get the "super_t" SELinux type. Detection is
	// gated by config.BottlerocketAutoDetect.
	HasBottlerocket bool
}

NodeGroup represents a group of nodes with the same label value

type NodeGrouper

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

NodeGrouper groups nodes by label and calculates resources

func NewNodeGrouper

func NewNodeGrouper(client kubernetes.Interface, cfg config.NodeAgentAutoscalerConfig, namespace string) *NodeGrouper

NewNodeGrouper creates a new NodeGrouper

func (*NodeGrouper) CalculateResources

func (ng *NodeGrouper) CalculateResources(group NodeGroup) (CalculatedResources, error)

CalculateResources calculates the resource requests and limits for a node group

func (*NodeGrouper) GetNodeGroups

func (ng *NodeGrouper) GetNodeGroups(ctx context.Context) ([]NodeGroup, error)

GetNodeGroups returns all node groups based on the configured label

type ResourcePair

type ResourcePair struct {
	CPU    resource.Quantity
	Memory resource.Quantity
}

ResourcePair holds CPU and Memory quantities

type TemplateData

type TemplateData struct {
	// Name is the DaemonSet name (e.g., "node-agent-m5-large")
	Name string
	// NodeGroupLabel is the value of the node group label
	NodeGroupLabel string
	// NodeGroupLabelKey is the configured grouping label key (e.g.
	// "node.kubernetes.io/instance-type"). The template keys both the nodeSelector
	// and the default group's affinity off this so they always match the operator's
	// actual grouping label, even when it is overridden.
	NodeGroupLabelKey string
	// IsDefaultGroup is true for the fallback group of nodes that do not carry the
	// grouping label. The template should select these nodes via a "DoesNotExist"
	// node affinity rather than a nodeSelector matching NodeGroupLabel.
	IsDefaultGroup bool
	// Resources contains the calculated resource requests and limits
	Resources TemplateResources
	// GoMemLimit is the GOMEMLIMIT value derived from the memory limit and percentage (e.g., "360MiB")
	GoMemLimit string
	// SELinuxType is the SELinux type rendered into the node-agent container's
	// securityContext ("super_t" for Bottlerocket groups, otherwise the configured default).
	SELinuxType string
}

TemplateData holds the data used to render the DaemonSet template

type TemplateRenderer

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

TemplateRenderer loads and renders DaemonSet templates

func NewTemplateRenderer

func NewTemplateRenderer(templatePath string, goMemLimitPercentage float64, nodeGroupLabelKey string, defaultSELinuxType string) (*TemplateRenderer, error)

NewTemplateRenderer creates a new TemplateRenderer

func (*TemplateRenderer) ReloadTemplate

func (tr *TemplateRenderer) ReloadTemplate() error

ReloadTemplate reloads the template from disk

func (*TemplateRenderer) RenderDaemonSet

func (tr *TemplateRenderer) RenderDaemonSet(group NodeGroup, resources CalculatedResources) (*appsv1.DaemonSet, error)

RenderDaemonSet renders a DaemonSet for the given node group and resources

func (*TemplateRenderer) StartWatching

func (tr *TemplateRenderer) StartWatching(ctx context.Context) error

StartWatching starts watching the template file for changes When the ConfigMap is updated, Kubernetes updates the mounted file, triggering a reload

func (*TemplateRenderer) StopWatching

func (tr *TemplateRenderer) StopWatching()

StopWatching stops the file watcher

type TemplateResourcePair

type TemplateResourcePair struct {
	CPU    string
	Memory string
}

TemplateResourcePair holds CPU and Memory as strings for template rendering

type TemplateResources

type TemplateResources struct {
	Requests TemplateResourcePair
	Limits   TemplateResourcePair
}

TemplateResources holds the resource values for template rendering

Jump to

Keyboard shortcuts

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