api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HPAKind just to avoid mispeling
	HPAKind = "HorizontalPodAutoscaler"
	// DeploymentKind is just to avoid mispeling
	DeploymentKind = "Deployment"
	// ReplicaSetKind is just to avoid mispeling
	ReplicaSetKind = "ReplicaSet"
	// StatefulSetKind is just to avoid mispeling
	StatefulSetKind = "StatefulSet"
	// DaemonSetKind is just to avoid mispeling
	DaemonSetKind = "DaemonSet"
	// VolumeClaimKind is just to avoid mispeling
	VolumeClaimKind = "PersistentVolumeClaim"
)

Variables

SupportedKinds groups all supported kinds

Functions

This section is empty.

Types

type ClusterConfig

type ClusterConfig struct {
	NodesCount int32 `yaml:"nodesCount,omitempty"`
}

ClusterConfig is used to setup defaults for cluster

type Container

type Container struct {
	Requests Resource
	Limits   Resource
}

Container is the simplified representation of k8s Container Client doesn't need to handle different version and the complexity of k8s.io package

type Cost

type Cost struct {
	MonthlyRanges []CostRange
}

Cost groups cost range by kinda

func (*Cost) MonthlyTotal

func (c *Cost) MonthlyTotal() CostRange

MonthlyTotal returns the sum for all MonthlyRanges

func (*Cost) Subtract

func (c *Cost) Subtract(costPrev Cost) DiffCost

Subtract current total cost from previous total cost

func (*Cost) ToMarkdown

func (c *Cost) ToMarkdown() string

ToMarkdown convert to Markdown string

type CostRange

type CostRange struct {
	Kind string `json:"kind"`

	MinRequested float64 `json:"minRequested"`
	MaxRequested float64 `json:"maxRequested"`

	HPABuffer float64 `json:"hpaBuffer"` //Note: currently only supports CPU Target utilizaiton

	MinLimited float64 `json:"minLimited"`
	MaxLimited float64 `json:"maxLimited"`
}

CostRange represent the range of estimated value

func (*CostRange) Add

func (c *CostRange) Add(costRange CostRange) CostRange

Add sums the given costrange to the current costrange

func (*CostRange) Subtract

func (c *CostRange) Subtract(costRangePrev CostRange) DiffCostRange

Subtract subtracts the given costrange to the current costrange

type CostimatorConfig

type CostimatorConfig struct {
	ResourceConf ResourceConfig `yaml:"resourceConf,omitempty"`
	ClusterConf  ClusterConfig  `yaml:"clusterConf,omitempty"`
}

CostimatorConfig Defaults for not provided info in manifests

func ConfigDefaults

func ConfigDefaults() CostimatorConfig

ConfigDefaults set default values for config

type DaemonSet

type DaemonSet struct {
	APIVersionKindName string
	NodesCount         int32
	Containers         []Container
}

DaemonSet is the simplified reprsentation of k8s DaemonSet Client doesn't need to handle different version and the complexity of k8s.io package

type Deployment

type Deployment struct {
	APIVersionKindName string
	Replicas           int32
	Containers         []Container
	// contains filtered or unexported fields
}

Deployment is the simplified reprsentation of k8s deployment Client doesn't need to handle different version and the complexity of k8s.io package

type DiffCost

type DiffCost struct {
	Summary string

	CostCurr         Cost
	CostPrev         Cost
	MonthlyDiffRange DiffCostRange
	// contains filtered or unexported fields
}

DiffCost holds the total difference between two costs

func (*DiffCost) ToMarkdown

func (d *DiffCost) ToMarkdown() string

ToMarkdown convert to Markdown string

type DiffCostRange

type DiffCostRange struct {
	Kind           string
	CostCurr       CostRange
	CostPrev       CostRange
	DiffValue      CostRange
	DiffPercentage CostRange
}

DiffCostRange holds the total difference between two costs

func (*DiffCostRange) ToMarkdown

func (d *DiffCostRange) ToMarkdown() string

ToMarkdown convert to Markdown string

func (*DiffCostRange) ToPriceDetails

func (d *DiffCostRange) ToPriceDetails() PriceDetails

ToPriceDetails struct

func (*DiffCostRange) ToPriceDiff

func (d *DiffCostRange) ToPriceDiff() PriceDiff

ToPriceDiff struct

func (*DiffCostRange) ToPriceMaxDiff

func (d *DiffCostRange) ToPriceMaxDiff() PriceMaxDiff

ToPriceMaxDiff struct

func (*DiffCostRange) ToPriceSummary

func (d *DiffCostRange) ToPriceSummary() PriceSummary

ToPriceSummary struct

type GCPPriceCatalog

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

GCPPriceCatalog implementation to make call to GCP CloudCatalog

func NewGCPPriceCatalog

func NewGCPPriceCatalog(credentials []byte, conf CostimatorConfig) (GCPPriceCatalog, error)

NewGCPPriceCatalog creates a gcpResourcePrice struct with Monthly prices for cpu and memory If credentials is nil, then the default service account will be used

func (*GCPPriceCatalog) CPUMonthlyPrice

func (pc *GCPPriceCatalog) CPUMonthlyPrice() float32

CPUMonthlyPrice returns the GCP CPU price in USD

func (*GCPPriceCatalog) MemoryMonthlyPrice

