forked from k3s-io/kine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
135 lines (128 loc) · 3.96 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"context"
"errors"
"fmt"
"os"
"time"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/k3s-io/kine/pkg/metrics"
"github.com/k3s-io/kine/pkg/version"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var (
config endpoint.Config
metricsConfig metrics.Config
)
func main() {
app := cli.NewApp()
app.Name = "kine"
app.Usage = "Minimal etcd v3 API to support custom Kubernetes storage engines"
app.Version = fmt.Sprintf("%s (%s)", version.Version, version.GitCommit)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "listen-address",
Value: "0.0.0.0:2379",
Destination: &config.Listener,
},
cli.StringFlag{
Name: "endpoint",
Usage: "Storage endpoint (default is sqlite)",
Destination: &config.Endpoint,
},
cli.StringFlag{
Name: "ca-file",
Usage: "CA cert for DB connection",
Destination: &config.BackendTLSConfig.CAFile,
},
cli.StringFlag{
Name: "cert-file",
Usage: "Certificate for DB connection",
Destination: &config.BackendTLSConfig.CertFile,
},
cli.StringFlag{
Name: "server-cert-file",
Usage: "Certificate for etcd connection",
Destination: &config.ServerTLSConfig.CertFile,
},
cli.StringFlag{
Name: "server-key-file",
Usage: "Key file for etcd connection",
Destination: &config.ServerTLSConfig.KeyFile,
},
cli.IntFlag{
Name: "datastore-max-idle-connections",
Usage: "Maximum number of idle connections retained by datastore. If value = 0, the system default will be used. If value < 0, idle connections will not be reused.",
Destination: &config.ConnectionPoolConfig.MaxIdle,
Value: 0,
},
cli.IntFlag{
Name: "datastore-max-open-connections",
Usage: "Maximum number of open connections used by datastore. If value <= 0, then there is no limit",
Destination: &config.ConnectionPoolConfig.MaxOpen,
Value: 0,
},
cli.DurationFlag{
Name: "datastore-connection-max-lifetime",
Usage: "Maximum amount of time a connection may be reused. If value <= 0, then there is no limit.",
Destination: &config.ConnectionPoolConfig.MaxLifetime,
Value: 0,
},
cli.StringFlag{
Name: "key-file",
Usage: "Key file for DB connection",
Destination: &config.BackendTLSConfig.KeyFile,
},
cli.StringFlag{
Name: "metrics-bind-address",
Usage: "The address the metric endpoint binds to. Default :8080, set 0 to disable metrics serving.",
Destination: &metricsConfig.ServerAddress,
Value: ":8080",
},
cli.DurationFlag{
Name: "slow-sql-threshold",
Usage: "The duration which SQL executed longer than will be logged. Default 1s, set <= 0 to disable slow SQL log.",
Destination: &metrics.SlowSQLThreshold,
Value: time.Second,
},
cli.BoolFlag{
Name: "metrics-enable-profiling",
Usage: "Enable net/http/pprof handlers on the metrics bind address. Default is false.",
Destination: &metricsConfig.EnableProfiling,
},
cli.DurationFlag{
Name: "watch-progress-notify-interval",
Usage: "Interval between periodic watch progress notifications. Default is 10m.",
Destination: &config.NotifyInterval,
Value: time.Minute * 10,
},
cli.BoolFlag{Name: "debug"},
}
app.Action = run
if err := app.Run(os.Args); err != nil {
if !errors.Is(err, context.Canceled) {
logrus.Fatal(err)
}
}
}
func run(c *cli.Context) error {
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: time.RFC3339Nano,
})
if c.Bool("debug") {
logrus.SetLevel(logrus.TraceLevel)
}
ctx := signals.SetupSignalContext()
metricsConfig.ServerTLSConfig = config.ServerTLSConfig
go metrics.Serve(ctx, metricsConfig)
config.MetricsRegisterer = metrics.Registry
_, err := endpoint.Listen(ctx, config)
if err != nil {
return err
}
<-ctx.Done()
return ctx.Err()
}