forked from kubernetes/kops
/
export_kubecfg.go
59 lines (48 loc) · 1.17 KB
/
export_kubecfg.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
package main
import (
"github.com/spf13/cobra"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/kutil"
)
type ExportKubecfgCommand struct {
tmpdir string
keyStore fi.CAStore
}
var exportKubecfgCommand ExportKubecfgCommand
func init() {
cmd := &cobra.Command{
Use: "kubecfg CLUSTERNAME",
Short: "Generate a kubecfg file for a cluster",
Long: `Creates a kubecfg file for a cluster, based on the state`,
Run: func(cmd *cobra.Command, args []string) {
err := exportKubecfgCommand.Run(args)
if err != nil {
exitWithError(err)
}
},
}
exportCmd.AddCommand(cmd)
}
func (c *ExportKubecfgCommand) Run(args []string) error {
err := rootCommand.ProcessArgs(args)
if err != nil {
return err
}
clusterRegistry, cluster, err := rootCommand.Cluster()
if err != nil {
return err
}
clusterName := cluster.Name
master := cluster.Spec.MasterPublicName
if master == "" {
master = "api." + clusterName
}
x := &kutil.CreateKubecfg{
ClusterName: clusterName,
KeyStore: clusterRegistry.KeyStore(clusterName),
SecretStore: clusterRegistry.SecretStore(cluster.Name),
MasterPublicName: master,
}
defer x.Close()
return x.WriteKubecfg()
}