-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
66 lines (60 loc) · 2.53 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package models
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/equinor/radix-operator/pkg/apis/defaults"
"github.com/equinor/radix-operator/pkg/apis/utils"
)
// Env instance variables
type Env struct {
UseSwagger bool
RadixComponentName string
RadixDeploymentName string
RadixDeploymentNamespace string
RadixJobSchedulersPerEnvironmentHistoryLimit int
RadixPort string
LogLevel string
}
// NewEnv Constructor
func NewEnv() *Env {
var (
useSwagger, _ = strconv.ParseBool(os.Getenv("USE_SWAGGER"))
radixAppName = strings.TrimSpace(os.Getenv(defaults.RadixAppEnvironmentVariable))
radixEnv = strings.TrimSpace(os.Getenv(defaults.EnvironmentnameEnvironmentVariable))
radixComponentName = strings.TrimSpace(os.Getenv(defaults.RadixComponentEnvironmentVariable))
radixDeployment = strings.TrimSpace(os.Getenv(defaults.RadixDeploymentEnvironmentVariable))
radixJobSchedulersPerEnvironmentHistoryLimit = strings.TrimSpace(os.Getenv("RADIX_JOB_SCHEDULERS_PER_ENVIRONMENT_HISTORY_LIMIT"))
radixPorts = strings.TrimSpace(os.Getenv(defaults.RadixPortsEnvironmentVariable))
logLevel = os.Getenv("LOG_LEVEL")
)
env := Env{
RadixComponentName: radixComponentName,
RadixDeploymentName: radixDeployment,
RadixDeploymentNamespace: utils.GetEnvironmentNamespace(radixAppName, radixEnv),
UseSwagger: useSwagger,
RadixJobSchedulersPerEnvironmentHistoryLimit: 10,
LogLevel: logLevel,
}
setPort(radixPorts, &env)
setHistoryLimit(radixJobSchedulersPerEnvironmentHistoryLimit, &env)
return &env
}
func setHistoryLimit(radixJobSchedulersPerEnvironmentHistoryLimit string, env *Env) {
if len(radixJobSchedulersPerEnvironmentHistoryLimit) > 0 {
if historyLimit, err := strconv.Atoi(radixJobSchedulersPerEnvironmentHistoryLimit); err == nil && historyLimit > 0 {
env.RadixJobSchedulersPerEnvironmentHistoryLimit = historyLimit
}
}
}
func setPort(radixPorts string, env *Env) {
radixPorts = strings.ReplaceAll(radixPorts, "(", "")
radixPorts = strings.ReplaceAll(radixPorts, ")", "")
ports := strings.Split(radixPorts, ",")
if len(ports) > 0 {
env.RadixPort = ports[0]
return
}
panic(fmt.Errorf("RADIX_PORTS not set"))
}