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 runCmdValidate(cmd *cobra.Command, args []string) error {
	cfg, err := config.ClusterFromFile(configPath)
	if err != nil {
		return fmt.Errorf("Unable to load cluster config: %v", err)
	}

	fmt.Printf("Validating UserData...\n")
	if err := cfg.ValidateUserData(stackTemplateOptions); err != nil {
		return err
	}
	fmt.Printf("UserData is valid.\n\n")

	fmt.Printf("Validating stack template...\n")
	data, err := cfg.RenderStackTemplate(stackTemplateOptions)
	if err != nil {
		return fmt.Errorf("Failed to render stack template: %v", err)
	}

	cluster := cluster.New(cfg, validateOpts.awsDebug)
	report, err := cluster.ValidateStack(string(data))
	if report != "" {
		fmt.Fprintf(os.Stderr, "Validation Report: %s\n", report)
	}

	if err != nil {
		return err
	}
	fmt.Printf("stack template is valid.\n\n")

	fmt.Printf("Validation OK!\n")
	return nil
}
示例#3
0
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 dowloaded.

You should be able to access the Kubernetes API once the containers finish downloading.
`
	fmt.Printf(successMsg, info.String())

	return nil
}
func runCmdStatus(cmd *cobra.Command, args []string) error {
	conf, err := config.ClusterFromFile(configPath)
	if err != nil {
		return fmt.Errorf("Failed to read cluster config: %v", err)
	}
	info, err := cluster.New(conf, false).Info()
	if err != nil {
		return fmt.Errorf("Failed fetching cluster info: %v", err)
	}

	fmt.Print(info.String())
	return nil
}
func runCmdDestroy(cmd *cobra.Command, args []string) error {
	cfg, err := config.ClusterFromFile(configPath)
	if err != nil {
		return fmt.Errorf("Error parsing config: %v", err)
	}

	c := cluster.New(cfg, destroyOpts.awsDebug)
	if err := c.Destroy(); err != nil {
		return fmt.Errorf("Failed destroying cluster: %v", err)
	}

	fmt.Println("CloudFormation stack is being destroyed. This will take several minutes")
	return nil
}
func runCmdDestroy(cmd *cobra.Command, args []string) error {
	cfg, err := config.ClusterFromFile(configPath)
	if err != nil {
		return fmt.Errorf("Error parsing config: %v", err)
	}

	c := cluster.New(cfg, destroyOpts.awsDebug)
	if err := c.Destroy(); err != nil {
		return fmt.Errorf("Failed destroying cluster: %v", err)
	}

	fmt.Println("Destroyed cluster")
	return nil
}
示例#7
0
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())
}
示例#10
0
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)
	}

	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 {
		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)
	}

	fmt.Print(info.String())

	return nil
}
func runCmdStatus(cmd *cobra.Command, args []string) {
	cfg := cluster.NewDefaultConfig(VERSION)
	err := cluster.DecodeConfigFromFile(cfg, rootOpts.ConfigPath)
	if err != nil {
		stderr("Unable to load cluster config: %v", err)
		os.Exit(1)
	}

	c := cluster.New(cfg, newAWSConfig(cfg))

	info, err := c.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 := cluster.NewDefaultConfig(VERSION)
	err := cluster.DecodeConfigFromFile(cfg, rootOpts.ConfigPath)
	if err != nil {
		stderr("Unable to load cluster config: %v", err)
		os.Exit(1)
	}

	c := cluster.New(cfg, newAWSConfig(cfg))

	if err := c.Destroy(); err != nil {
		stderr("Failed destroying cluster: %v", err)
		os.Exit(1)
	}

	clusterDir := path.Join("clusters", cfg.ClusterName)
	if err := os.RemoveAll(clusterDir); err != nil {
		stderr("Failed removing local cluster directory: %v", err)
		os.Exit(1)
	}

	fmt.Println("Destroyed cluster")
}
示例#13
0
func runCmdUp(cmd *cobra.Command, args []string) {
	cfg := cluster.NewDefaultConfig(VERSION)
	err := cluster.DecodeConfigFromFile(cfg, rootOpts.ConfigPath)
	if err != nil {
		stderr("Unable to load cluster config: %v", err)
		os.Exit(1)
	}

	c := cluster.New(cfg, newAWSConfig(cfg))

	clusterDir, err := filepath.Abs(path.Join("clusters", cfg.ClusterName))
	if err != nil {
		stderr("Unable to expand cluster directory to absolute path: %v", err)
		os.Exit(1)
	}

	if err := os.MkdirAll(clusterDir, 0700); err != nil {
		stderr("Failed creating cluster workspace %s: %v", clusterDir, err)
		os.Exit(1)
	}

	tlsConfig, err := initTLS(cfg, clusterDir)
	if err != nil {
		stderr("Failed initializing TLS infrastructure: %v", err)
		os.Exit(1)
	}

	fmt.Println("Initialized TLS infrastructure")

	kubeconfig, err := newKubeconfig(cfg, tlsConfig)
	if err != nil {
		stderr("Failed rendering kubeconfig: %v", err)
		os.Exit(1)
	}

	kubeconfigPath := path.Join(clusterDir, "kubeconfig")
	if err := ioutil.WriteFile(kubeconfigPath, kubeconfig, 0600); err != nil {
		stderr("Failed writing kubeconfig to %s: %v", kubeconfigPath, err)
		os.Exit(1)
	}

	fmt.Printf("Wrote kubeconfig to %s\n", kubeconfigPath)

	fmt.Println("Waiting for cluster creation...")

	if err := c.Create(tlsConfig); err != nil {
		stderr("Failed creating cluster: %v", err)
		os.Exit(1)
	}

	fmt.Println("Successfully created cluster")
	fmt.Println("")

	info, err := c.Info()
	if err != nil {
		stderr("Failed fetching cluster info: %v", err)
		os.Exit(1)
	}

	fmt.Printf(info.String())
}