-
Notifications
You must be signed in to change notification settings - Fork 15
/
kubeconfig.go
49 lines (40 loc) · 1.21 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
package cke
import (
"k8s.io/client-go/tools/clientcmd/api"
)
// Kubeconfig creates *api.Config that will be rendered as "kubeconfig" file.
func Kubeconfig(cluster, user, ca, clientCrt, clientKey string) *api.Config {
cfg := api.NewConfig()
c := api.NewCluster()
c.Server = "https://localhost:16443"
c.CertificateAuthorityData = []byte(ca)
cfg.Clusters[cluster] = c
auth := api.NewAuthInfo()
auth.ClientCertificateData = []byte(clientCrt)
auth.ClientKeyData = []byte(clientKey)
cfg.AuthInfos[user] = auth
ctx := api.NewContext()
ctx.AuthInfo = user
ctx.Cluster = cluster
cfg.Contexts["default"] = ctx
cfg.CurrentContext = "default"
return cfg
}
// UserKubeconfig makes kubeconfig for users
func UserKubeconfig(cluster, userName, ca, clientCrt, clientKey, server string) *api.Config {
cfg := api.NewConfig()
c := api.NewCluster()
c.Server = server
c.CertificateAuthorityData = []byte(ca)
cfg.Clusters[cluster] = c
auth := api.NewAuthInfo()
auth.ClientCertificateData = []byte(clientCrt)
auth.ClientKeyData = []byte(clientKey)
cfg.AuthInfos[userName] = auth
ctx := api.NewContext()
ctx.AuthInfo = userName
ctx.Cluster = cluster
cfg.Contexts["default"] = ctx
cfg.CurrentContext = "default"
return cfg
}