Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CSV provider lookup precedence does not seem correct #2310

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions pkg/cloud/provider/csvprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,60 +228,65 @@ func (k *csvKey) ID() string {
return k.ProviderID
}

func (c *CSVProvider) NodePricing(key models.Key) (*models.Node, models.PricingMetadata, error) {
c.DownloadPricingDataLock.RLock()
defer c.DownloadPricingDataLock.RUnlock()
meta := models.PricingMetadata{}
var node *models.Node
func (c *CSVProvider) nodePricing(key models.Key) *models.Node {
if p, ok := c.Pricing[key.ID()]; ok {
node = &models.Node{
return &models.Node{
Cost: p.MarketPriceHourly,
PricingType: models.CsvExact,
}
}

s := strings.Split(key.ID(), ",") // Try without a region to be sure
if len(s) == 2 {
if p, ok := c.Pricing[s[1]]; ok {
node = &models.Node{
return &models.Node{
Cost: p.MarketPriceHourly,
PricingType: models.CsvExact,
}
}
}

classKey := key.Features() // Use node attributes to try and do a class match
if cost, ok := c.NodeClassPricing[classKey]; ok {
log.Infof("Unable to find provider ID `%s`, using features:`%s`", key.ID(), key.Features())
node = &models.Node{
return &models.Node{
Cost: fmt.Sprintf("%f", cost),
PricingType: models.CsvClass,
}
}

if node != nil {
if t := key.GPUType(); t != "" {
t = strings.ToLower(t)
count := key.GPUCount()
node.GPU = strconv.Itoa(count)
hourly := 0.0
if p, ok := c.GPUClassPricing[t]; ok {
var err error
hourly, err = strconv.ParseFloat(p.MarketPriceHourly, 64)
if err != nil {
log.Errorf("Unable to parse %s as float", p.MarketPriceHourly)
}
}
totalCost := hourly * float64(count)
node.GPUCost = fmt.Sprintf("%f", totalCost)
nc, err := strconv.ParseFloat(node.Cost, 64)
return nil
}

func (c *CSVProvider) NodePricing(key models.Key) (*models.Node, models.PricingMetadata, error) {
c.DownloadPricingDataLock.RLock()
defer c.DownloadPricingDataLock.RUnlock()

node := c.nodePricing(key)
if node == nil {
return nil, models.PricingMetadata{}, fmt.Errorf("Unable to find Node matching `%s`:`%s`", key.ID(), key.Features())
}
if t := key.GPUType(); t != "" {
t = strings.ToLower(t)
count := key.GPUCount()
node.GPU = strconv.Itoa(count)
hourly := 0.0
if p, ok := c.GPUClassPricing[t]; ok {
var err error
hourly, err = strconv.ParseFloat(p.MarketPriceHourly, 64)
if err != nil {
log.Errorf("Unable to parse %s as float", node.Cost)
log.Errorf("Unable to parse %s as float", p.MarketPriceHourly)
}
node.Cost = fmt.Sprintf("%f", nc+totalCost)
}
return node, meta, nil
} else {
return nil, meta, fmt.Errorf("Unable to find Node matching `%s`:`%s`", key.ID(), key.Features())
totalCost := hourly * float64(count)
node.GPUCost = fmt.Sprintf("%f", totalCost)
nc, err := strconv.ParseFloat(node.Cost, 64)
if err != nil {
log.Errorf("Unable to parse %s as float", node.Cost)
}
node.Cost = fmt.Sprintf("%f", nc+totalCost)
}
return node, models.PricingMetadata{}, nil
}

func NodeValueFromMapField(m string, n *v1.Node, useRegion bool) string {
Expand Down
Loading
Loading