cloud

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectRegion

func DetectRegion(node *v1.Node) string

func RegisterCloudProvider

func RegisterCloudProvider(name ProviderKind, cloud Factory)

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 {
	DiscountedCost   string `json:"discountedHourlyCost"`
	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 Cloud

todo: move the cloud to a staging src for a common lib for crane community

func GetCloudProvider

func GetCloudProvider(name ProviderKind, cloudConfig io.Reader, priceConfig *PriceConfig, cache *cache.Cache) (Cloud, 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 InitCloudProvider

func InitCloudProvider(CloudOpts CloudConfig, priceConfig *PriceConfig, cache *cache.Cache) (Cloud, error)

InitCloudProvider creates a cloud provider instance.

type CloudCacher

type CloudCacher interface {
	WarmUp() error
	Refresh()
}

type CloudConfig

type CloudConfig struct {
	CloudConfigFile string `json:"cloudConfigFile"`
	Provider        string `json:"provider"`
}

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 datasource-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

type CustomPricing

type CustomPricing struct {
	Region           string  `json:"region"`
	Provider         string  `json:"provider"`
	Description      string  `json:"description"`
	CpuHourlyPrice   float64 `json:"cpuHourlyPrice"`
	RamGBHourlyPrice float64 `json:"ramGBHourlyPrice"`
}

type Factory

type Factory func(cloudConfig io.Reader, priceConfig *PriceConfig, cache *cache.Cache) (Cloud, error)

Factory is a function that returns a cloud.Cloud. 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 NodePricer

type NodePricer interface {
	NodePrice(spec spec.CloudNodeSpec) (*Node, error)
}

type NodeSpecConverter

type NodeSpecConverter interface {
	Node2Spec(node *v1.Node) spec.CloudNodeSpec
}

type PlatformKind

type PlatformKind string
const (
	ServerlessKind PlatformKind = "serverless"
	ServerfulKind  PlatformKind = "serverful"
)

type PlatformParameter

type PlatformParameter struct {
	// cluster nodes number
	Nodes        *int32
	ClusterLevel *string
	Platform     PlatformKind
}

type PlatformPricer

type PlatformPricer interface {
	PlatformPrice(cp PlatformParameter) *Prices
}

type Pod

type Pod struct {
	BaseInstancePrice
}

type PodPricer

type PodPricer interface {
	// ServerlessPodPrice means this is a serverless pod instance, such as TencentCloud EKS pod, or AliCloud ECI
	ServerlessPodPrice(spec spec.CloudPodSpec) (*Pod, error)
	// PodPrice means this pod is in the non-serverless real node. the node is not virtual kubelet. not used now
	PodPrice(spec spec.CloudPodSpec) (*Pod, error)
}

type PodSpecConverter

type PodSpecConverter interface {
	Pod2Spec(pod *v1.Pod) spec.CloudPodSpec
	Pod2ServerlessSpec(pod *v1.Pod) spec.CloudPodSpec
}

type Price

type Price struct {
	InstanceType string     `json:"instanceType"`
	ChargeType   string     `json:"chargeType"`
	Memory       string     `json:"memory"`
	VCpu         string     `json:"vcpu"`
	CvmPrice     *PriceItem `json:"cvmPrice,omitempty"`
}

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 Pricer

type Pricer interface {
	NodePricer
	PodPricer
	PlatformPricer
}

type Prices

type Prices struct {
	TotalPrice    float64
	DiscountPrice *float64
}

? cost means [price * timespan]. maybe we refine the price and cost meaning later, now the price and cost is same

type ProviderKind

type ProviderKind string
const (
	TencentCloud ProviderKind = "qcloud"
	DefaultCloud ProviderKind = "default"
)

func DetectProvider

func DetectProvider(node *v1.Node) ProviderKind

Jump to

Keyboard shortcuts

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