forked from infinispan/infinispan-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (66 loc) · 2.09 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/infinispan/infinispan-operator/launcher/listener"
"github.com/infinispan/infinispan-operator/launcher/operator"
"go.uber.org/zap/zapcore"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)
func main() {
if len(os.Args) < 2 {
exit()
}
zapOpts := zap.Options{
Development: true,
TimeEncoder: zapcore.ISO8601TimeEncoder,
}
// Operator Flags
operatorFs := flag.NewFlagSet("operator", flag.ExitOnError)
metricsAddr := operatorFs.String("metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
probeAddr := operatorFs.String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
enableLeaderElection := operatorFs.Bool("leader-elect", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
zapOpts.BindFlags(operatorFs)
// Listener Flags
listenerFs := flag.NewFlagSet("listener", flag.ExitOnError)
listenerFs.String("kubeconfig", "", "Paths to a kubeconfig. Only required if out-of-cluster.")
listenerNs := listenerFs.String("namespace", "", "The namespace of the Infinispan cluster.")
listenerCluster := listenerFs.String("cluster", "", "The name of the Infinispan cluster.")
zapOpts.BindFlags(listenerFs)
switch os.Args[1] {
case "operator":
parse(operatorFs, os.Args[2:])
operator.New(operator.Parameters{
MetricsBindAddress: *metricsAddr,
HealthProbeBindAddress: *probeAddr,
LeaderElection: *enableLeaderElection,
ZapOptions: &zapOpts,
})
case "listener":
parse(listenerFs, os.Args[2:])
if *listenerNs == "" {
listenerFs.Usage()
os.Exit(1)
}
listener.New(context.Background(), listener.Parameters{
Namespace: *listenerNs,
Cluster: *listenerCluster,
ZapOptions: &zapOpts,
})
default:
exit()
}
}
func exit() {
fmt.Println("expected 'operator' or 'listener' subcommands")
os.Exit(1)
}
func parse(flags *flag.FlagSet, args []string) {
if err := flags.Parse(args); err != nil {
fmt.Println(err)
os.Exit(1)
}
}