From 52e1578a4e12d765b65f40721db9b52871cfe96b Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Mon, 18 Jan 2016 13:21:23 -0600 Subject: [PATCH 1/3] Allow for autoscaling. --- main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.go b/main.go index 028db7a..a98c560 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,12 @@ type GrowCommand struct { Nodes int } +// AutoScaleCommand keeps context about a cluster command +type AutoScaleCommand struct { + *ClusterCommand + AutoScale bool +} + // UserNameEnvKey is the name of the env var accepted for the username const UserNameEnvVar = "CARINA_USERNAME" @@ -163,6 +169,11 @@ func New() *Application { growCommand.Flag("by", "number of segments to increase the cluster by").Required().IntVar(&growCommand.Nodes) growCommand.Action(growCommand.Grow) + autoscaleCommand := new(AutoScaleCommand) + autoscaleCommand.ClusterCommand = cap.NewClusterCommand(ctx, "autoscale", "Enable or disable autoscale on a cluster") + autoscaleCommand.Flag("autoscale", "whether autoscale is on or off").BoolVar(&autoscaleCommand.AutoScale) + autoscaleCommand.Action(autoscaleCommand.SetAutoScale) + credentialsCommand := cap.NewCredentialsCommand(ctx, "credentials", "download credentials") credentialsCommand.Action(credentialsCommand.Download) @@ -547,6 +558,13 @@ func (carina *GrowCommand) Grow(pc *kingpin.ParseContext) (err error) { }) } +// SetAutoScale sets AutoScale on the cluster +func (carina *AutoScaleCommand) SetAutoScale(pc *kingpin.ParseContext) (err error) { + return carina.clusterApply(func(clusterName string) (*libcarina.Cluster, error) { + return carina.ClusterClient.SetAutoScale(clusterName, carina.AutoScale) + }) +} + // Rebuild nukes your cluster and builds it over again func (carina *WaitClusterCommand) Rebuild(pc *kingpin.ParseContext) (err error) { return carina.clusterApplyWait(carina.ClusterClient.Rebuild) From a70306715e1d9479414081cc281182cc487c3c26 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Mon, 18 Jan 2016 13:43:37 -0600 Subject: [PATCH 2/3] Set autoscale according to either "on" or "off" --- main.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index a98c560..9ca9e7c 100644 --- a/main.go +++ b/main.go @@ -92,9 +92,15 @@ type GrowCommand struct { // AutoScaleCommand keeps context about a cluster command type AutoScaleCommand struct { *ClusterCommand - AutoScale bool + AutoScale string } +// AutoScaleOn is the "give me autoscale on this cluster" string for the cli +const AutoScaleOn = "on" + +// AutoScaleOff is the "turn off autoscale on this cluster" string for the cli +const AutoScaleOff = "off" + // UserNameEnvKey is the name of the env var accepted for the username const UserNameEnvVar = "CARINA_USERNAME" @@ -171,7 +177,7 @@ func New() *Application { autoscaleCommand := new(AutoScaleCommand) autoscaleCommand.ClusterCommand = cap.NewClusterCommand(ctx, "autoscale", "Enable or disable autoscale on a cluster") - autoscaleCommand.Flag("autoscale", "whether autoscale is on or off").BoolVar(&autoscaleCommand.AutoScale) + autoscaleCommand.Flag("autoscale", "whether autoscale is on or off").EnumVar(&autoscaleCommand.AutoScale, AutoScaleOn, AutoScaleOff) autoscaleCommand.Action(autoscaleCommand.SetAutoScale) credentialsCommand := cap.NewCredentialsCommand(ctx, "credentials", "download credentials") @@ -561,7 +567,17 @@ func (carina *GrowCommand) Grow(pc *kingpin.ParseContext) (err error) { // SetAutoScale sets AutoScale on the cluster func (carina *AutoScaleCommand) SetAutoScale(pc *kingpin.ParseContext) (err error) { return carina.clusterApply(func(clusterName string) (*libcarina.Cluster, error) { - return carina.ClusterClient.SetAutoScale(clusterName, carina.AutoScale) + scale := true + + switch carina.AutoScale { + case AutoScaleOn: + scale = true + break + case AutoScaleOff: + scale = false + break + } + return carina.ClusterClient.SetAutoScale(clusterName, scale) }) } From 4920a57365dcf04ecdb20179c4be4781e24805d8 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Mon, 18 Jan 2016 13:48:27 -0600 Subject: [PATCH 3/3] Enum'ed Arg --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 9ca9e7c..d196926 100644 --- a/main.go +++ b/main.go @@ -177,7 +177,7 @@ func New() *Application { autoscaleCommand := new(AutoScaleCommand) autoscaleCommand.ClusterCommand = cap.NewClusterCommand(ctx, "autoscale", "Enable or disable autoscale on a cluster") - autoscaleCommand.Flag("autoscale", "whether autoscale is on or off").EnumVar(&autoscaleCommand.AutoScale, AutoScaleOn, AutoScaleOff) + autoscaleCommand.Arg("autoscale", "whether autoscale is on or off").EnumVar(&autoscaleCommand.AutoScale, AutoScaleOn, AutoScaleOff) autoscaleCommand.Action(autoscaleCommand.SetAutoScale) credentialsCommand := cap.NewCredentialsCommand(ctx, "credentials", "download credentials")