2017-10-31 13:55:35 +00:00
|
|
|
package pki
|
|
|
|
|
2017-11-01 21:46:43 +00:00
|
|
|
import "encoding/base64"
|
|
|
|
|
2018-03-14 00:18:07 +00:00
|
|
|
func getKubeConfigX509(kubernetesURL string, clusterName string, componentName string, caPath string, crtPath string, keyPath string) string {
|
2017-10-31 13:55:35 +00:00
|
|
|
return `apiVersion: v1
|
|
|
|
kind: Config
|
|
|
|
clusters:
|
|
|
|
- cluster:
|
|
|
|
api-version: v1
|
|
|
|
certificate-authority: ` + caPath + `
|
|
|
|
server: "` + kubernetesURL + `"
|
2018-03-14 00:18:07 +00:00
|
|
|
name: "` + clusterName + `"
|
2017-10-31 13:55:35 +00:00
|
|
|
contexts:
|
|
|
|
- context:
|
2018-03-14 00:18:07 +00:00
|
|
|
cluster: "` + clusterName + `"
|
2018-08-08 17:17:11 +00:00
|
|
|
user: "` + componentName + `-` + clusterName + `"
|
|
|
|
name: "` + clusterName + `"
|
|
|
|
current-context: "` + clusterName + `"
|
2017-10-31 13:55:35 +00:00
|
|
|
users:
|
2018-08-08 17:17:11 +00:00
|
|
|
- name: "` + componentName + `-` + clusterName + `"
|
2017-10-31 13:55:35 +00:00
|
|
|
user:
|
|
|
|
client-certificate: ` + crtPath + `
|
|
|
|
client-key: ` + keyPath + ``
|
|
|
|
}
|
2017-11-01 21:46:43 +00:00
|
|
|
|
2018-03-14 00:18:07 +00:00
|
|
|
func GetKubeConfigX509WithData(kubernetesURL string, clusterName string, componentName string, cacrt string, crt string, key string) string {
|
2017-11-01 21:46:43 +00:00
|
|
|
return `apiVersion: v1
|
|
|
|
kind: Config
|
|
|
|
clusters:
|
|
|
|
- cluster:
|
|
|
|
api-version: v1
|
|
|
|
certificate-authority-data: ` + base64.StdEncoding.EncodeToString([]byte(cacrt)) + `
|
|
|
|
server: "` + kubernetesURL + `"
|
2018-03-14 00:18:07 +00:00
|
|
|
name: "` + clusterName + `"
|
2017-11-01 21:46:43 +00:00
|
|
|
contexts:
|
|
|
|
- context:
|
2018-03-14 00:18:07 +00:00
|
|
|
cluster: "` + clusterName + `"
|
2018-08-08 17:17:11 +00:00
|
|
|
user: "` + componentName + `-` + clusterName + `"
|
|
|
|
name: "` + clusterName + `"
|
|
|
|
current-context: "` + clusterName + `"
|
2017-11-01 21:46:43 +00:00
|
|
|
users:
|
2018-08-08 17:17:11 +00:00
|
|
|
- name: "` + componentName + `-` + clusterName + `"
|
2017-11-01 21:46:43 +00:00
|
|
|
user:
|
|
|
|
client-certificate-data: ` + base64.StdEncoding.EncodeToString([]byte(crt)) + `
|
|
|
|
client-key-data: ` + base64.StdEncoding.EncodeToString([]byte(key)) + ``
|
|
|
|
}
|