diff --git a/main.go b/main.go index 028db7a..d196926 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,18 @@ type GrowCommand struct { Nodes int } +// AutoScaleCommand keeps context about a cluster command +type AutoScaleCommand struct { + *ClusterCommand + 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" @@ -163,6 +175,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.Arg("autoscale", "whether autoscale is on or off").EnumVar(&autoscaleCommand.AutoScale, AutoScaleOn, AutoScaleOff) + autoscaleCommand.Action(autoscaleCommand.SetAutoScale) + credentialsCommand := cap.NewCredentialsCommand(ctx, "credentials", "download credentials") credentialsCommand.Action(credentialsCommand.Download) @@ -547,6 +564,23 @@ 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) { + scale := true + + switch carina.AutoScale { + case AutoScaleOn: + scale = true + break + case AutoScaleOff: + scale = false + break + } + return carina.ClusterClient.SetAutoScale(clusterName, scale) + }) +} + // Rebuild nukes your cluster and builds it over again func (carina *WaitClusterCommand) Rebuild(pc *kingpin.ParseContext) (err error) { return carina.clusterApplyWait(carina.ClusterClient.Rebuild)