Documentation
¶
Index ¶
- func DetectRegion(node *v1.Node) string
- func RegisterCloudProvider(name string, cloud Factory)
- func SetCustomPricing(obj *CustomPricing, name string, value string) error
- type BaseInstancePrice
- type ChargeType
- type CloudConfig
- type CloudPrice
- type CustomPricing
- type Factory
- type Node
- type Pod
- type Price
- type PriceConfig
- type PriceItem
- type ProviderType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectRegion ¶
func RegisterCloudProvider ¶
RegisterCloudProvider registers a cloudsdk.Factory by name. This is expected to happen during app startup.
func SetCustomPricing ¶
func SetCustomPricing(obj *CustomPricing, name string, value string) error
Types ¶
type BaseInstancePrice ¶
type BaseInstancePrice struct {
Cost string `json:"hourlyCost"`
Cpu string `json:"cpu"`
CpuHourlyCost string `json:"cpuHourlyCost"`
Ram string `json:"ram"`
RamBytes string `json:"ramBytes"`
RamGBHourlyCost string `json:"ramGBHourlyCost"`
UsesDefaultPrice bool `json:"usesDefaultPrice"`
// Used to compute an implicit CPU Core/Hr price when CPU pricing is not provided.
DefaultCpuPrice string `json:"defaultCpuPrice"`
// Used to compute an implicit RAM GB/Hr price when RAM pricing is not provided.
DefaultRamPrice string `json:"defaultRamPrice"`
// Default or ChargeType
UsageType string `json:"usageType"`
InstanceType string `json:"instanceType,omitempty"`
Region string `json:"region,omitempty"`
ProviderID string `json:"providerID,omitempty"`
}
type ChargeType ¶
type ChargeType string
type CloudConfig ¶
type CloudPrice ¶
type CloudPrice interface {
// UpdateConfigFromConfigMap update CustomPricing from configmap
UpdateConfigFromConfigMap(map[string]string) (*CustomPricing, error)
// GetConfig return CustomPricing
GetConfig() (*CustomPricing, error)
// GetNodeCost a model to compute each node cpu and ram unit price cost.
/**
This is an idea from FinOps, because the traditional billing and pricing system for cloud resource is not adaptive to cloud native resource.
cost model is a way to estimate and breakdown the resource price to each container or pod.
!!! Note cost model is just used to estimate cost not to replace the billing, because real billing depends on the billing system.
!!! model is an experimental implementation of the cost allocation and showback & chargeback from the FinOps.
1. The simplest cost model is to estimate a resource price of all nodes or pods by the same price.
for example, when compute costs, you can assume all container's cpu & ram unit price is the same, 2$ Core/Hour, 0.3$ Gib/Hour
2. Advanced cost model is to estimate a resource price by cost breakdown.
this theory is based on each cloud machine instance is different price with different instance type and charge type.
so the containers in different node type or eks pod has different price
*/
// GetNodesCost, key is node name
// GetNodesCost get all the real nodes price of kubernetes cluster.
GetNodesCost() (map[string]*Node, error)
// GetPodsCost get the eks or tke pod price.
// if the pod is in the real node of kubernetes cluster, then its price is computed from the instance backed the node by cost breakdown.
// if the pod is in virtual node of kubernetes cluster, then its price came from the pod billing directly or the virtual machine instance price backed the the pod.
// Note!!! In distributed cloud, the cluster master maybe in one cloud provider, but the nodes in the cluster maybe in multiple clouds from different cloud providers
// so the node and pod pricing is crossing clouds, currently do not support it.
// GetPodsCost, key is namespace/name
// This interface is better for unified real node or vk node, because we get pod costs, then we get container costs too.
GetPodsCost() (map[string]*Pod, error)
// OnNodeDelete
OnNodeDelete(node *v1.Node) error
// OnNodeAdd
OnNodeAdd(node *v1.Node) error
// OnNodeUpdate
OnNodeUpdate(old, new *v1.Node) error
// IsVirtualNode detects the node is virtual node.
IsVirtualNode(node *v1.Node) bool
WarmUp() error
Refresh()
GetNodesPricing() (map[string]*Price, error)
}
cross cloud pricing
func GetCloudProvider ¶
func GetCloudProvider(name string, cloudConfig io.Reader, priceConfig *PriceConfig, cache *cache.Cache) (CloudPrice, error)
GetCloudProvider creates an instance of the named price provider, or nil if the name is unknown. The error return is only used if the named provider was known but failed to initialize. The config parameter specifies the io.Reader handler of the configuration file for the price provider, or nil for no configuration.
func InitPriceProvider ¶
func InitPriceProvider(CloudOpts CloudConfig, priceConfig *PriceConfig, cache *cache.Cache) (CloudPrice, error)
InitPriceProvider creates a price provider instance.
type CustomPricing ¶
type Factory ¶
type Factory func(cloudConfig io.Reader, priceConfig *PriceConfig, cache *cache.Cache) (CloudPrice, error)
Factory is a function that returns a cloudsdk.Interface. The config parameter provides an io.Reader handler to the factory in order to load specific configurations. If no configuration is provided the parameter is nil.
type Node ¶
type Node struct {
BaseInstancePrice
}
type Pod ¶
type Pod struct {
BaseInstancePrice
}
type PriceConfig ¶
type PriceConfig struct {
// contains filtered or unexported fields
}
func NewProviderConfig ¶
func NewProviderConfig(customPricing *CustomPricing) *PriceConfig
func (*PriceConfig) GetConfig ¶
func (pc *PriceConfig) GetConfig() (*CustomPricing, error)
GetConfig return CustomPricing
func (*PriceConfig) UpdateConfigFromConfigMap ¶
func (pc *PriceConfig) UpdateConfigFromConfigMap(priceConf map[string]string) (*CustomPricing, error)
UpdateConfigFromConfigMap update CustomPricing from configmap
type PriceItem ¶
type PriceItem struct {
UnitPrice *float64 `json:"unitPrice,omitempty" name:"unitPrice"`
ChargeUnit *string `json:"chargeUnit,omitempty" name:"chargeUnit"`
OriginalPrice *float64 `json:"originalPrice,omitempty" name:"originalPrice"`
DiscountPrice *float64 `json:"discountPrice,omitempty" name:"discountPrice"`
Discount *float64 `json:"discount,omitempty" name:"discount"`
UnitPriceDiscount *float64 `json:"unitPriceDiscount,omitempty" name:"unitPriceDiscount"`
UnitPriceSecondStep *float64 `json:"unitPriceSecondStep,omitempty" name:"unitPriceSecondStep"`
UnitPriceDiscountSecondStep *float64 `json:"unitPriceDiscountSecondStep,omitempty" name:"unitPriceDiscountSecondStep"`
UnitPriceThirdStep *float64 `json:"unitPriceThirdStep,omitempty" name:"unitPriceThirdStep"`
UnitPriceDiscountThirdStep *float64 `json:"unitPriceDiscountThirdStep,omitempty" name:"unitPriceDiscountThirdStep"`
OriginalPriceThreeYear *float64 `json:"originalPriceThreeYear,omitempty" name:"originalPriceThreeYear"`
DiscountPriceThreeYear *float64 `json:"discountPriceThreeYear,omitempty" name:"discountPriceThreeYear"`
DiscountThreeYear *float64 `json:"discountThreeYear,omitempty" name:"discountThreeYear"`
OriginalPriceFiveYear *float64 `json:"originalPriceFiveYear,omitempty" name:"originalPriceFiveYear"`
DiscountPriceFiveYear *float64 `json:"discountPriceFiveYear,omitempty" name:"discountPriceFiveYear"`
DiscountFiveYear *float64 `json:"discountFiveYear,omitempty" name:"discountFiveYear"`
OriginalPriceOneYear *float64 `json:"originalPriceOneYear,omitempty" name:"originalPriceOneYear"`
DiscountPriceOneYear *float64 `json:"discountPriceOneYear,omitempty" name:"discountPriceOneYear"`
DiscountOneYear *float64 `json:"discountOneYear,omitempty" name:"discountOneYear"`
}
type ProviderType ¶
type ProviderType string
const ( TencentCloud ProviderType = "qcloud" DefaultCloud ProviderType = "default" )
func DetectProvider ¶
func DetectProvider(node *v1.Node) ProviderType