-
Notifications
You must be signed in to change notification settings - Fork 6
/
scale.go
61 lines (51 loc) · 1.76 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
60
61
package nodegroup
import (
"fmt"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
"github.com/spf13/pflag"
)
type scaleCommand struct {
*commands.BaseCommand
name string
count int
completion.Kubernetes
resolver.CachingKubernetes
}
// ScaleCommand creates the "kubernetes nodegroup scale" command
func ScaleCommand() commands.Command {
return &scaleCommand{
BaseCommand: commands.New(
"scale",
"Scale the number of nodes in the node group.",
"upctl kubernetes nodegroup scale 55199a44-4751-4e27-9394-7c7661910be3 --name secondary-node-group --count 3",
),
}
}
// InitCommand implements Command.InitCommand
func (s *scaleCommand) InitCommand() {
flagSet := &pflag.FlagSet{}
flagSet.StringVar(&s.name, "name", "", "Node group name")
flagSet.IntVar(&s.count, "count", 0, "Node count")
s.AddFlags(flagSet)
_ = s.Cobra().MarkFlagRequired("name")
_ = s.Cobra().MarkFlagRequired("count")
}
// ExecuteSingleArgument implements commands.SingleArgumentCommand
func (s *scaleCommand) ExecuteSingleArgument(exec commands.Executor, arg string) (output.Output, error) {
msg := fmt.Sprintf("Scaling node group %s of cluster %v", s.name, arg)
exec.PushProgressStarted(msg)
res, err := exec.All().ModifyKubernetesNodeGroup(exec.Context(), &request.ModifyKubernetesNodeGroupRequest{
ClusterUUID: arg,
Name: s.name,
NodeGroup: request.ModifyKubernetesNodeGroup{Count: s.count},
})
if err != nil {
return commands.HandleError(exec, msg, err)
}
exec.PushProgressSuccess(msg)
return output.OnlyMarshaled{Value: res}, nil
}