core.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package env
  2. import (
  3. "path"
  4. )
  5. const DefaultConfigPath = "/var/configs"
  6. const DefaultStorageFile = "federated-store.yaml"
  7. const (
  8. APIPortEnvVar = "API_PORT"
  9. ClusterIDEnvVar = "CLUSTER_ID"
  10. AppNameEnvVar = "APP_NAME"
  11. ConfigPathEnvVar = "CONFIG_PATH"
  12. PProfEnabledEnvVar = "PPROF_ENABLED"
  13. InstallNamespaceEnvVar = "INSTALL_NAMESPACE"
  14. )
  15. // GetAPIPort returns the environment variable value for APIPortEnvVar which
  16. // is the port number the API is available on.
  17. func GetAPIPortWithDefault(def int) int {
  18. return GetInt(APIPortEnvVar, def)
  19. }
  20. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  21. // configurable identifier used for multi-cluster metric emission.
  22. func GetClusterID() string {
  23. return Get(ClusterIDEnvVar, "")
  24. }
  25. // GetAppName returns the name of the application name running the values
  26. func GetAppName() string {
  27. return Get(AppNameEnvVar, "Opencost")
  28. }
  29. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  30. // model configuration path
  31. func GetConfigPath() string {
  32. return Get(ConfigPathEnvVar, DefaultConfigPath)
  33. }
  34. func GetPathFromConfig(subPaths ...string) string {
  35. subPath := path.Join(subPaths...)
  36. return path.Join(GetConfigPath(), subPath)
  37. }
  38. func GetDefaultStorageConfigFilePath() string {
  39. return path.Join(GetConfigPath(), DefaultStorageFile)
  40. }
  41. func IsPProfEnabled() bool {
  42. return GetBool(PProfEnabledEnvVar, false)
  43. }
  44. func GetInstallNamespace(def string) string {
  45. return Get(InstallNamespaceEnvVar, def)
  46. }