gsc

package module
v0.0.0-...-811cdb2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 16 Imported by: 7

README

gardener-scaling-common

[!NOTE] Presently, this is 🚧 WIP prototype for Proof of Concept only.

A module that encapsulates

  1. Go Types that represent common scaling related entities of Gardener Kubernetes Cluster. See API Types
  2. Common Go-Client Utility functions in Client Util

Consumers

This is currently consumed by

  1. Gardener Scaling History
  2. Gardener Virtual Autoscaler
  3. Gardener Scaling Recommender

Documentation

Index

Constants

View Source
const LabelVirtualScaled = "virtual-scaled"
View Source
const PodScheduleCommited = 1
View Source
const PodScheduleNominated = -1
View Source
const PodSchedulePending = -2
View Source
const PodUnscheduled = 0
View Source
const PoolLabel = "worker.gardener.cloud/pool"
View Source
const PoolLabelAlt = "worker_gardener_cloud_pool"
View Source
const PoolLabelAlt1 = "worker.gardener.cloud_pool"

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")
View Source
var ZoneLabels = []string{"topology.kubernetes.io/zone", "topology.gke.io/zone", "topology.ebs.csi.aws.com/zone", "topology.disk.csi.azure.com/zone", "failure-domain.beta.kubernetes.io/zone"}

Functions

func AsIntOrString

func AsIntOrString(val any) (target intstr.IntOrString, err error)

func AsQuantity

func AsQuantity(str string) (norm resource.Quantity, err error)

func BoolToBytes

func BoolToBytes(b bool) []byte

func CmpNodeInfoDescending

func CmpNodeInfoDescending(a, b NodeInfo) int

func CompareEventsByEventTime

func CompareEventsByEventTime(a, b EventInfo) int

func ContainsPod

func ContainsPod(podUID string, podInfos []PodInfo) bool

func CumulatePodRequests

func CumulatePodRequests(pod *corev1.Pod) corev1.ResourceList

func GetInnerMap

func GetInnerMap(parentMap map[string]any, keys ...string) (map[string]any, error)

func GetInnerMapValue

func GetInnerMapValue(parentMap map[string]any, keys ...string) (any, error)

func GetLabelValue

func GetLabelValue(labelMap map[string]string, labelNames []string) (labelValue string, ok bool)

func GetPoolName

func GetPoolName(labels map[string]string) (label string, ok bool)

func GetZone

func GetZone(labels map[string]string) (label string, ok bool)

func GetZoneAnyMap

func GetZoneAnyMap(labelsMap map[string]any) string

func HashBool

func HashBool(hasher hash.Hash, val bool)

func HashDuration

func HashDuration(hasher hash.Hash, d time.Duration)

func HashInt

func HashInt(hasher hash.Hash, val int)

func HashInt64

func HashInt64(hasher hash.Hash, val int64)

func HashLabels

func HashLabels(hasher hash.Hash, labels map[string]string)

func HashResource

func HashResource(hasher hash.Hash, name corev1.ResourceName, quantity resource.Quantity)

func HashResources

func HashResources(hasher hash.Hash, resources corev1.ResourceList)

func HashSlice

func HashSlice[T ~string](hasher hash.Hash, strSlice []T)

func HashTaints

func HashTaints(hasher hash.Hash, taints []corev1.Taint)

func IsEqualNodeInfo

func IsEqualNodeInfo(a, b NodeInfo) bool

func IsEqualPodInfo

func IsEqualPodInfo(a, b PodInfo) bool

func IsEqualQuantity

func IsEqualQuantity(a, b resource.Quantity) bool

func IsEqualTaint

func IsEqualTaint(a, b corev1.Taint) bool

func IsResourceListEqual

func IsResourceListEqual(r1 corev1.ResourceList, r2 corev1.ResourceList) bool

func MustParseQuantity

func MustParseQuantity(str string) (norm resource.Quantity)

MustParseQuantity parses given str as normalized quantity or panics. NOTE: ONLY USE FOR UNIT TESTS OR LITERALS

func NormalizeQuantity

func NormalizeQuantity(q resource.Quantity) (norm resource.Quantity, err error)

func ResourcesAsString

func ResourcesAsString(resources corev1.ResourceList) string

func SumResources

