/
maintenance.go
61 lines (50 loc) · 1.7 KB
/
maintenance.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 main
import (
"github.com/spf13/cobra"
dc "github.com/chef/automate/api/config/deployment"
"github.com/chef/automate/api/config/load_balancer"
w "github.com/chef/automate/api/config/shared/wrappers"
"github.com/chef/automate/components/automate-cli/pkg/docs"
"github.com/chef/automate/components/automate-cli/pkg/status"
"github.com/chef/automate/components/automate-deployment/pkg/client"
)
var maintenanceOpts = struct {
timeout int64
}{}
func init() {
maintenanceCmd.PersistentFlags().Int64VarP(&maintenanceOpts.timeout, "timeout", "t", 10, "Request timeout in seconds")
RootCmd.AddCommand(maintenanceCmd)
}
var maintenanceCmd = &cobra.Command{
Use: "maintenance [on|off]",
Short: "Put Chef Automate into or out of maintenance mode",
Long: "Chef Automate maintenance mode keeps all services running but rejects new connections at the load balancer so that maintenance operations can be performed.",
Args: cobra.ExactArgs(1),
RunE: runMaintenanceCmd,
Annotations: map[string]string{
docs.Tag: docs.FrontEnd,
},
}
func runMaintenanceCmd(cmd *cobra.Command, args []string) error {
if args[0] != "off" && args[0] != "on" {
return status.New(status.InvalidCommandArgsError, "you must supply either 'on' or 'off'")
}
enable := w.Bool(false)
if args[0] == "on" {
enable = w.Bool(true)
}
cfg := dc.NewUserOverrideConfig()
cfg.LoadBalancer = &load_balancer.ConfigRequest{
V1: &load_balancer.ConfigRequest_V1{
Sys: &load_balancer.ConfigRequest_V1_System{
Service: &load_balancer.ConfigRequest_V1_System_Service{
MaintenanceMode: enable,
},
},
},
}
if err := client.PatchAutomateConfig(maintenanceOpts.timeout, cfg, writer); err != nil {
return err
}
return nil
}