azureprovider.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package cloud
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io"
  7. "net/url"
  8. "os"
  9. "regexp"
  10. "strconv"
  11. "strings"
  12. "sync"
  13. "github.com/kubecost/cost-model/pkg/clustercache"
  14. "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-09-01/skus"
  15. "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
  16. "github.com/Azure/azure-sdk-for-go/services/preview/commerce/mgmt/2015-06-01-preview/commerce"
  17. "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-06-01/subscriptions"
  18. "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
  19. "github.com/Azure/go-autorest/autorest"
  20. "github.com/Azure/go-autorest/autorest/azure"
  21. "github.com/Azure/go-autorest/autorest/azure/auth"
  22. v1 "k8s.io/api/core/v1"
  23. "k8s.io/klog"
  24. )
  25. const (
  26. AzurePremiumStorageClass = "premium"
  27. AzureStandardStorageClass = "standard"
  28. )
  29. var (
  30. regionCodeMappings = map[string]string{
  31. "ap": "asia",
  32. "au": "australia",
  33. "br": "brazil",
  34. "ca": "canada",
  35. "eu": "europe",
  36. "fr": "france",
  37. "in": "india",
  38. "ja": "japan",
  39. "kr": "korea",
  40. "uk": "uk",
  41. "us": "us",
  42. "za": "southafrica",
  43. }
  44. //mtBasic, _ = regexp.Compile("^BASIC.A\\d+[_Promo]*$")
  45. //mtStandardA, _ = regexp.Compile("^A\\d+[_Promo]*$")
  46. mtStandardB, _ = regexp.Compile(`^Standard_B\d+m?[_v\d]*[_Promo]*$`)
  47. mtStandardD, _ = regexp.Compile(`^Standard_D\d[_v\d]*[_Promo]*$`)
  48. mtStandardE, _ = regexp.Compile(`^Standard_E\d+i?[_v\d]*[_Promo]*$`)
  49. mtStandardF, _ = regexp.Compile(`^Standard_F\d+[_v\d]*[_Promo]*$`)
  50. mtStandardG, _ = regexp.Compile(`^Standard_G\d+[_v\d]*[_Promo]*$`)
  51. mtStandardL, _ = regexp.Compile(`^Standard_L\d+[_v\d]*[_Promo]*$`)
  52. mtStandardM, _ = regexp.Compile(`^Standard_M\d+[m|t|l]*s[_v\d]*[_Promo]*$`)
  53. mtStandardN, _ = regexp.Compile(`^Standard_N[C|D|V]\d+r?[_v\d]*[_Promo]*$`)
  54. )
  55. type regionParts []string
  56. func (r regionParts) String() string {
  57. var result string
  58. for _, p := range r {
  59. result += p
  60. }
  61. return result
  62. }
  63. func getRegions(service string, subscriptionsClient subscriptions.Client, providersClient resources.ProvidersClient, subscriptionID string) (map[string]string, error) {
  64. allLocations := make(map[string]string)
  65. supLocations := make(map[string]string)
  66. // retrieve all locations for the subscription id (some of them may not be supported by the required provider)
  67. if locations, err := subscriptionsClient.ListLocations(context.TODO(), subscriptionID); err == nil {
  68. // fill up the map: DisplayName - > Name
  69. for _, loc := range *locations.Value {
  70. allLocations[*loc.DisplayName] = *loc.Name
  71. }
  72. } else {
  73. return nil, err
  74. }
  75. // identify supported locations for the namespace and resource type
  76. const (
  77. providerNamespaceForCompute = "Microsoft.Compute"
  78. resourceTypeForCompute = "locations/vmSizes"
  79. providerNamespaceForAks = "Microsoft.ContainerService"
  80. resourceTypeForAks = "managedClusters"
  81. )
  82. switch service {
  83. case "aks":
  84. if providers, err := providersClient.Get(context.TODO(), providerNamespaceForAks, ""); err == nil {
  85. for _, pr := range *providers.ResourceTypes {
  86. if *pr.ResourceType == resourceTypeForAks {
  87. for _, displName := range *pr.Locations {
  88. if loc, ok := allLocations[displName]; ok {
  89. supLocations[loc] = displName
  90. } else {
  91. klog.V(1).Infof("unsupported cloud region %s", loc)
  92. }
  93. }
  94. break
  95. }
  96. }
  97. } else {
  98. return nil, err
  99. }
  100. return supLocations, nil
  101. default:
  102. if providers, err := providersClient.Get(context.TODO(), providerNamespaceForCompute, ""); err == nil {
  103. for _, pr := range *providers.ResourceTypes {
  104. if *pr.ResourceType == resourceTypeForCompute {
  105. for _, displName := range *pr.Locations {
  106. if loc, ok := allLocations[displName]; ok {
  107. supLocations[loc] = displName
  108. } else {
  109. klog.V(1).Infof("unsupported cloud region %s", loc)
  110. }
  111. }
  112. break
  113. }
  114. }
  115. } else {
  116. return nil, err
  117. }
  118. return supLocations, nil
  119. }
  120. }
  121. func toRegionID(meterRegion string, regions map[string]string) (string, error) {
  122. var rp regionParts = strings.Split(strings.ToLower(meterRegion), " ")
  123. regionCode := regionCodeMappings[rp[0]]
  124. lastPart := rp[len(rp)-1]
  125. var regionIds []string
  126. if _, err := strconv.Atoi(lastPart); err == nil {
  127. regionIds = []string{
  128. fmt.Sprintf("%s%s%s", regionCode, rp[1:len(rp)-1], lastPart),
  129. fmt.Sprintf("%s%s%s", rp[1:len(rp)-1], regionCode, lastPart),
  130. }
  131. } else {
  132. regionIds = []string{
  133. fmt.Sprintf("%s%s", regionCode, rp[1:]),
  134. fmt.Sprintf("%s%s", rp[1:], regionCode),
  135. }
  136. }
  137. for _, regionID := range regionIds {
  138. if checkRegionID(regionID, regions) {
  139. return regionID, nil
  140. }
  141. }
  142. return "", fmt.Errorf("Couldn't find region")
  143. }
  144. func checkRegionID(regionID string, regions map[string]string) bool {
  145. for region := range regions {
  146. if regionID == region {
  147. return true
  148. }
  149. }
  150. return false
  151. }
  152. // AzurePricing either contains a Node or PV
  153. type AzurePricing struct {
  154. Node *Node
  155. PV *PV
  156. }
  157. type Azure struct {
  158. Pricing map[string]*AzurePricing
  159. DownloadPricingDataLock sync.RWMutex
  160. Clientset clustercache.ClusterCache
  161. Config *ProviderConfig
  162. }
  163. type azureKey struct {
  164. Labels map[string]string
  165. GPULabel string
  166. GPULabelValue string
  167. }
  168. func (k *azureKey) Features() string {
  169. region := strings.ToLower(k.Labels[v1.LabelZoneRegion])
  170. instance := k.Labels[v1.LabelInstanceType]
  171. usageType := "ondemand"
  172. return fmt.Sprintf("%s,%s,%s", region, instance, usageType)
  173. }
  174. func (k *azureKey) GPUType() string {
  175. if t, ok := k.Labels[k.GPULabel]; ok {
  176. return t
  177. }
  178. return ""
  179. }
  180. func (k *azureKey) ID() string {
  181. return ""
  182. }
  183. func (az *Azure) GetKey(labels map[string]string) Key {
  184. cfg, err := az.GetConfig()
  185. if err != nil {
  186. klog.Infof("Error loading azure custom pricing information")
  187. }
  188. // azure defaults, see https://docs.microsoft.com/en-us/azure/aks/gpu-cluster
  189. gpuLabel := "accelerator"
  190. gpuLabelValue := "nvidia"
  191. if cfg.GpuLabel != "" {
  192. gpuLabel = cfg.GpuLabel
  193. }
  194. if cfg.GpuLabelValue != "" {
  195. gpuLabelValue = cfg.GpuLabelValue
  196. }
  197. return &azureKey{
  198. Labels: labels,
  199. GPULabel: gpuLabel,
  200. GPULabelValue: gpuLabelValue,
  201. }
  202. }
  203. // CreateString builds strings effectively
  204. func createString(keys ...string) string {
  205. var b strings.Builder
  206. for _, key := range keys {
  207. b.WriteString(key)
  208. }
  209. return b.String()
  210. }
  211. func transformMachineType(subCategory string, mt []string) []string {
  212. switch {
  213. case strings.Contains(subCategory, "Basic"):
  214. return []string{createString("Basic_", mt[0])}
  215. case len(mt) == 2:
  216. return []string{createString("Standard_", mt[0]), createString("Standard_", mt[1])}
  217. default:
  218. return []string{createString("Standard_", mt[0])}
  219. }
  220. }
  221. func addSuffix(mt string, suffixes ...string) []string {
  222. result := make([]string, len(suffixes))
  223. var suffix string
  224. parts := strings.Split(mt, "_")
  225. if len(parts) > 2 {
  226. for _, p := range parts[2:] {
  227. suffix = createString(suffix, "_", p)
  228. }
  229. }
  230. for i, s := range suffixes {
  231. result[i] = createString(parts[0], "_", parts[1], s, suffix)
  232. }
  233. return result
  234. }
  235. func getMachineTypeVariants(mt string) []string {
  236. switch {
  237. case mtStandardB.MatchString(mt):
  238. return []string{createString(mt, "s")}
  239. case mtStandardD.MatchString(mt):
  240. var result []string
  241. result = append(result, addSuffix(mt, "s")[0])
  242. dsType := strings.Replace(mt, "Standard_D", "Standard_DS", -1)
  243. result = append(result, dsType)
  244. result = append(result, addSuffix(dsType, "-1", "-2", "-4", "-8")...)
  245. return result
  246. case mtStandardE.MatchString(mt):
  247. return addSuffix(mt, "s", "-2s", "-4s", "-8s", "-16s", "-32s")
  248. case mtStandardF.MatchString(mt):
  249. return addSuffix(mt, "s")
  250. case mtStandardG.MatchString(mt):
  251. var result []string
  252. gsType := strings.Replace(mt, "Standard_G", "Standard_GS", -1)
  253. result = append(result, gsType)
  254. return append(result, addSuffix(gsType, "-4", "-8", "-16")...)
  255. case mtStandardL.MatchString(mt):
  256. return addSuffix(mt, "s")
  257. case mtStandardM.MatchString(mt) && strings.HasSuffix(mt, "ms"):
  258. base := strings.TrimSuffix(mt, "ms")
  259. return addSuffix(base, "-2ms", "-4ms", "-8ms", "-16ms", "-32ms", "-64ms")
  260. case mtStandardM.MatchString(mt) && (strings.HasSuffix(mt, "ls") || strings.HasSuffix(mt, "ts")):
  261. return []string{}
  262. case mtStandardM.MatchString(mt) && strings.HasSuffix(mt, "s"):
  263. base := strings.TrimSuffix(mt, "s")
  264. return addSuffix(base, "", "m")
  265. case mtStandardN.MatchString(mt):
  266. return addSuffix(mt, "s")
  267. }
  268. return []string{}
  269. }
  270. func (az *Azure) GetManagementPlatform() (string, error) {
  271. nodes := az.Clientset.GetAllNodes()
  272. if len(nodes) > 0 {
  273. n := nodes[0]
  274. providerID := n.Spec.ProviderID
  275. if strings.Contains(providerID, "aks") {
  276. return "aks", nil
  277. }
  278. }
  279. return "", nil
  280. }
  281. // DownloadPricingData uses provided azure "best guesses" for pricing
  282. func (az *Azure) DownloadPricingData() error {
  283. az.DownloadPricingDataLock.Lock()
  284. defer az.DownloadPricingDataLock.Unlock()
  285. config, err := az.GetConfig()
  286. if err != nil {
  287. return err
  288. }
  289. var authorizer autorest.Authorizer
  290. if config.AzureClientID != "" && config.AzureClientSecret != "" && config.AzureTenantID != "" {
  291. credentialsConfig := auth.NewClientCredentialsConfig(config.AzureClientID, config.AzureClientSecret, config.AzureTenantID)
  292. a, err := credentialsConfig.Authorizer()
  293. if err != nil {
  294. return err
  295. }
  296. authorizer = a
  297. }
  298. if authorizer == nil {
  299. a, err := auth.NewAuthorizerFromEnvironment()
  300. authorizer = a
  301. if err != nil { // Failed to create authorizer from environment, try from file
  302. a, err := auth.NewAuthorizerFromFile(azure.PublicCloud.ResourceManagerEndpoint)
  303. if err != nil {
  304. return err
  305. }
  306. authorizer = a
  307. }
  308. }
  309. sClient := subscriptions.NewClient()
  310. sClient.Authorizer = authorizer
  311. rcClient := commerce.NewRateCardClient(config.AzureSubscriptionID)
  312. rcClient.Authorizer = authorizer
  313. skusClient := skus.NewResourceSkusClient(config.AzureSubscriptionID)
  314. skusClient.Authorizer = authorizer
  315. providersClient := resources.NewProvidersClient(config.AzureSubscriptionID)
  316. providersClient.Authorizer = authorizer
  317. containerServiceClient := containerservice.NewContainerServicesClient(config.AzureSubscriptionID)
  318. containerServiceClient.Authorizer = authorizer
  319. rateCardFilter := fmt.Sprintf("OfferDurableId eq 'MS-AZR-0003p' and Currency eq '%s' and Locale eq 'en-US' and RegionInfo eq '%s'", config.CurrencyCode, config.AzureBillingRegion)
  320. klog.Infof("Using ratecard query %s", rateCardFilter)
  321. result, err := rcClient.Get(context.TODO(), rateCardFilter)
  322. if err != nil {
  323. return err
  324. }
  325. allPrices := make(map[string]*AzurePricing)
  326. regions, err := getRegions("compute", sClient, providersClient, config.AzureSubscriptionID)
  327. if err != nil {
  328. return err
  329. }
  330. c, err := az.GetConfig()
  331. if err != nil {
  332. return err
  333. }
  334. baseCPUPrice := c.CPU
  335. for _, v := range *result.Meters {
  336. meterName := *v.MeterName
  337. meterRegion := *v.MeterRegion
  338. meterCategory := *v.MeterCategory
  339. meterSubCategory := *v.MeterSubCategory
  340. region, err := toRegionID(meterRegion, regions)
  341. if err != nil {
  342. continue
  343. }
  344. if !strings.Contains(meterSubCategory, "Windows") {
  345. if strings.Contains(meterCategory, "Storage") {
  346. if strings.Contains(meterSubCategory, "HDD") || strings.Contains(meterSubCategory, "SSD") {
  347. var storageClass string = ""
  348. if strings.Contains(meterName, "S4 ") {
  349. storageClass = AzureStandardStorageClass
  350. } else if strings.Contains(meterName, "P4 ") {
  351. storageClass = AzurePremiumStorageClass
  352. }
  353. if storageClass != "" {
  354. var priceInUsd float64
  355. if len(v.MeterRates) < 1 {
  356. klog.V(1).Infof("missing rate info %+v", map[string]interface{}{"MeterSubCategory": *v.MeterSubCategory, "region": region})
  357. continue
  358. }
  359. for _, rate := range v.MeterRates {
  360. priceInUsd += *rate
  361. }
  362. priceStr := fmt.Sprintf("%f", priceInUsd)
  363. key := region + "," + storageClass
  364. klog.V(4).Infof("Adding PV.Key: %s, Cost: %s", key, priceStr)
  365. allPrices[key] = &AzurePricing{
  366. PV: &PV{
  367. Cost: priceStr,
  368. Region: region,
  369. },
  370. }
  371. }
  372. }
  373. }
  374. if strings.Contains(meterCategory, "Virtual Machines") {
  375. // not available now
  376. if strings.Contains(meterSubCategory, "Promo") {
  377. continue
  378. }
  379. usageType := ""
  380. if !strings.Contains(meterName, "Low Priority") {
  381. usageType = "ondemand"
  382. } else {
  383. usageType = "preemptible"
  384. }
  385. var instanceTypes []string
  386. name := strings.TrimSuffix(meterName, " Low Priority")
  387. instanceType := strings.Split(name, "/")
  388. for _, it := range instanceType {
  389. instanceTypes = append(instanceTypes, strings.Replace(it, " ", "_", 1))
  390. }
  391. instanceTypes = transformMachineType(meterSubCategory, instanceTypes)
  392. if strings.Contains(name, "Expired") {
  393. instanceTypes = []string{}
  394. }
  395. var priceInUsd float64
  396. if len(v.MeterRates) < 1 {
  397. klog.V(1).Infof("missing rate info %+v", map[string]interface{}{"MeterSubCategory": *v.MeterSubCategory, "region": region})
  398. continue
  399. }
  400. for _, rate := range v.MeterRates {
  401. priceInUsd += *rate
  402. }
  403. priceStr := fmt.Sprintf("%f", priceInUsd)
  404. for _, instanceType := range instanceTypes {
  405. key := fmt.Sprintf("%s,%s,%s", region, instanceType, usageType)
  406. allPrices[key] = &AzurePricing{
  407. Node: &Node{
  408. Cost: priceStr,
  409. BaseCPUPrice: baseCPUPrice,
  410. },
  411. }
  412. }
  413. }
  414. }
  415. }
  416. az.Pricing = allPrices
  417. return nil
  418. }
  419. // AllNodePricing returns the Azure pricing objects stored
  420. func (az *Azure) AllNodePricing() (interface{}, error) {
  421. az.DownloadPricingDataLock.RLock()
  422. defer az.DownloadPricingDataLock.RUnlock()
  423. return az.Pricing, nil
  424. }
  425. // NodePricing returns Azure pricing data for a single node
  426. func (az *Azure) NodePricing(key Key) (*Node, error) {
  427. az.DownloadPricingDataLock.RLock()
  428. defer az.DownloadPricingDataLock.RUnlock()
  429. if n, ok := az.Pricing[key.Features()]; ok {
  430. klog.V(4).Infof("Returning pricing for node %s: %+v from key %s", key, n, key.Features())
  431. if key.GPUType() != "" {
  432. n.Node.GPU = "1" // TODO: support multiple GPUs
  433. }
  434. return n.Node, nil
  435. }
  436. klog.V(1).Infof("[Warning] no pricing data found for %s: %s", key.Features(), key)
  437. c, err := az.GetConfig()
  438. if err != nil {
  439. return nil, fmt.Errorf("No default pricing data available")
  440. }
  441. if key.GPUType() != "" {
  442. return &Node{
  443. VCPUCost: c.CPU,
  444. RAMCost: c.RAM,
  445. GPUCost: c.GPU,
  446. GPU: "1", // TODO: support multiple GPUs
  447. }, nil
  448. }
  449. return &Node{
  450. VCPUCost: c.CPU,
  451. RAMCost: c.RAM,
  452. UsesBaseCPUPrice: true,
  453. }, nil
  454. }
  455. // Stubbed NetworkPricing for Azure. Pull directly from azure.json for now
  456. func (az *Azure) NetworkPricing() (*Network, error) {
  457. cpricing, err := az.Config.GetCustomPricingData()
  458. if err != nil {
  459. return nil, err
  460. }
  461. znec, err := strconv.ParseFloat(cpricing.ZoneNetworkEgress, 64)
  462. if err != nil {
  463. return nil, err
  464. }
  465. rnec, err := strconv.ParseFloat(cpricing.RegionNetworkEgress, 64)
  466. if err != nil {
  467. return nil, err
  468. }
  469. inec, err := strconv.ParseFloat(cpricing.InternetNetworkEgress, 64)
  470. if err != nil {
  471. return nil, err
  472. }
  473. return &Network{
  474. ZoneNetworkEgressCost: znec,
  475. RegionNetworkEgressCost: rnec,
  476. InternetNetworkEgressCost: inec,
  477. }, nil
  478. }
  479. type azurePvKey struct {
  480. Labels map[string]string
  481. StorageClass string
  482. StorageClassParameters map[string]string
  483. DefaultRegion string
  484. }
  485. func (az *Azure) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) PVKey {
  486. return &azurePvKey{
  487. Labels: pv.Labels,
  488. StorageClass: pv.Spec.StorageClassName,
  489. StorageClassParameters: parameters,
  490. DefaultRegion: defaultRegion,
  491. }
  492. }
  493. func (key *azurePvKey) GetStorageClass() string {
  494. return key.StorageClass
  495. }
  496. func (key *azurePvKey) Features() string {
  497. storageClass := key.StorageClassParameters["storageaccounttype"]
  498. if strings.EqualFold(storageClass, "Premium_LRS") {
  499. storageClass = AzurePremiumStorageClass
  500. } else if strings.EqualFold(storageClass, "Standard_LRS") {
  501. storageClass = AzureStandardStorageClass
  502. }
  503. if region, ok := key.Labels[v1.LabelZoneRegion]; ok {
  504. return region + "," + storageClass
  505. }
  506. return key.DefaultRegion + "," + storageClass
  507. }
  508. func (*Azure) GetDisks() ([]byte, error) {
  509. return nil, nil
  510. }
  511. func (az *Azure) ClusterInfo() (map[string]string, error) {
  512. remote := os.Getenv(remoteEnabled)
  513. remoteEnabled := false
  514. if os.Getenv(remote) == "true" {
  515. remoteEnabled = true
  516. }
  517. m := make(map[string]string)
  518. m["name"] = "Azure Cluster #1"
  519. c, err := az.GetConfig()
  520. if err != nil {
  521. return nil, err
  522. }
  523. if c.ClusterName != "" {
  524. m["name"] = c.ClusterName
  525. }
  526. m["provider"] = "azure"
  527. m["remoteReadEnabled"] = strconv.FormatBool(remoteEnabled)
  528. m["id"] = os.Getenv(clusterIDKey)
  529. return m, nil
  530. }
  531. func (az *Azure) AddServiceKey(url url.Values) error {
  532. return nil
  533. }
  534. func (az *Azure) UpdateConfigFromConfigMap(a map[string]string) (*CustomPricing, error) {
  535. return az.Config.UpdateFromMap(a)
  536. }
  537. func (az *Azure) UpdateConfig(r io.Reader, updateType string) (*CustomPricing, error) {
  538. defer az.DownloadPricingData()
  539. return az.Config.Update(func(c *CustomPricing) error {
  540. a := make(map[string]interface{})
  541. err := json.NewDecoder(r).Decode(&a)
  542. if err != nil {
  543. return err
  544. }
  545. for k, v := range a {
  546. kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
  547. vstr, ok := v.(string)
  548. if ok {
  549. err := SetCustomPricingField(c, kUpper, vstr)
  550. if err != nil {
  551. return err
  552. }
  553. } else {
  554. sci := v.(map[string]interface{})
  555. sc := make(map[string]string)
  556. for k, val := range sci {
  557. sc[k] = val.(string)
  558. }
  559. c.SharedCosts = sc //todo: support reflection/multiple map fields
  560. }
  561. }
  562. remoteEnabled := os.Getenv(remoteEnabled)
  563. if remoteEnabled == "true" {
  564. err := UpdateClusterMeta(os.Getenv(clusterIDKey), c.ClusterName)
  565. if err != nil {
  566. return err
  567. }
  568. }
  569. return nil
  570. })
  571. }
  572. func (az *Azure) GetConfig() (*CustomPricing, error) {
  573. c, err := az.Config.GetCustomPricingData()
  574. if c.Discount == "" {
  575. c.Discount = "0%"
  576. }
  577. if c.NegotiatedDiscount == "" {
  578. c.NegotiatedDiscount = "0%"
  579. }
  580. if c.CurrencyCode == "" {
  581. c.CurrencyCode = "USD"
  582. }
  583. if c.AzureBillingRegion == "" {
  584. c.AzureBillingRegion = "US"
  585. }
  586. if err != nil {
  587. return nil, err
  588. }
  589. return c, nil
  590. }
  591. func (az *Azure) ExternalAllocations(string, string, []string, string, string, bool) ([]*OutOfClusterAllocation, error) {
  592. return nil, nil
  593. }
  594. func (az *Azure) ApplyReservedInstancePricing(nodes map[string]*Node) {
  595. }
  596. func (az *Azure) PVPricing(pvk PVKey) (*PV, error) {
  597. az.DownloadPricingDataLock.RLock()
  598. defer az.DownloadPricingDataLock.RUnlock()
  599. pricing, ok := az.Pricing[pvk.Features()]
  600. if !ok {
  601. klog.V(4).Infof("Persistent Volume pricing not found for %s: %s", pvk.GetStorageClass(), pvk.Features())
  602. return &PV{}, nil
  603. }
  604. return pricing.PV, nil
  605. }
  606. func (az *Azure) GetLocalStorageQuery(window, offset string, rate bool) string {
  607. return ""
  608. }