azureprovider.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. // rate is in disk per month, resolve price per hour, then GB per hour
  363. pricePerHour := priceInUsd / 730.0 / 32.0
  364. priceStr := fmt.Sprintf("%f", pricePerHour)
  365. key := region + "," + storageClass
  366. klog.V(4).Infof("Adding PV.Key: %s, Cost: %s", key, priceStr)
  367. allPrices[key] = &AzurePricing{
  368. PV: &PV{
  369. Cost: priceStr,
  370. Region: region,
  371. },
  372. }
  373. }
  374. }
  375. }
  376. if strings.Contains(meterCategory, "Virtual Machines") {
  377. // not available now
  378. if strings.Contains(meterSubCategory, "Promo") {
  379. continue
  380. }
  381. usageType := ""
  382. if !strings.Contains(meterName, "Low Priority") {
  383. usageType = "ondemand"
  384. } else {
  385. usageType = "preemptible"
  386. }
  387. var instanceTypes []string
  388. name := strings.TrimSuffix(meterName, " Low Priority")
  389. instanceType := strings.Split(name, "/")
  390. for _, it := range instanceType {
  391. instanceTypes = append(instanceTypes, strings.Replace(it, " ", "_", 1))
  392. }
  393. instanceTypes = transformMachineType(meterSubCategory, instanceTypes)
  394. if strings.Contains(name, "Expired") {
  395. instanceTypes = []string{}
  396. }
  397. var priceInUsd float64
  398. if len(v.MeterRates) < 1 {
  399. klog.V(1).Infof("missing rate info %+v", map[string]interface{}{"MeterSubCategory": *v.MeterSubCategory, "region": region})
  400. continue
  401. }
  402. for _, rate := range v.MeterRates {
  403. priceInUsd += *rate
  404. }
  405. priceStr := fmt.Sprintf("%f", priceInUsd)
  406. for _, instanceType := range instanceTypes {
  407. key := fmt.Sprintf("%s,%s,%s", region, instanceType, usageType)
  408. allPrices[key] = &AzurePricing{
  409. Node: &Node{
  410. Cost: priceStr,
  411. BaseCPUPrice: baseCPUPrice,
  412. },
  413. }
  414. }
  415. }
  416. }
  417. }
  418. az.Pricing = allPrices
  419. return nil
  420. }
  421. // AllNodePricing returns the Azure pricing objects stored
  422. func (az *Azure) AllNodePricing() (interface{}, error) {
  423. az.DownloadPricingDataLock.RLock()
  424. defer az.DownloadPricingDataLock.RUnlock()
  425. return az.Pricing, nil
  426. }
  427. // NodePricing returns Azure pricing data for a single node
  428. func (az *Azure) NodePricing(key Key) (*Node, error) {
  429. az.DownloadPricingDataLock.RLock()
  430. defer az.DownloadPricingDataLock.RUnlock()
  431. if n, ok := az.Pricing[key.Features()]; ok {
  432. klog.V(4).Infof("Returning pricing for node %s: %+v from key %s", key, n, key.Features())
  433. if key.GPUType() != "" {
  434. n.Node.GPU = "1" // TODO: support multiple GPUs
  435. }
  436. return n.Node, nil
  437. }
  438. klog.V(1).Infof("[Warning] no pricing data found for %s: %s", key.Features(), key)
  439. c, err := az.GetConfig()
  440. if err != nil {
  441. return nil, fmt.Errorf("No default pricing data available")
  442. }
  443. if key.GPUType() != "" {
  444. return &Node{
  445. VCPUCost: c.CPU,
  446. RAMCost: c.RAM,
  447. GPUCost: c.GPU,
  448. GPU: "1", // TODO: support multiple GPUs
  449. }, nil
  450. }
  451. return &Node{
  452. VCPUCost: c.CPU,
  453. RAMCost: c.RAM,
  454. UsesBaseCPUPrice: true,
  455. }, nil
  456. }
  457. // Stubbed NetworkPricing for Azure. Pull directly from azure.json for now
  458. func (az *Azure) NetworkPricing() (*Network, error) {
  459. cpricing, err := az.Config.GetCustomPricingData()
  460. if err != nil {
  461. return nil, err
  462. }
  463. znec, err := strconv.ParseFloat(cpricing.ZoneNetworkEgress, 64)
  464. if err != nil {
  465. return nil, err
  466. }
  467. rnec, err := strconv.ParseFloat(cpricing.RegionNetworkEgress, 64)
  468. if err != nil {
  469. return nil, err
  470. }
  471. inec, err := strconv.ParseFloat(cpricing.InternetNetworkEgress, 64)
  472. if err != nil {
  473. return nil, err
  474. }
  475. return &Network{
  476. ZoneNetworkEgressCost: znec,
  477. RegionNetworkEgressCost: rnec,
  478. InternetNetworkEgressCost: inec,
  479. }, nil
  480. }
  481. type azurePvKey struct {
  482. Labels map[string]string
  483. StorageClass string
  484. StorageClassParameters map[string]string
  485. DefaultRegion string
  486. }
  487. func (az *Azure) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) PVKey {
  488. return &azurePvKey{
  489. Labels: pv.Labels,
  490. StorageClass: pv.Spec.StorageClassName,
  491. StorageClassParameters: parameters,
  492. DefaultRegion: defaultRegion,
  493. }
  494. }
  495. func (key *azurePvKey) GetStorageClass() string {
  496. return key.StorageClass
  497. }
  498. func (key *azurePvKey) Features() string {
  499. storageClass := key.StorageClassParameters["storageaccounttype"]
  500. if strings.EqualFold(storageClass, "Premium_LRS") {
  501. storageClass = AzurePremiumStorageClass
  502. } else if strings.EqualFold(storageClass, "Standard_LRS") {
  503. storageClass = AzureStandardStorageClass
  504. }
  505. if region, ok := key.Labels[v1.LabelZoneRegion]; ok {
  506. return region + "," + storageClass
  507. }
  508. return key.DefaultRegion + "," + storageClass
  509. }
  510. func (*Azure) GetDisks() ([]byte, error) {
  511. return nil, nil
  512. }
  513. func (az *Azure) ClusterInfo() (map[string]string, error) {
  514. remote := os.Getenv(remoteEnabled)
  515. remoteEnabled := false
  516. if os.Getenv(remote) == "true" {
  517. remoteEnabled = true
  518. }
  519. m := make(map[string]string)
  520. m["name"] = "Azure Cluster #1"
  521. c, err := az.GetConfig()
  522. if err != nil {
  523. return nil, err
  524. }
  525. if c.ClusterName != "" {
  526. m["name"] = c.ClusterName
  527. }
  528. m["provider"] = "azure"
  529. m["remoteReadEnabled"] = strconv.FormatBool(remoteEnabled)
  530. m["id"] = os.Getenv(clusterIDKey)
  531. return m, nil
  532. }
  533. func (az *Azure) AddServiceKey(url url.Values) error {
  534. return nil
  535. }
  536. func (az *Azure) UpdateConfigFromConfigMap(a map[string]string) (*CustomPricing, error) {
  537. return az.Config.UpdateFromMap(a)
  538. }
  539. func (az *Azure) UpdateConfig(r io.Reader, updateType string) (*CustomPricing, error) {
  540. defer az.DownloadPricingData()
  541. return az.Config.Update(func(c *CustomPricing) error {
  542. a := make(map[string]interface{})
  543. err := json.NewDecoder(r).Decode(&a)
  544. if err != nil {
  545. return err
  546. }
  547. for k, v := range a {
  548. kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
  549. vstr, ok := v.(string)
  550. if ok {
  551. err := SetCustomPricingField(c, kUpper, vstr)
  552. if err != nil {
  553. return err
  554. }
  555. } else {
  556. sci := v.(map[string]interface{})
  557. sc := make(map[string]string)
  558. for k, val := range sci {
  559. sc[k] = val.(string)
  560. }
  561. c.SharedCosts = sc //todo: support reflection/multiple map fields
  562. }
  563. }
  564. remoteEnabled := os.Getenv(remoteEnabled)
  565. if remoteEnabled == "true" {
  566. err := UpdateClusterMeta(os.Getenv(clusterIDKey), c.ClusterName)
  567. if err != nil {
  568. return err
  569. }
  570. }
  571. return nil
  572. })
  573. }
  574. func (az *Azure) GetConfig() (*CustomPricing, error) {
  575. c, err := az.Config.GetCustomPricingData()
  576. if c.Discount == "" {
  577. c.Discount = "0%"
  578. }
  579. if c.NegotiatedDiscount == "" {
  580. c.NegotiatedDiscount = "0%"
  581. }
  582. if c.CurrencyCode == "" {
  583. c.CurrencyCode = "USD"
  584. }
  585. if c.AzureBillingRegion == "" {
  586. c.AzureBillingRegion = "US"
  587. }
  588. if err != nil {
  589. return nil, err
  590. }
  591. return c, nil
  592. }
  593. func (az *Azure) ExternalAllocations(string, string, []string, string, string, bool) ([]*OutOfClusterAllocation, error) {
  594. return nil, nil
  595. }
  596. func (az *Azure) ApplyReservedInstancePricing(nodes map[string]*Node) {
  597. }
  598. func (az *Azure) PVPricing(pvk PVKey) (*PV, error) {
  599. az.DownloadPricingDataLock.RLock()
  600. defer az.DownloadPricingDataLock.RUnlock()
  601. pricing, ok := az.Pricing[pvk.Features()]
  602. if !ok {
  603. klog.V(4).Infof("Persistent Volume pricing not found for %s: %s", pvk.GetStorageClass(), pvk.Features())
  604. return &PV{}, nil
  605. }
  606. return pricing.PV, nil
  607. }
  608. func (az *Azure) GetLocalStorageQuery(window, offset string, rate bool, used bool) string {
  609. return ""
  610. }