-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (50 loc) · 1.82 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
package main
import (
"context"
"flag"
"os"
"os/signal"
"time"
"github.com/Octops/octops-image-syncer/cmd"
"github.com/Octops/octops-image-syncer/internal/version"
"github.com/Octops/octops-image-syncer/pkg/runtime/log"
"k8s.io/client-go/tools/clientcmd"
)
var (
masterURL string
kubeconfig string
port int
syncPeriod string
metricsBindAddress string
)
func main() {
log.Logger().Info(version.Info())
flag.Parse()
if kubeconfig == "" {
kubeconfig = flag.Lookup("kubeconfig").Value.String()
}
clientConf, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
log.Logger().Fatalf("Error building kubeconfig: %s", err.Error())
}
duration, err := time.ParseDuration(syncPeriod)
if err != nil {
log.Logger().WithError(err).Fatalf("error parsing sync-period flag: %s", syncPeriod)
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
if err := cmd.Execute(ctx, clientConf, duration, port, metricsBindAddress); err != nil {
log.Logger().WithError(err).Fatal("failed to start syncer")
}
}
func init() {
if flag.Lookup("kubeconfig") == nil {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
}
if flag.Lookup("master") == nil {
flag.StringVar(&masterURL, "master", "", "The addr of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
}
flag.IntVar(&port, "addr", 8090, "Port used by the broadcaster to communicate via http")
flag.StringVar(&syncPeriod, "sync-period", "15s", "Determines the minimum frequency that the syncer will check for Fleets updates")
flag.StringVar(&metricsBindAddress, "metrics-bind-address", "0.0.0.0:8095", "The TCP address that the controller should bind to for serving prometheus metrics")
}