calc

package
v0.0.0-...-12a9c2f Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package calc provides function to calculate resource quotas for different k8s resources.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrResourceNotSupported is returned if a k8s resource is not supported by kuota-calc.
	ErrResourceNotSupported = errors.New("resource not supported")
)

Functions

func ConvertToRuntimeObjectFromYaml

func ConvertToRuntimeObjectFromYaml(yamlData []byte, suppressWarningForUnregisteredKind bool) (object runtime.Object, kind, version *string, err error)

ConvertToRuntimeObjectFromYaml decodes a yaml document into a k8s object. If the kind is not found, it will display a warning.

Types

type CalculationError

type CalculationError struct {
	Version string
	Kind    string
	// contains filtered or unexported fields
}

CalculationError is an error implementation that includes a k8s Kind/Version.

func (CalculationError) Error

func (cErr CalculationError) Error() string

func (CalculationError) Unwrap

func (cErr CalculationError) Unwrap() error

Unwrap implements the errors.Unwrap interface.

type Details

type Details struct {
	Version     string
	Kind        string
	Name        string
	Strategy    string
	Replicas    int32
	MaxReplicas int32
	Hpa         bool
}

Details contains a few details of a k8s resource, which are needed to generate a detailed resource usage report.

type PodResources

type PodResources struct {
	Containers     Resources
	InitContainers Resources
	MaxResources   Resources
}

PodResources contain the sum of the resources required by the initContainer, the normal containers and the maximum the pod can require at any time for each resource quantity. In other words, max(Containers.MinCPU, InitContainers.MinCPU), max(Containers.MaxCPU, InitContainers.MaxCPU), etc.

type ResourceObject

type ResourceObject struct {
	Object       runtime.Object
	Kind         string
	Version      string
	LinkedObject runtime.Object
}

ResourceObject is a struct that contains a k8s object, its kind and version and an optional linked object.

type ResourceUsage

type ResourceUsage struct {
	NormalResources  Resources
	RolloutResources Resources
	Details          Details
}

ResourceUsage summarizes the usage of compute resources for a k8s resource.

func ResourceQuotaFromYaml

func ResourceQuotaFromYaml(resourceObject ResourceObject) (*ResourceUsage, error)

ResourceQuotaFromYaml decodes a single yaml document into a k8s object. Then performs a type assertion on the object and calculates the resource needs of it. Currently supported: * apps.openshift.io/v1 - DeploymentConfig * apps/v1 - Deployment * apps/v1 - StatefulSet * apps/v1 - DaemonSet * batch/v1 - CronJob * batch/v1 - Job * v1 - Pod

type Resources

type Resources struct {
	CPUMin    resource.Quantity
	CPUMax    resource.Quantity
	MemoryMin resource.Quantity
	MemoryMax resource.Quantity
}

Resources contains the limits and requests for cpu and memory that are typically used in kubernetes and openshift. Can be used to apply arithmetic operations equally on all quantities.

func ConvertToResources

func ConvertToResources(req *v1.ResourceRequirements) Resources

ConvertToResources converts a kubernetes/openshift ResourceRequirements struct to a Resources struct

func Total

func Total(maxRollout int, usage []*ResourceUsage) Resources

Total calculates the sum of all usages. maxRollout limits how many simultaneous rollouts are assumed. Negative maxRollout value -> unlimited rollouts.

func (Resources) Add

func (r Resources) Add(y Resources) Resources

Add adds the provided y resources to the current value.

func (Resources) Mul

func (r Resources) Mul(y float64) Resources

Mul multiplies all resource values by the given multiplier.

func (Resources) MulInt32

func (r Resources) MulInt32(y int32) Resources

MulInt32 multiplies all resource values by the given multiplier.

Jump to

Keyboard shortcuts

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