func SumResources(resources []corev1.ResourceList) corev1.ResourceList

Types

type AutoscalerConfig

type AutoscalerConfig struct {
	NodeTemplates     map[string]NodeTemplate
	NodeGroups        map[string]NodeGroupInfo
	ExistingNodes     []NodeInfo
	CASettings        CASettingsInfo
	Mode              AutoscalerMode
	SuccessSignalPath string
	ErrorSignalPath   string
	Hash              string
}

func (AutoscalerConfig) GetHash

func (a AutoscalerConfig) GetHash() string

func (*AutoscalerConfig) Init

func (c *AutoscalerConfig) Init() error

type AutoscalerMode

type AutoscalerMode string
const AutoscalerReplayerPauseMode AutoscalerMode = "replay-mode-pause"
const AutoscalerReplayerRunMode AutoscalerMode = "replay-mode-run"
const AutoscalerStandaloneMode AutoscalerMode = "standalone-mode"

type CASettingsInfo

type CASettingsInfo struct {
	SnapshotTimestamp             time.Time
	Expander                      string
	NodeGroupsMinMax              map[string]MinMax
	MaxNodeProvisionTime          time.Duration
	ScanInterval                  time.Duration
	MaxGracefulTerminationSeconds int
	NewPodScaleUpDelay            time.Duration
	MaxEmptyBulkDelete            int
	IgnoreDaemonSetUtilization    bool
	MaxNodesTotal                 int `db:"MaxNodesTotal"`
	// Priorities is the value of the `priorities` key in the `cluster-autoscaler-priority-expander` config map.
	// See https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/expander/priority/readme.md#configuration
	Priorities string
	Hash       string //primary key
}

CASettingsInfo represents configuration settings of the k8s cluster-autoscaler. This is currently a very minimal struct only capturing those options that can be configured in a gardener shoot spec. TODO Also add scale down properties

func (CASettingsInfo) GetHash

func (cas CASettingsInfo) GetHash() string

func (CASettingsInfo) String

func (cas CASettingsInfo) String() string

type ClusterSnapshot

type ClusterSnapshot struct {
	ID               string
	Number           int
	SnapshotTime     time.Time
	AutoscalerConfig AutoscalerConfig
	WorkerPools      []WorkerPoolInfo
	PriorityClasses  []PriorityClassInfo
	Pods             []PodInfo
	Nodes            []NodeInfo
	Hash             string
}

ClusterSnapshot represents captured snapshot information about a gardener cluster that is useful for auto-scaling state.

func (ClusterSnapshot) GetHash

func (c ClusterSnapshot) GetHash() string

func (ClusterSnapshot) GetPodNamspaces

func (c ClusterSnapshot) GetPodNamspaces() sets.Set[string]

func (ClusterSnapshot) GetPodUIDs

func (c ClusterSnapshot) GetPodUIDs() sets.Set[string]

func (ClusterSnapshot) GetPodsWithScheduleStatus

func (c ClusterSnapshot) GetPodsWithScheduleStatus(status PodScheduleStatus) []PodInfo

func (ClusterSnapshot) GetPriorityClassUIDs

func (c ClusterSnapshot) GetPriorityClassUIDs() sets.Set[string]

func (ClusterSnapshot) HasSameUnscheduledPods

func (c ClusterSnapshot) HasSameUnscheduledPods(other ClusterSnapshot) bool

type EventInfo

type EventInfo struct {
	UID                     string    `db:"UID"`
	EventTime               time.Time `db:"EventTime"`
	ReportingController     string    `db:"ReportingController"`
	Reason                  string    `db:"Reason"`
	Message                 string    `db:"Message"`
	InvolvedObjectKind      string    `db:"InvolvedObjectKind"`
	InvolvedObjectName      string    `db:"InvolvedObjectName"`
	InvolvedObjectNamespace string    `db:"InvolvedObjectNamespace"`
	InvolvedObjectUID       string    `db:"InvolvedObjectUID"`
}

EventInfo represents information about an event emitted in the k8s cluster.

func (EventInfo) String

func (eI EventInfo) String() string

type MachineDeploymentInfo

