opencost.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package env
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/core/pkg/env"
  5. "github.com/opencost/opencost/core/pkg/log"
  6. "github.com/opencost/opencost/core/pkg/util/timeutil"
  7. )
  8. // Environment variables specific to the running of opencost
  9. const (
  10. DefaultAPIPort = 9003
  11. defaultOpencostNamespace = "opencost"
  12. )
  13. const (
  14. UTCOffsetEnvVar = "UTC_OFFSET"
  15. )
  16. func GetOpencostAPIPort() int {
  17. return env.GetAPIPortWithDefault(DefaultAPIPort)
  18. }
  19. // GetOpencostNamespace returns the environment variable value that is set for the kubernetes namespace
  20. // this service is installed in.
  21. func GetOpencostNamespace() string {
  22. return env.GetInstallNamespace(defaultOpencostNamespace)
  23. }
  24. // GetUTCOffset returns the environment variable value for UTCOffset
  25. func GetUTCOffset() string {
  26. return env.Get(UTCOffsetEnvVar, "")
  27. }
  28. // GetParsedUTCOffset returns the duration of the configured UTC offset
  29. func GetParsedUTCOffset() time.Duration {
  30. offset, err := timeutil.ParseUTCOffset(GetUTCOffset())
  31. if err != nil {
  32. log.Warnf("Failed to parse UTC offset: %s", err)
  33. return time.Duration(0)
  34. }
  35. return offset
  36. }