/
monitor.go
62 lines (54 loc) · 1.76 KB
/
monitor.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
62
package main
import (
"time"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/openshift/baremetal-runtimecfg/pkg/config"
"github.com/openshift/baremetal-runtimecfg/pkg/monitor"
)
var log = logrus.New()
func main() {
var rootCmd = &cobra.Command{
Use: "monitor path_to_kubeconfig path_to_haproxy_cfg_template path_to_config",
Short: "Monitors master membership and updates HAProxy",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 3 {
cmd.Help()
return nil
}
clusterName, clusterDomain, err := config.GetKubeconfigClusterNameAndDomain(args[0])
if err != nil {
return err
}
apiPort, err := cmd.Flags().GetUint16("api-port")
if err != nil {
return err
}
lbPort, err := cmd.Flags().GetUint16("lb-port")
if err != nil {
return err
}
statPort, err := cmd.Flags().GetUint16("stat-port")
if err != nil {
return err
}
checkInterval, err := cmd.Flags().GetDuration("check-interval")
if err != nil {
return err
}
apiVip, err := cmd.Flags().GetIP("api-vip")
if err != nil {
return err
}
return monitor.Monitor(args[0], clusterName, clusterDomain, args[1], args[2], apiVip.String(), apiPort, lbPort, statPort, checkInterval)
},
}
rootCmd.Flags().Uint16("api-port", 6443, "Port where the OpenShift API listens at")
rootCmd.Flags().Uint16("lb-port", 9445, "Port where the API HAProxy LB will listen at")
rootCmd.Flags().Uint16("stat-port", 50000, "Port where the HAProxy stats API will listen at")
rootCmd.Flags().Duration("check-interval", time.Second*6, "Time between monitor checks")
rootCmd.Flags().IP("api-vip", nil, "Virtual IP Address to reach the OpenShift API")
if err := rootCmd.Execute(); err != nil {
log.Fatalf("Failed due to %s", err)
}
}