env.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2020 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package utils
  14. import (
  15. "fmt"
  16. "os"
  17. "strconv"
  18. )
  19. // TestEnvName gets the name of the test environment. In the CI it is "aws_1.18.x" or similar.
  20. func TestEnvName() string {
  21. return GetEnvVarWithDefault("TEST_ENV_NAME", "localhost")
  22. }
  23. // TestRetryNumber get the max retry. Example, for OpenShift it's 40.
  24. func TestRetryNumber() int {
  25. count := GetEnvVarWithDefault("RETRY_MAX", "45")
  26. number, err := strconv.Atoi(count)
  27. if err != nil {
  28. panic(fmt.Errorf("Error when converting to numeric value %v", err))
  29. }
  30. return number
  31. }
  32. // IsPlatformOpenShift check if the platform is openshift or not
  33. func IsPlatformOpenShift() bool {
  34. return TestEnvName() == "openshift"
  35. }
  36. // GetEnvVarWithDefault get environment variable by key.
  37. func GetEnvVarWithDefault(env, defaultValue string) string {
  38. val := os.Getenv(env)
  39. if val == "" {
  40. return defaultValue
  41. }
  42. return val
  43. }