type MachineDeploymentInfo struct {
	SnapshotMeta
	Replicas          int
	PoolName          string
	Zone              string
	MaxSurge          intstr.IntOrString
	MaxUnavailable    intstr.IntOrString
	MachineClassName  string
	DeletionTimestamp time.Time
	Labels            map[string]string
	Taints            []corev1.Taint
	Hash              string
}

MachineDeploymentInfo represents snapshot information captured about the MCM MachineDeployment object present in the control plane of a gardener shoot cluster.

func (MachineDeploymentInfo) GetHash

func (m MachineDeploymentInfo) GetHash() string

func (MachineDeploymentInfo) String

func (m MachineDeploymentInfo) String() string

type MinMax

type MinMax struct {
	Min int
	Max int
}

func (MinMax) String

func (m MinMax) String() string

type NodeGroupInfo

type NodeGroupInfo struct {
	Name       string
	PoolName   string
	Zone       string
	TargetSize int
	MinSize    int
	MaxSize    int
	Hash       string
}

func (NodeGroupInfo) GetHash

func (ng NodeGroupInfo) GetHash() string

func (NodeGroupInfo) String

func (ng NodeGroupInfo) String() string

type NodeInfo

type NodeInfo struct {
	SnapshotMeta
	ProviderID         string
	AllocatableVolumes int
	Labels             map[string]string
	Taints             []corev1.Taint
	Allocatable        corev1.ResourceList
	Capacity           corev1.ResourceList
	DeletionTimestamp  time.Time
	Hash               string
}

NodeInfo represents snapshot information captured about an active k8s Node in the cluster at a particular moment in time. . A NodeInfo snapshot is only captured if there is a change in the properties excepting for DeletionTimestamp, in which case the DeletionTimestamp is only updated.

func (NodeInfo) GetHash

func (n NodeInfo) GetHash() string

func (NodeInfo) String

func (n NodeInfo) String() string

type NodeTemplate

type NodeTemplate struct {
	Name string
	//CPU              resource.Quantity
	//GPU              resource.Quantity
	//Memory           resource.Quantity
	//EphemeralStorage resource.Quantity
	InstanceType string
	Region       string
	Zone         string
	Capacity     corev1.ResourceList
	Allocatable  corev1.ResourceList
	Labels       map[string]string
	Taints       []corev1.Taint
	Hash         string
}

func (NodeTemplate) GetHash

func (t NodeTemplate) GetHash() string

type PodInfo

type PodInfo struct {
	SnapshotMeta
	UID               string
	NodeName          string
	NominatedNodeName string
	Labels            map[string]string
	Requests          corev1.ResourceList
	Spec              corev1.PodSpec
	PodScheduleStatus PodScheduleStatus
	DeletionTimestamp time.Time
	Hash              string
}

PodInfo represents snapshot information captured about a k8s Pod deployed into the cluster at a particular moment in time. When the `Pod` is deleted its `DeletionTimestamp` is updated.

func (PodInfo) GetHash

func (p PodInfo) GetHash() string

func (PodInfo) String

func (p PodInfo) String() string

type PodScheduleStatus

type PodScheduleStatus int

type PriorityClassInfo

type PriorityClassInfo struct {
	RowID             int64
	SnapshotTimestamp time.Time
	Hash              string
	schedulingv1.PriorityClass
}

func (PriorityClassInfo) GetHash

func (p PriorityClassInfo) GetHash() string

func (PriorityClassInfo) String

func (p PriorityClassInfo) String() string

type SnapshotMeta

type SnapshotMeta struct {
	RowID             int64
	CreationTimestamp time.Time
	SnapshotTimestamp time.Time
	Name              string
	Namespace         string
}

type WorkerPoolInfo

type WorkerPoolInfo struct {
	SnapshotMeta
	MachineType       string
	Architecture      string
	Minimum           int
	Maximum           int
	MaxSurge          intstr.IntOrString
	MaxUnavailable    intstr.IntOrString
	Zones             []string
	Labels            map[string]string
	Taints            []corev1.Taint
	DeletionTimestamp time.Time
	Hash              string
}

WorkerPoolInfo represents snapshot information corresponding to the gardener shoot worker pool.

func (WorkerPoolInfo) GetHash

func (w WorkerPoolInfo) GetHash() string

func (WorkerPoolInfo) String

func (w WorkerPoolInfo) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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