-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubeconfig.go
47 lines (44 loc) · 1.44 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
package pki
import "encoding/base64"
func getKubeConfigX509(kubernetesURL string, clusterName string, componentName string, caPath string, crtPath string, keyPath string) string {
return `apiVersion: v1
kind: Config
clusters:
- cluster:
api-version: v1
certificate-authority: ` + caPath + `
server: "` + kubernetesURL + `"
name: "` + clusterName + `"
contexts:
- context:
cluster: "` + clusterName + `"
user: "` + componentName + `-` + clusterName + `"
name: "` + clusterName + `"
current-context: "` + clusterName + `"
users:
- name: "` + componentName + `-` + clusterName + `"
user:
client-certificate: ` + crtPath + `
client-key: ` + keyPath + ``
}
func GetKubeConfigX509WithData(kubernetesURL string, clusterName string, componentName string, cacrt string, crt string, key string) string {
return `apiVersion: v1
kind: Config
clusters:
- cluster:
api-version: v1
certificate-authority-data: ` + base64.StdEncoding.EncodeToString([]byte(cacrt)) + `
server: "` + kubernetesURL + `"
name: "` + clusterName + `"
contexts:
- context:
cluster: "` + clusterName + `"
user: "` + componentName + `-` + clusterName + `"
name: "` + clusterName + `"
current-context: "` + clusterName + `"
users:
- name: "` + componentName + `-` + clusterName + `"
user:
client-certificate-data: ` + base64.StdEncoding.EncodeToString([]byte(crt)) + `
client-key-data: ` + base64.StdEncoding.EncodeToString([]byte(key)) + ``
}