func (pc *GCPPriceCatalog) MemoryMonthlyPrice() float32

MemoryMonthlyPrice returns the GCP Memory price in USD

func (*GCPPriceCatalog) PdStandardMonthlyPrice

func (pc *GCPPriceCatalog) PdStandardMonthlyPrice() float32

PdStandardMonthlyPrice returns the GCP Storage PD price in USD

type GroupVersionKind

type GroupVersionKind struct {
	Group   string
	Version string
	Kind    string
}

GroupVersionKind is the reprsentation of k8s type This object is used to to avoid sprawl of dependent library (eg. apimachinary) across the code This will allow easy migration to others library (eg. kyaml) in the future once the dependency is all encapulated into k8s_decoder.go

type HPA

type HPA struct {
	APIVersionKindName  string
	TargetRef           string
	MinReplicas         int32
	MaxReplicas         int32
	TargetCPUPercentage int32
}

HPA is the simplified reprsentation of k8s HPA Client doesn't need to handle different version and the complexity of k8s.io package

type HorizontalScalableResource

type HorizontalScalableResource interface {
	// contains filtered or unexported methods
}

HorizontalScalableResource is a Horizontal Scalable Resource Implemented by Deployment, ReplicaSet and StatefulSet

type MachineFamily

type MachineFamily string

MachineFamily type

const (
	// E2 machines
	E2 MachineFamily = "E2"
	// N1 machines
	N1 MachineFamily = "N1"
	// N2 machines
	N2 MachineFamily = "N2"
	// N2D machines
	N2D MachineFamily = "N2D"
)

type Manifests

type Manifests struct {
	Deployments []*Deployment

	ReplicaSets []*ReplicaSet

	StatefulSets []*StatefulSet

	DaemonSets   []*DaemonSet
	VolumeClaims []*VolumeClaim
	// contains filtered or unexported fields
}

Manifests holds all deployments and executes cost estimation

func (*Manifests) EstimateCost

func (m *Manifests) EstimateCost(pc GCPPriceCatalog) Cost

EstimateCost loop through all resources and group it by kind

func (*Manifests) LoadObjects

func (m *Manifests) LoadObjects(data []byte, conf CostimatorConfig) error

LoadObjects allow you to decode and load into Manifests your k8s objects For now, it only understands Deployment and HPA

func (*Manifests) LoadObjectsFromPath

func (m *Manifests) LoadObjectsFromPath(path string, conf CostimatorConfig) error

LoadObjectsFromPath loads all files from folder and subfolder finishing with yaml or yml

type PriceDetails

type PriceDetails struct {
	USD  CostRange `json:"usd"`
	Perc CostRange `json:"perc"`
}

PriceDetails ...

type PriceDiff

type PriceDiff struct {
	Summary PriceSummary `json:"summary"`
	Details PriceDetails `json:"details"`
}

PriceDiff ...

type PriceMaxDiff

type PriceMaxDiff struct {
	USD  float64 `json:"usd"`
	Perc float64 `json:"perc"`
}

PriceMaxDiff ...

type PriceSummary

type PriceSummary struct {
	PossiblyCostIncrease bool         `json:"possiblyCostIncrease"`
	MaxDiff              PriceMaxDiff `json:"maxDiff"`
}

PriceSummary ...

type ReplicaSet

type ReplicaSet struct {
	APIVersionKindName string
	Replicas           int32
	Containers         []Container
	// contains filtered or unexported fields
}

ReplicaSet is the simplified reprsentation of k8s replicaset Client doesn't need to handle different version and the complexity of k8s.io package

type Resource

type Resource struct {
	CPU     int64
	Memory  int64
	Storage int64
}

Resource is the simplified reprsentation of k8s Resource Client doesn't need to handle different version and the complexity of k8s.io package

type ResourceConfig

type ResourceConfig struct {
	MachineFamily                          MachineFamily `yaml:"machineFamily,omitempty"`
	Region                                 string        `yaml:"region,omitempty"`
	DefaultCPUinMillis                     int64         `yaml:"defaultCPUinMillis,omitempty"`
	DefaultMemoryinBytes                   int64         `yaml:"defaultMemoryinBytes,omitempty"`
	PercentageIncreaseForUnboundedRerouces int64         `yaml:"percentageIncreaseForUnboundedRerouces,omitempty"`
}

ResourceConfig is used to setup defaults for resources

type ResourcePrice

type ResourcePrice interface {
	CPUMonthlyPrice() float32
	MemoryMonthlyPrice() float32
}

ResourcePrice interface

type StatefulSet

type StatefulSet struct {
	APIVersionKindName string
	Replicas           int32
	Containers         []Container

	VolumeClaims []*VolumeClaim
	// contains filtered or unexported fields
}

StatefulSet is the simplified reprsentation of k8s StatefulSet Client doesn't need to handle different version and the complexity of k8s.io package

type StoragePrice

type StoragePrice interface {
	PdStandardMonthlyPrice() float32
}

StoragePrice interface

type VolumeClaim

type VolumeClaim struct {
	APIVersionKindName string
	StorageClass       string
	Requests           Resource
	Limits             Resource
}

VolumeClaim is the simplified reprsentation of k8s VolumeClaim Client doesn't need to handle different version and the complexity of k8s.io package

Jump to

Keyboard shortcuts

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