Merge pull request #307 from justinsb/fix_208

If no changes are needed in an update, don't print a confusing message
This commit is contained in:
Justin Santa Barbara 2016-08-14 23:43:06 -04:00 committed by GitHub
commit d9fb3812cb
5 changed files with 30 additions and 13 deletions

View File

@ -91,15 +91,16 @@ func (c *CreateClusterCmd) Run(args []string) error {
isDryrun := false
// direct requires --yes (others do not, because they don't make changes)
targetName := c.Target
if c.Target == cloudup.TargetDirect {
if !c.Yes {
isDryrun = true
c.Target = cloudup.TargetDryRun
targetName = cloudup.TargetDryRun
}
}
if c.Target == cloudup.TargetDryRun {
isDryrun = true
c.Target = cloudup.TargetDryRun
targetName = cloudup.TargetDryRun
}
clusterName := rootCommand.clusterName
@ -374,7 +375,7 @@ func (c *CreateClusterCmd) Run(args []string) error {
InstanceGroups: fullInstanceGroups,
Models: strings.Split(c.Models, ","),
ClusterRegistry: clusterRegistry,
Target: c.Target,
TargetName: targetName,
OutDir: c.OutDir,
DryRun: isDryrun,
}

View File

@ -127,7 +127,7 @@ func readKubectlClusterConfig() (*kutil.KubectlClusterWithName, error) {
}
// Minify should have done this
if len(config.Clusters) != 1 {
if len(config.Clusters) != 1 {
return nil, fmt.Errorf("expected exactly one cluster in kubectl config, found %d", len(config.Clusters))
}

View File

@ -53,16 +53,18 @@ func (c *UpdateClusterCmd) Run(args []string) error {
}
isDryrun := false
targetName := c.Target
// direct requires --yes (others do not, because they don't do anything!)
if c.Target == cloudup.TargetDirect {
if !c.Yes {
isDryrun = true
c.Target = cloudup.TargetDryRun
targetName = cloudup.TargetDryRun
}
}
if c.Target == cloudup.TargetDryRun {
isDryrun = true
c.Target = cloudup.TargetDryRun
targetName = cloudup.TargetDryRun
}
if c.OutDir == "" {
@ -118,7 +120,7 @@ func (c *UpdateClusterCmd) Run(args []string) error {
InstanceGroups: fullInstanceGroups,
Models: strings.Split(c.Models, ","),
ClusterRegistry: clusterRegistry,
Target: c.Target,
TargetName: targetName,
OutDir: c.OutDir,
DryRun: isDryrun,
}
@ -128,7 +130,12 @@ func (c *UpdateClusterCmd) Run(args []string) error {
}
if isDryrun {
fmt.Printf("Must specify --yes to apply changes\n")
target := applyCmd.Target.(*fi.DryRunTarget)
if target.HasChanges() {
fmt.Printf("Must specify --yes to apply changes\n")
} else {
fmt.Printf("No changes need to be applied\n")
}
return nil
}
@ -196,4 +203,4 @@ func hasKubecfg(contextName string) (bool, error) {
}
}
return false, nil
}
}

View File

@ -32,8 +32,11 @@ type ApplyClusterCmd struct {
// Models is a list of cloudup models to apply
Models []string
// Target specifies how we are operating e.g. direct to GCE, or AWS, or dry-run, or terraform
Target string
// TargetName specifies how we are operating e.g. direct to GCE, or AWS, or dry-run, or terraform
TargetName string
// Target is the fi.Target we will operate against
Target fi.Target
// OutDir is a local directory in which we place output, can cache files etc
OutDir string
@ -413,7 +416,7 @@ func (c *ApplyClusterCmd) Run() error {
var target fi.Target
switch c.Target {
switch c.TargetName {
case TargetDirect:
switch cluster.Spec.CloudProvider {
case "gce":
@ -432,8 +435,9 @@ func (c *ApplyClusterCmd) Run() error {
case TargetDryRun:
target = fi.NewDryRunTarget(os.Stdout)
default:
return fmt.Errorf("unsupported target type %q", c.Target)
return fmt.Errorf("unsupported target type %q", c.TargetName)
}
c.Target = target
context, err := fi.NewContext(target, cloud, keyStore, secretStore, checkExisting)
if err != nil {

View File

@ -257,3 +257,8 @@ func ValueAsString(value reflect.Value) string {
func (t *DryRunTarget) Finish(taskMap map[string]Task) error {
return t.PrintReport(taskMap, t.out)
}
// HasChanges returns true iff any changes would have been made
func (t *DryRunTarget) HasChanges() bool {
return len(t.changes) != 0
}