Merge pull request #401 from justinsb/move_cloudprovider_not_set_message

Misc error handling tidying
This commit is contained in:
Justin Santa Barbara 2016-09-08 00:14:48 -04:00 committed by GitHub
commit a51effbbdd
4 changed files with 9 additions and 10 deletions

View File

@ -47,7 +47,7 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
err := createCluster.Run(args)
if err != nil {
glog.Exitf("%v", err)
exitWithError("%v", err)
}
},
}
@ -209,8 +209,7 @@ func (c *CreateClusterCmd) Run(args []string) error {
}
} else {
// This is hard, because of the etcd cluster
glog.Errorf("Cannot change master-zones from the CLI")
os.Exit(1)
return fmt.Errorf("Cannot change master-zones from the CLI")
}
}
@ -298,8 +297,7 @@ func (c *CreateClusterCmd) Run(args []string) error {
}
if cluster.SharedVPC() && cluster.Spec.NetworkCIDR == "" {
glog.Errorf("Must specify NetworkCIDR when VPC is set")
os.Exit(1)
return fmt.Errorf("Must specify NetworkCIDR when VPC is set")
}
if cluster.Spec.CloudProvider == "" {
@ -311,6 +309,9 @@ func (c *CreateClusterCmd) Run(args []string) error {
break
}
}
if cluster.Spec.CloudProvider == "" {
return fmt.Errorf("unable to infer CloudProvider from Zones (is there a typo in --zones?)")
}
}
sshPublicKeys := make(map[string][]byte)

View File

@ -24,8 +24,7 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
err := exportKubecfgCommand.Run(args)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
exitWithError(err)
}
},
}

View File

@ -37,8 +37,7 @@ It allows you to create, destroy, upgrade and maintain clusters.`,
func Execute() {
goflag.CommandLine.Parse([]string{})
if err := rootCommand.cobraCommand.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
exitWithError(err)
}
}

View File

@ -156,7 +156,7 @@ func (c *Cluster) Validate(strict bool) error {
// Check CloudProvider
{
if c.Spec.CloudProvider == "" {
return fmt.Errorf("unable to infer CloudProvider from Zones (is there a typo in --zones?)")
return fmt.Errorf("CloudProvider is not set")
}
if c.Spec.Kubelet != nil && c.Spec.Kubelet.CloudProvider != "" && c.Spec.Kubelet.CloudProvider != c.Spec.CloudProvider {
return fmt.Errorf("Kubelet CloudProvider did not match cluster CloudProvider")