costmodelenv.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. package env
  2. import (
  3. "regexp"
  4. "strconv"
  5. "time"
  6. "github.com/opencost/opencost/pkg/log"
  7. "github.com/opencost/opencost/pkg/util/timeutil"
  8. )
  9. const (
  10. AppVersionEnvVar = "APP_VERSION"
  11. AWSAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"
  12. AWSAccessKeySecretEnvVar = "AWS_SECRET_ACCESS_KEY"
  13. AWSClusterIDEnvVar = "AWS_CLUSTER_ID"
  14. AWSPricingURL = "AWS_PRICING_URL"
  15. AlibabaAccessKeyIDEnvVar = "ALIBABA_ACCESS_KEY_ID"
  16. AlibabaAccessKeySecretEnvVar = "ALIBABA_SECRET_ACCESS_KEY"
  17. KubecostNamespaceEnvVar = "KUBECOST_NAMESPACE"
  18. PodNameEnvVar = "POD_NAME"
  19. ClusterIDEnvVar = "CLUSTER_ID"
  20. ClusterProfileEnvVar = "CLUSTER_PROFILE"
  21. PrometheusServerEndpointEnvVar = "PROMETHEUS_SERVER_ENDPOINT"
  22. MaxQueryConcurrencyEnvVar = "MAX_QUERY_CONCURRENCY"
  23. QueryLoggingFileEnvVar = "QUERY_LOGGING_FILE"
  24. RemoteEnabledEnvVar = "REMOTE_WRITE_ENABLED"
  25. RemotePWEnvVar = "REMOTE_WRITE_PASSWORD"
  26. SQLAddressEnvVar = "SQL_ADDRESS"
  27. UseCSVProviderEnvVar = "USE_CSV_PROVIDER"
  28. CSVRegionEnvVar = "CSV_REGION"
  29. CSVEndpointEnvVar = "CSV_ENDPOINT"
  30. CSVPathEnvVar = "CSV_PATH"
  31. ConfigPathEnvVar = "CONFIG_PATH"
  32. CloudProviderAPIKeyEnvVar = "CLOUD_PROVIDER_API_KEY"
  33. DisableAggregateCostModelCache = "DISABLE_AGGREGATE_COST_MODEL_CACHE"
  34. EmitPodAnnotationsMetricEnvVar = "EMIT_POD_ANNOTATIONS_METRIC"
  35. EmitNamespaceAnnotationsMetricEnvVar = "EMIT_NAMESPACE_ANNOTATIONS_METRIC"
  36. EmitKsmV1MetricsEnvVar = "EMIT_KSM_V1_METRICS"
  37. EmitKsmV1MetricsOnly = "EMIT_KSM_V1_METRICS_ONLY"
  38. ThanosEnabledEnvVar = "THANOS_ENABLED"
  39. ThanosQueryUrlEnvVar = "THANOS_QUERY_URL"
  40. ThanosOffsetEnvVar = "THANOS_QUERY_OFFSET"
  41. ThanosMaxSourceResEnvVar = "THANOS_MAX_SOURCE_RESOLUTION"
  42. LogCollectionEnabledEnvVar = "LOG_COLLECTION_ENABLED"
  43. ProductAnalyticsEnabledEnvVar = "PRODUCT_ANALYTICS_ENABLED"
  44. ErrorReportingEnabledEnvVar = "ERROR_REPORTING_ENABLED"
  45. ValuesReportingEnabledEnvVar = "VALUES_REPORTING_ENABLED"
  46. DBBasicAuthUsername = "DB_BASIC_AUTH_USERNAME"
  47. DBBasicAuthPassword = "DB_BASIC_AUTH_PW"
  48. DBBearerToken = "DB_BEARER_TOKEN"
  49. MultiClusterBasicAuthUsername = "MC_BASIC_AUTH_USERNAME"
  50. MultiClusterBasicAuthPassword = "MC_BASIC_AUTH_PW"
  51. MultiClusterBearerToken = "MC_BEARER_TOKEN"
  52. InsecureSkipVerify = "INSECURE_SKIP_VERIFY"
  53. KubeConfigPathEnvVar = "KUBECONFIG_PATH"
  54. UTCOffsetEnvVar = "UTC_OFFSET"
  55. CacheWarmingEnabledEnvVar = "CACHE_WARMING_ENABLED"
  56. ETLEnabledEnvVar = "ETL_ENABLED"
  57. ETLMaxPrometheusQueryDurationMinutes = "ETL_MAX_PROMETHEUS_QUERY_DURATION_MINUTES"
  58. ETLResolutionSeconds = "ETL_RESOLUTION_SECONDS"
  59. LegacyExternalAPIDisabledVar = "LEGACY_EXTERNAL_API_DISABLED"
  60. PromClusterIDLabelEnvVar = "PROM_CLUSTER_ID_LABEL"
  61. PricingConfigmapName = "PRICING_CONFIGMAP_NAME"
  62. MetricsConfigmapName = "METRICS_CONFIGMAP_NAME"
  63. KubecostJobNameEnvVar = "KUBECOST_JOB_NAME"
  64. KubecostConfigBucketEnvVar = "KUBECOST_CONFIG_BUCKET"
  65. ClusterInfoFileEnabledEnvVar = "CLUSTER_INFO_FILE_ENABLED"
  66. ClusterCacheFileEnabledEnvVar = "CLUSTER_CACHE_FILE_ENABLED"
  67. PrometheusQueryOffsetEnvVar = "PROMETHEUS_QUERY_OFFSET"
  68. PrometheusRetryOnRateLimitResponseEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT"
  69. PrometheusRetryOnRateLimitMaxRetriesEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_MAX_RETRIES"
  70. PrometheusRetryOnRateLimitDefaultWaitEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_DEFAULT_WAIT"
  71. IngestPodUIDEnvVar = "INGEST_POD_UID"
  72. ETLReadOnlyMode = "ETL_READ_ONLY"
  73. AllocationNodeLabelsEnabled = "ALLOCATION_NODE_LABELS_ENABLED"
  74. AllocationNodeLabelsIncludeList = "ALLOCATION_NODE_LABELS_INCLUDE_LIST"
  75. regionOverrideList = "REGION_OVERRIDE_LIST"
  76. )
  77. var offsetRegex = regexp.MustCompile(`^(\+|-)(\d\d):(\d\d)$`)
  78. func IsETLReadOnlyMode() bool {
  79. return GetBool(ETLReadOnlyMode, false)
  80. }
  81. // GetKubecostConfigBucket returns a file location for a mounted bucket configuration which is used to store
  82. // a subset of kubecost configurations that require sharing via remote storage.
  83. func GetKubecostConfigBucket() string {
  84. return Get(KubecostConfigBucketEnvVar, "")
  85. }
  86. // IsClusterInfoFileEnabled returns true if the cluster info is read from a file or pulled from the local
  87. // cloud provider and kubernetes.
  88. func IsClusterInfoFileEnabled() bool {
  89. return GetBool(ClusterInfoFileEnabledEnvVar, false)
  90. }
  91. // IsClusterCacheFileEnabled returns true if the kubernetes cluster data is read from a file or pulled from the local
  92. // kubernetes API.
  93. func IsClusterCacheFileEnabled() bool {
  94. return GetBool(ClusterCacheFileEnabledEnvVar, false)
  95. }
  96. // IsPrometheusRetryOnRateLimitResponse will attempt to retry if a 429 response is received OR a 400 with a body containing
  97. // ThrottleException (common in AWS services like AMP)
  98. func IsPrometheusRetryOnRateLimitResponse() bool {
  99. return GetBool(PrometheusRetryOnRateLimitResponseEnvVar, true)
  100. }
  101. // GetPrometheusRetryOnRateLimitMaxRetries returns the maximum number of retries that should be attempted prior to failing.
  102. // Only used if IsPrometheusRetryOnRateLimitResponse() is true.
  103. func GetPrometheusRetryOnRateLimitMaxRetries() int {
  104. return GetInt(PrometheusRetryOnRateLimitMaxRetriesEnvVar, 5)
  105. }
  106. // GetPrometheusRetryOnRateLimitDefaultWait returns the default wait time for a retriable rate limit response without a
  107. // Retry-After header.
  108. func GetPrometheusRetryOnRateLimitDefaultWait() time.Duration {
  109. return GetDuration(PrometheusRetryOnRateLimitDefaultWaitEnvVar, 100*time.Millisecond)
  110. }
  111. // GetPrometheusQueryOffset returns the time.Duration to offset all prometheus queries by. NOTE: This env var is applied
  112. // to all non-range queries made via our query context. This should only be applied when there is a significant delay in
  113. // data arriving in the target prom db. For example, if supplying a thanos or cortex querier for the prometheus server, using
  114. // a 3h offset will ensure that current time = current time - 3h.
  115. //
  116. // This offset is NOT the same as the GetThanosOffset() option, as that is only applied to queries made specifically targetting
  117. // thanos. This offset is applied globally.
  118. func GetPrometheusQueryOffset() time.Duration {
  119. offset := Get(PrometheusQueryOffsetEnvVar, "")
  120. if offset == "" {
  121. return 0
  122. }
  123. dur, err := timeutil.ParseDuration(offset)
  124. if err != nil {
  125. return 0
  126. }
  127. return dur
  128. }
  129. func GetPricingConfigmapName() string {
  130. return Get(PricingConfigmapName, "pricing-configs")
  131. }
  132. func GetMetricsConfigmapName() string {
  133. return Get(MetricsConfigmapName, "metrics-config")
  134. }
  135. // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
  136. // the AWS access key for authentication
  137. func GetAppVersion() string {
  138. return Get(AppVersionEnvVar, "1.91.0-rc.0")
  139. }
  140. // IsEmitNamespaceAnnotationsMetric returns true if cost-model is configured to emit the kube_namespace_annotations metric
  141. // containing the namespace annotations
  142. func IsEmitNamespaceAnnotationsMetric() bool {
  143. return GetBool(EmitNamespaceAnnotationsMetricEnvVar, false)
  144. }
  145. // IsEmitPodAnnotationsMetric returns true if cost-model is configured to emit the kube_pod_annotations metric containing
  146. // pod annotations.
  147. func IsEmitPodAnnotationsMetric() bool {
  148. return GetBool(EmitPodAnnotationsMetricEnvVar, false)
  149. }
  150. // IsEmitKsmV1Metrics returns true if cost-model is configured to emit all necessary KSM v1
  151. // metrics that were removed in KSM v2
  152. func IsEmitKsmV1Metrics() bool {
  153. return GetBool(EmitKsmV1MetricsEnvVar, true)
  154. }
  155. func IsEmitKsmV1MetricsOnly() bool {
  156. return GetBool(EmitKsmV1MetricsOnly, false)
  157. }
  158. // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
  159. // the AWS access key for authentication
  160. func GetAWSAccessKeyID() string {
  161. return Get(AWSAccessKeyIDEnvVar, "")
  162. }
  163. // GetAWSAccessKeySecret returns the environment variable value for AWSAccessKeySecretEnvVar which represents
  164. // the AWS access key secret for authentication
  165. func GetAWSAccessKeySecret() string {
  166. return Get(AWSAccessKeySecretEnvVar, "")
  167. }
  168. // GetAWSClusterID returns the environment variable value for AWSClusterIDEnvVar which represents
  169. // an AWS specific cluster identifier.
  170. func GetAWSClusterID() string {
  171. return Get(AWSClusterIDEnvVar, "")
  172. }
  173. // GetAWSPricingURL returns an optional alternative URL to fetch AWS pricing data from; for use in airgapped environments
  174. func GetAWSPricingURL() string {
  175. return Get(AWSPricingURL, "")
  176. }
  177. // GetAlibabaAccessKeyID returns the environment variable value for AlibabaAccessKeyIDEnvVar which represents
  178. // the Alibaba access key for authentication
  179. func GetAlibabaAccessKeyID() string {
  180. return Get(AlibabaAccessKeyIDEnvVar, "")
  181. }
  182. // GetAlibabaAccessKeySecret returns the environment variable value for AlibabaAccessKeySecretEnvVar which represents
  183. // the Alibaba access key secret for authentication
  184. func GetAlibabaAccessKeySecret() string {
  185. return Get(AlibabaAccessKeySecretEnvVar, "")
  186. }
  187. // GetKubecostNamespace returns the environment variable value for KubecostNamespaceEnvVar which
  188. // represents the namespace the cost model exists in.
  189. func GetKubecostNamespace() string {
  190. return Get(KubecostNamespaceEnvVar, "kubecost")
  191. }
  192. // GetPodName returns the name of the current running pod. If this environment variable is not set,
  193. // empty string is returned.
  194. func GetPodName() string {
  195. return Get(PodNameEnvVar, "")
  196. }
  197. // GetClusterProfile returns the environment variable value for ClusterProfileEnvVar which
  198. // represents the cluster profile configured for
  199. func GetClusterProfile() string {
  200. return Get(ClusterProfileEnvVar, "development")
  201. }
  202. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  203. // configurable identifier used for multi-cluster metric emission.
  204. func GetClusterID() string {
  205. return Get(ClusterIDEnvVar, "")
  206. }
  207. // GetPrometheusServerEndpoint returns the environment variable value for PrometheusServerEndpointEnvVar which
  208. // represents the prometheus server endpoint used to execute prometheus queries.
  209. func GetPrometheusServerEndpoint() string {
  210. return Get(PrometheusServerEndpointEnvVar, "")
  211. }
  212. func GetInsecureSkipVerify() bool {
  213. return GetBool(InsecureSkipVerify, false)
  214. }
  215. // IsAggregateCostModelCacheDisabled returns the environment variable value for DisableAggregateCostModelCache which
  216. // will inform the aggregator on whether to load cached data. Defaults to false
  217. func IsAggregateCostModelCacheDisabled() bool {
  218. return GetBool(DisableAggregateCostModelCache, false)
  219. }
  220. // IsRemoteEnabled returns the environment variable value for RemoteEnabledEnvVar which represents whether
  221. // or not remote write is enabled for prometheus for use with SQL backed persistent storage.
  222. func IsRemoteEnabled() bool {
  223. return GetBool(RemoteEnabledEnvVar, false)
  224. }
  225. // GetRemotePW returns the environment variable value for RemotePWEnvVar which represents the remote
  226. // persistent storage password.
  227. func GetRemotePW() string {
  228. return Get(RemotePWEnvVar, "")
  229. }
  230. // GetSQLAddress returns the environment variable value for SQLAddressEnvVar which represents the SQL
  231. // database address used with remote persistent storage.
  232. func GetSQLAddress() string {
  233. return Get(SQLAddressEnvVar, "")
  234. }
  235. // IsUseCSVProvider returns the environment variable value for UseCSVProviderEnvVar which represents
  236. // whether or not the use of a CSV cost provider is enabled.
  237. func IsUseCSVProvider() bool {
  238. return GetBool(UseCSVProviderEnvVar, false)
  239. }
  240. // GetCSVRegion returns the environment variable value for CSVRegionEnvVar which represents the
  241. // region configured for a CSV provider.
  242. func GetCSVRegion() string {
  243. return Get(CSVRegionEnvVar, "")
  244. }
  245. // GetCSVEndpoint returns the environment variable value for CSVEndpointEnvVar which represents the
  246. // endpoint configured for a S3 CSV provider another than AWS S3.
  247. func GetCSVEndpoint() string {
  248. return Get(CSVEndpointEnvVar, "")
  249. }
  250. // GetCSVPath returns the environment variable value for CSVPathEnvVar which represents the key path
  251. // configured for a CSV provider.
  252. func GetCSVPath() string {
  253. return Get(CSVPathEnvVar, "")
  254. }
  255. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  256. // model configuration path
  257. func GetConfigPath() string {
  258. return Get(ConfigPathEnvVar, "")
  259. }
  260. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  261. // model configuration path
  262. func GetConfigPathWithDefault(defaultValue string) string {
  263. return Get(ConfigPathEnvVar, defaultValue)
  264. }
  265. // GetCloudProviderAPI returns the environment variable value for CloudProviderAPIEnvVar which represents
  266. // the API key provided for the cloud provider.
  267. func GetCloudProviderAPIKey() string {
  268. return Get(CloudProviderAPIKeyEnvVar, "")
  269. }
  270. // IsThanosEnabled returns the environment variable value for ThanosEnabledEnvVar which represents whether
  271. // or not thanos is enabled.
  272. func IsThanosEnabled() bool {
  273. return GetBool(ThanosEnabledEnvVar, false)
  274. }
  275. // GetThanosQueryUrl returns the environment variable value for ThanosQueryUrlEnvVar which represents the
  276. // target query endpoint for hitting thanos.
  277. func GetThanosQueryUrl() string {
  278. return Get(ThanosQueryUrlEnvVar, "")
  279. }
  280. // GetThanosOffset returns the environment variable value for ThanosOffsetEnvVar which represents the total
  281. // amount of time to offset all queries made to thanos.
  282. func GetThanosOffset() string {
  283. return Get(ThanosOffsetEnvVar, "3h")
  284. }
  285. // GetThanosMaxSourceResolution returns the environment variable value for ThanosMaxSourceResEnvVar which represents
  286. // the max source resolution to use when querying thanos.
  287. func GetThanosMaxSourceResolution() string {
  288. res := Get(ThanosMaxSourceResEnvVar, "raw")
  289. switch res {
  290. case "raw":
  291. return "0s"
  292. case "0s":
  293. fallthrough
  294. case "5m":
  295. fallthrough
  296. case "1h":
  297. return res
  298. default:
  299. return "0s"
  300. }
  301. }
  302. // IsLogCollectionEnabled returns the environment variable value for LogCollectionEnabledEnvVar which represents
  303. // whether or not log collection has been enabled for kubecost deployments.
  304. func IsLogCollectionEnabled() bool {
  305. return GetBool(LogCollectionEnabledEnvVar, true)
  306. }
  307. // IsProductAnalyticsEnabled returns the environment variable value for ProductAnalyticsEnabledEnvVar
  308. func IsProductAnalyticsEnabled() bool {
  309. return GetBool(ProductAnalyticsEnabledEnvVar, true)
  310. }
  311. // IsErrorReportingEnabled returns the environment variable value for ErrorReportingEnabledEnvVar
  312. func IsErrorReportingEnabled() bool {
  313. return GetBool(ErrorReportingEnabledEnvVar, true)
  314. }
  315. // IsValuesReportingEnabled returns the environment variable value for ValuesReportingEnabledEnvVar
  316. func IsValuesReportingEnabled() bool {
  317. return GetBool(ValuesReportingEnabledEnvVar, true)
  318. }
  319. // GetMaxQueryConcurrency returns the environment variable value for MaxQueryConcurrencyEnvVar
  320. func GetMaxQueryConcurrency() int {
  321. return GetInt(MaxQueryConcurrencyEnvVar, 5)
  322. }
  323. // GetQueryLoggingFile returns a file location if query logging is enabled. Otherwise, empty string
  324. func GetQueryLoggingFile() string {
  325. return Get(QueryLoggingFileEnvVar, "")
  326. }
  327. func GetDBBasicAuthUsername() string {
  328. return Get(DBBasicAuthUsername, "")
  329. }
  330. func GetDBBasicAuthUserPassword() string {
  331. return Get(DBBasicAuthPassword, "")
  332. }
  333. func GetDBBearerToken() string {
  334. return Get(DBBearerToken, "")
  335. }
  336. // GetMultiClusterBasicAuthUsername returns the environemnt variable value for MultiClusterBasicAuthUsername
  337. func GetMultiClusterBasicAuthUsername() string {
  338. return Get(MultiClusterBasicAuthUsername, "")
  339. }
  340. // GetMultiClusterBasicAuthPassword returns the environemnt variable value for MultiClusterBasicAuthPassword
  341. func GetMultiClusterBasicAuthPassword() string {
  342. return Get(MultiClusterBasicAuthPassword, "")
  343. }
  344. func GetMultiClusterBearerToken() string {
  345. return Get(MultiClusterBearerToken, "")
  346. }
  347. // GetKubeConfigPath returns the environment variable value for KubeConfigPathEnvVar
  348. func GetKubeConfigPath() string {
  349. return Get(KubeConfigPathEnvVar, "")
  350. }
  351. // GetUTCOffset returns the environemnt variable value for UTCOffset
  352. func GetUTCOffset() string {
  353. return Get(UTCOffsetEnvVar, "")
  354. }
  355. // GetParsedUTCOffset returns the duration of the configured UTC offset
  356. func GetParsedUTCOffset() time.Duration {
  357. offset := time.Duration(0)
  358. if offsetStr := GetUTCOffset(); offsetStr != "" {
  359. match := offsetRegex.FindStringSubmatch(offsetStr)
  360. if match == nil {
  361. log.Warnf("Illegal UTC offset: %s", offsetStr)
  362. return offset
  363. }
  364. sig := 1
  365. if match[1] == "-" {
  366. sig = -1
  367. }
  368. hrs64, _ := strconv.ParseInt(match[2], 10, 64)
  369. hrs := sig * int(hrs64)
  370. mins64, _ := strconv.ParseInt(match[3], 10, 64)
  371. mins := sig * int(mins64)
  372. offset = time.Duration(hrs)*time.Hour + time.Duration(mins)
  373. }
  374. return offset
  375. }
  376. // GetKubecostJobName returns the environment variable value for KubecostJobNameEnvVar
  377. func GetKubecostJobName() string {
  378. return Get(KubecostJobNameEnvVar, "kubecost")
  379. }
  380. func IsCacheWarmingEnabled() bool {
  381. return GetBool(CacheWarmingEnabledEnvVar, true)
  382. }
  383. func IsETLEnabled() bool {
  384. return GetBool(ETLEnabledEnvVar, true)
  385. }
  386. func GetETLMaxPrometheusQueryDuration() time.Duration {
  387. dayMins := 60 * 24
  388. mins := time.Duration(GetInt64(ETLMaxPrometheusQueryDurationMinutes, int64(dayMins)))
  389. return mins * time.Minute
  390. }
  391. // GetETLResolution determines the resolution of ETL queries. The smaller the
  392. // duration, the higher the resolution; the higher the resolution, the more
  393. // accurate the query results, but the more computationally expensive.
  394. func GetETLResolution() time.Duration {
  395. // Use the configured ETL resolution, or default to
  396. // 5m (i.e. 300s)
  397. secs := time.Duration(GetInt64(ETLResolutionSeconds, 300))
  398. return secs * time.Second
  399. }
  400. func LegacyExternalCostsAPIDisabled() bool {
  401. return GetBool(LegacyExternalAPIDisabledVar, false)
  402. }
  403. // GetPromClusterLabel returns the environemnt variable value for PromClusterIDLabel
  404. func GetPromClusterLabel() string {
  405. return Get(PromClusterIDLabelEnvVar, "cluster_id")
  406. }
  407. // IsIngestingPodUID returns the env variable from ingestPodUID, which alters the
  408. // contents of podKeys in Allocation
  409. func IsIngestingPodUID() bool {
  410. return GetBool(IngestPodUIDEnvVar, false)
  411. }
  412. func GetAllocationNodeLabelsEnabled() bool {
  413. return GetBool(AllocationNodeLabelsEnabled, true)
  414. }
  415. var defaultAllocationNodeLabelsIncludeList []string = []string{
  416. "cloud.google.com/gke-nodepool",
  417. "eks.amazonaws.com/nodegroup",
  418. "kubernetes.azure.com/agentpool",
  419. "node.kubernetes.io/instance-type",
  420. "topology.kubernetes.io/region",
  421. "topology.kubernetes.io/zone",
  422. }
  423. func GetAllocationNodeLabelsIncludeList() []string {
  424. // If node labels are not enabled, return an empty list.
  425. if !GetAllocationNodeLabelsEnabled() {
  426. return []string{}
  427. }
  428. list := GetList(AllocationNodeLabelsIncludeList, ",")
  429. // If node labels are enabled, but the white list is empty, use defaults.
  430. if len(list) == 0 {
  431. return defaultAllocationNodeLabelsIncludeList
  432. }
  433. return list
  434. }
  435. func GetRegionOverrideList() []string {
  436. regionList := GetList(regionOverrideList, ",")
  437. if regionList == nil {
  438. return []string{}
  439. }
  440. return regionList
  441. }