-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubeconfig.go
65 lines (54 loc) · 1.52 KB
/
kubeconfig.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
package k8s
import (
"fmt"
"net/http"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd/api"
)
func clusters(cfg Config) []string {
ret := cfg.Clusters
for _, sc := range cfg.StaticClusters {
ret = append(ret, sc.Name)
}
return ret
}
type ClusterConfigMap map[string]rest.Config
func CreateClusterConfigMap(tenant string, cfg Config) (ClusterConfigMap, error) {
configs := ClusterConfigMap{}
for _, cluster := range cfg.Clusters {
configs[cluster] = rest.Config{
Host: fmt.Sprintf("https://apiserver.%s.%s.cloud.nais.io", cluster, tenant),
AuthProvider: &api.AuthProviderConfig{
Name: GoogleAuthPlugin,
},
WrapTransport: func(rt http.RoundTripper) http.RoundTripper {
return otelhttp.NewTransport(rt, otelhttp.WithServerName(cluster))
},
}
}
staticConfigs, err := getStaticClusterConfigs(cfg.StaticClusters)
if err != nil {
return nil, err
}
for cluster, cfg := range staticConfigs {
configs[cluster] = cfg
}
return configs, nil
}
func getStaticClusterConfigs(clusters []StaticCluster) (ClusterConfigMap, error) {
configs := ClusterConfigMap{}
for _, cluster := range clusters {
configs[cluster.Name] = rest.Config{
Host: cluster.Host,
BearerToken: cluster.Token,
TLSClientConfig: rest.TLSClientConfig{
Insecure: true,
},
WrapTransport: func(rt http.RoundTripper) http.RoundTripper {
return otelhttp.NewTransport(rt, otelhttp.WithServerName(cluster.Name))
},
}
}
return configs, nil
}