forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configmap.go
46 lines (36 loc) · 1.15 KB
/
configmap.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
package kube
import (
"fmt"
"strings"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
const (
Exposecontroller = "exposecontroller"
)
func GetConfigmapData(client *kubernetes.Clientset, name, ns string) (map[string]string, error) {
cm, err := client.CoreV1().ConfigMaps(ns).Get(name, meta_v1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get configmap %s in namespace %s, %v", name, ns, err)
}
return cm.Data, nil
}
func GetCurrentDomain(client *kubernetes.Clientset, ns string) (string, error) {
data, err := GetConfigmapData(client, Exposecontroller, ns)
if err != nil {
return "", err
}
return extractDomainValue(data)
}
func extractDomainValue(data map[string]string) (string, error) {
//TODO change exposecontroller so it supports key/pair configmap as well as yaml file (for backwards compatibility)
yaml := data["config.yml"]
values := strings.Split(yaml, "\n")
for _, line := range values {
pair := strings.Split(line, ":")
if pair[0] == "domain" {
return strings.TrimSpace(pair[1]), nil
}
}
return "", fmt.Errorf("failed to find a domain in %s configmap", Exposecontroller)
}