func runCmdValidate(cmd *cobra.Command, args []string) { cfg, err := config.NewConfigFromFile(ConfigPath) if err != nil { stderr("Unable to load cluster config: %v", err) os.Exit(1) } if err := cfg.ReadAssetsFromFiles(); err != nil { stderr("Error reading assets from files: %v", err) os.Exit(1) } if err := cfg.TemplateAndEncodeAssets(); err != nil { stderr("template/encode error: %v", err) os.Exit(1) } cluster := cluster.New(cfg, upOpts.awsDebug) report, err := cluster.ValidateStack() if report != "" { fmt.Printf("Validation Report: %s\n", report) } if err != nil { stderr("Error creating cluster: %v", err) os.Exit(1) } else { fmt.Printf("Validation OK!\n") } }
func runCmdUp(cmd *cobra.Command, args []string) { cfg, err := config.NewConfigFromFile(ConfigPath) if err != nil { stderr("Unable to load cluster config: %v", err) os.Exit(1) } if err := cfg.ReadAssetsFromFiles(); err != nil { stderr("Error reading assets from files: %v", err) os.Exit(1) } if err := cfg.TemplateAndEncodeAssets(); err != nil { stderr("Error templating assets: %v", err) os.Exit(1) } if upOpts.export { templatePath := fmt.Sprintf("./%s.stack-template.json", cfg.ClusterName) fmt.Printf("Exporting %s\n", templatePath) if err := ioutil.WriteFile(templatePath, cfg.StackTemplate.Bytes(), 0600); err != nil { stderr("Error writing %s : %v", templatePath, err) os.Exit(1) } fmt.Printf("BEWARE: %s contains your TLS secrets!\n", templatePath) os.Exit(0) } cluster := cluster.New(cfg, upOpts.awsDebug) if upOpts.update { if err := cluster.Update(); err != nil { stderr("Error updating cluster: %v", err) os.Exit(1) } } else { if err := cluster.Create(); err != nil { stderr("Error creating cluster: %v", err) os.Exit(1) } } info, err := cluster.Info() if err != nil { stderr("Failed fetching cluster info: %v", err) os.Exit(1) } fmt.Print(info.String()) }
func runCmdDestroy(cmd *cobra.Command, args []string) { cfg, err := config.NewConfigFromFile(ConfigPath) if err != nil { stderr("Error parsing config: %v", err) os.Exit(1) } cluster := cluster.New(cfg, destroyOpts.awsDebug) if err := cluster.Destroy(); err != nil { stderr("Failed destroying cluster: %v", err) os.Exit(1) } fmt.Println("Destroyed cluster") }
func runCmdStatus(cmd *cobra.Command, args []string) { cfg, err := config.NewConfigFromFile(ConfigPath) if err != nil { stderr("Error parsing config: %v", err) os.Exit(1) } cluster := cluster.New(cfg, false) info, err := cluster.Info() if err != nil { stderr("Failed fetching cluster info: %v", err) os.Exit(1) } fmt.Print(info.String()) }
func runCmdRender(cmd *cobra.Command, args []string) { cfg, err := config.NewConfigFromFile(ConfigPath) if err != nil { stderr("Error parsing config from file: %v", err) os.Exit(1) } if err := cfg.GenerateDefaultAssets(); err != nil { stderr("Error generating default assets : %v", err) os.Exit(1) } if err := cfg.KubeConfig.Template(cfg); err != nil { stderr("Error templating kubeconfig : %v", err) os.Exit(1) } if err := cfg.WriteAssetsToFiles(); err != nil { stderr("Error writing assets to file: %v", err) os.Exit(1) } fmt.Printf("Edit %s and/or any of the cluster assets. Then use the \"kube-aws up\" command to create the stack\n", ConfigPath) }