-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.go
57 lines (51 loc) · 1.48 KB
/
misc.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
package config
import (
"os"
"strconv"
"strings"
)
// GetWorkspaceToken returns the workspace token provided in the environment variables
// Env variable CONFIG_BACKEND_TOKEN is deprecating soon
// WORKSPACE_TOKEN is newly introduced. This will override CONFIG_BACKEND_TOKEN
func GetWorkspaceToken() string {
token := GetString("WORKSPACE_TOKEN", "")
if token != "" && token != "<your_token_here>" {
return token
}
return GetString("CONFIG_BACKEND_TOKEN", "")
}
// GetNamespaceIdentifier
func GetNamespaceIdentifier() string {
k8sNamespace := GetKubeNamespace()
if k8sNamespace != "" {
return k8sNamespace
}
return "none"
}
// GetKubeNamespace returns value stored in KUBE_NAMESPACE env var
func GetKubeNamespace() string {
return os.Getenv("KUBE_NAMESPACE")
}
func GetInstanceID() string {
instance := GetString("INSTANCE_ID", "")
instanceArr := strings.Split(instance, "-")
len := len(instanceArr)
// This handles 2 kinds of server instances
// a. Processor OR Gateway running in non HA mod where the instance name ends with the index
// b. Gateway running in HA mode, where the instance name is of the form *-gw-ha-<index>-<statefulset-id>-<pod-id>
potentialServerIndexIndicees := []int{len - 1, len - 3}
for _, i := range potentialServerIndexIndicees {
if i < 0 {
continue
}
serverIndex := instanceArr[i]
_, err := strconv.Atoi(serverIndex)
if err == nil {
return serverIndex
}
}
return ""
}
func GetReleaseName() string {
return os.Getenv("RELEASE_NAME")
}