2
0

costmodelenv.go 19 KB

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