-
Notifications
You must be signed in to change notification settings - Fork 24
/
scale.go
59 lines (49 loc) · 1.32 KB
/
scale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2019 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cmd
import (
"context"
"fmt"
"github.com/tsuru/rpaas-operator/pkg/rpaas/client"
"github.com/urfave/cli"
)
func initScaleFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "service, s",
Usage: "service name",
Required: true,
},
cli.StringFlag{
Name: "instance, i",
Usage: "instance name",
Required: true,
},
cli.IntFlag{
Name: "quantity, q",
Usage: "amount of units to scale to",
Required: true,
},
}
}
func Scale() cli.Command {
return cli.Command{
Name: "scale",
Usage: "Scales the specified rpaas instance to [-q] replica(s)",
Flags: initScaleFlags(),
Action: func(ctx *cli.Context) error {
tsuruClient, err := client.NewTsuruClient(ctx.GlobalString("target"), ctx.String("service"), ctx.GlobalString("token"))
if err != nil {
return err
}
inst := client.ScaleInstance{Instance: client.Instance{Name: ctx.String("instance")}, Replicas: int32(ctx.Int("quantity"))}
err = tsuruClient.Scale(context.TODO(), inst)
if err != nil {
return err
}
fmt.Fprintf(ctx.App.Writer, "Instance successfully scaled to %d replica(s)\n", inst.Replicas)
return nil
},
}
}