Skip to content

Commit

Permalink
Merge pull request #2295 from saweber/saweber/gcp-g2-instance-fix
Browse files Browse the repository at this point in the history
add fix for GCP instance types that contain 'Nvidia' but not 'Nvidia Tesla' in description
  • Loading branch information
nikovacevic committed Nov 29, 2023
2 parents 1b3a267 + 7ac1699 commit 7bc5a26
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/cloud/gcp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ var gcpRegions = []string{
}

var (
nvidiaGPURegex = regexp.MustCompile("(Nvidia Tesla [^ ]+) ")
nvidiaTeslaGPURegex = regexp.MustCompile("(Nvidia Tesla [^ ]+) ")
nvidiaGPURegex = regexp.MustCompile("(Nvidia [^ ]+) ")
// gce://guestbook-12345/...
// => guestbook-12345
gceRegex = regexp.MustCompile("gce://([^/]*)/*")
Expand Down Expand Up @@ -772,13 +773,23 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]models.Key, pvKeys m
}

var gpuType string
for matchnum, group := range nvidiaGPURegex.FindStringSubmatch(product.Description) {
for matchnum, group := range nvidiaTeslaGPURegex.FindStringSubmatch(product.Description) {
if matchnum == 1 {
gpuType = strings.ToLower(strings.Join(strings.Split(group, " "), "-"))
log.Debugf("GCP Billing API: GPU type found: '%s'", gpuType)
}
}

// If a 'Nvidia Tesla' is not found, try 'Nvidia'
if gpuType == "" {
for matchnum, group := range nvidiaGPURegex.FindStringSubmatch(product.Description) {
if matchnum == 1 {
gpuType = strings.ToLower(strings.Join(strings.Split(group, " "), "-"))
log.Debugf("GCP Billing API: GPU type found: '%s'", gpuType)
}
}
}

candidateKeys := []string{}
if gcp.ValidPricingKeys == nil {
gcp.ValidPricingKeys = make(map[string]bool)
Expand Down

0 comments on commit 7bc5a26

Please sign in to comment.