func retrievePrices()

in cost-optimization/gke-shift-left-cost/api/resource_price.go [61:103]


func retrievePrices(client *billing.CloudCatalogClient, conf CostimatorConfig) (GCPPriceCatalog, error) {
	skuIter, err := retrieveAllSKUs(client)

	var cpuPi, memoryPi, storagePdPi *billingpb.PricingInfo
	for {
		sku, err := skuIter.Next()
		if err == iterator.Done ||
			(cpuPi != nil && memoryPi != nil && storagePdPi != nil) {
			break
		}
		if err != nil {
			return GCPPriceCatalog{}, err
		}

		if cpuPi == nil && matchCPU(sku, conf) {
			cpuPi = sku.GetPricingInfo()[0]
		} else if memoryPi == nil && matchMemory(sku, conf) {
			memoryPi = sku.GetPricingInfo()[0]
		} else if storagePdPi == nil && matchGCEPersistentDisk(sku, conf) {
			storagePdPi = sku.GetPricingInfo()[0]
		}
	}
	if err == nil && (cpuPi == nil || memoryPi == nil || storagePdPi == nil) {
		return GCPPriceCatalog{}, fmt.Errorf("Couldn't find all Price Infos: %+v", conf)
	}

	cpuPrice, err := calculateMonthlyPrice(cpuPi)
	if err != nil {
		return GCPPriceCatalog{}, err
	}
	memoryPrice, err := calculateMonthlyPrice(memoryPi)
	if err != nil {
		return GCPPriceCatalog{}, err
	}
	pdStandardPrice, err := calculateMonthlyPrice(storagePdPi)
	if err != nil {
		return GCPPriceCatalog{}, err
	}
	return GCPPriceCatalog{
		cpuPrice:        cpuPrice,
		memoryPrice:     memoryPrice,
		pdStandardPrice: pdStandardPrice}, nil
}