This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 468
/
command_up.go
91 lines (77 loc) · 2.44 KB
/
command_up.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"io/ioutil"
"github.com/coreos/coreos-kubernetes/multi-node/aws/pkg/cluster"
"github.com/coreos/coreos-kubernetes/multi-node/aws/pkg/config"
"github.com/spf13/cobra"
)
var (
cmdUp = &cobra.Command{
Use: "up",
Short: "Create a new Kubernetes cluster",
Long: ``,
RunE: runCmdUp,
SilenceUsage: true,
}
upOpts = struct {
awsDebug, export, update bool
}{}
)
func init() {
cmdRoot.AddCommand(cmdUp)
cmdUp.Flags().BoolVar(&upOpts.export, "export", false, "Don't create cluster, instead export cloudformation stack file")
// cmdUp.Flags().BoolVar(&upOpts.update, "update", false, "update existing cluster with new cloudformation stack")
cmdUp.Flags().BoolVar(&upOpts.awsDebug, "aws-debug", false, "Log debug information from aws-sdk-go library")
}
func runCmdUp(cmd *cobra.Command, args []string) error {
conf, err := config.ClusterFromFile(configPath)
if err != nil {
return fmt.Errorf("Failed to read cluster config: %v", err)
}
if err := conf.ValidateUserData(stackTemplateOptions); err != nil {
return err
}
data, err := conf.RenderStackTemplate(stackTemplateOptions)
if err != nil {
return fmt.Errorf("Failed to render stack template: %v", err)
}
if upOpts.export {
templatePath := fmt.Sprintf("%s.stack-template.json", conf.ClusterName)
fmt.Printf("Exporting %s\n", templatePath)
if err := ioutil.WriteFile(templatePath, data, 0600); err != nil {
return fmt.Errorf("Error writing %s : %v", templatePath, err)
}
if conf.KMSKeyARN == "" {
fmt.Printf("BEWARE: %s contains your TLS secrets!\n", templatePath)
}
return nil
}
cluster := cluster.New(conf, upOpts.awsDebug)
if upOpts.update {
report, err := cluster.Update(string(data))
if err != nil {
return fmt.Errorf("Error updating cluster: %v", err)
}
if report != "" {
fmt.Printf("Update stack: %s\n", report)
}
} else {
fmt.Printf("Creating AWS resources. This should take around 5 minutes.\n")
if err := cluster.Create(string(data)); err != nil {
return fmt.Errorf("Error creating cluster: %v", err)
}
}
info, err := cluster.Info()
if err != nil {
return fmt.Errorf("Failed fetching cluster info: %v", err)
}
successMsg :=
`Success! Your AWS resources have been created:
%s
The containers that power your cluster are now being downloaded.
You should be able to access the Kubernetes API once the containers finish downloading.
`
fmt.Printf(successMsg, info.String())
return nil
}