core.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. ConfigPathEnvVar = "CONFIG_PATH"
  11. PProfEnabledEnvVar = "PPROF_ENABLED"
  12. InstallNamespaceEnvVar = "INSTALL_NAMESPACE"
  13. )
  14. // GetAPIPort returns the environment variable value for APIPortEnvVar which
  15. // is the port number the API is available on.
  16. func GetAPIPortWithDefault(def int) int {
  17. return GetInt(APIPortEnvVar, def)
  18. }
  19. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  20. // configurable identifier used for multi-cluster metric emission.
  21. func GetClusterID() string {
  22. return Get(ClusterIDEnvVar, "")
  23. }
  24. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  25. // model configuration path
  26. func GetConfigPath() string {
  27. return Get(ConfigPathEnvVar, DefaultConfigPath)
  28. }
  29. func GetPathFromConfig(subPaths ...string) string {
  30. subPath := path.Join(subPaths...)
  31. return path.Join(GetConfigPath(), subPath)
  32. }
  33. func GetDefaultStorageConfigFilePath() string {
  34. return path.Join(GetConfigPath(), DefaultStorageFile)
  35. }
  36. func IsPProfEnabled() bool {
  37. return GetBool(PProfEnabledEnvVar, false)
  38. }
  39. func GetInstallNamespace(def string) string {
  40. return Get(InstallNamespaceEnvVar, def)
  41. }