forked from argoproj/argo-rollouts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (50 loc) · 1.36 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
package main
import (
"strings"
rolloutsPlugin "github.com/argoproj/argo-rollouts/rollout/steps/plugin/rpc"
"github.com/argoproj/argo-rollouts/test/cmd/step-plugin-e2e/internal/plugin"
goPlugin "github.com/hashicorp/go-plugin"
log "github.com/sirupsen/logrus"
)
var handshakeConfig = goPlugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "ARGO_ROLLOUTS_RPC_PLUGIN",
MagicCookieValue: "step",
}
func main() {
logCtx := log.WithFields(log.Fields{"plugin": "e2e"})
setLogLevel("debug")
log.SetFormatter(createFormatter("text"))
// pluginMap is the map of plugins we can dispense.
var pluginMap = map[string]goPlugin.Plugin{
"RpcStepPlugin": &rolloutsPlugin.RpcStepPlugin{Impl: plugin.New(logCtx)},
}
goPlugin.Serve(&goPlugin.ServeConfig{
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
})
}
func createFormatter(logFormat string) log.Formatter {
var formatType log.Formatter
switch strings.ToLower(logFormat) {
case "json":
formatType = &log.JSONFormatter{}
case "text":
formatType = &log.TextFormatter{
FullTimestamp: true,
}
default:
log.Infof("Unknown format: %s. Using text logformat", logFormat)
formatType = &log.TextFormatter{
FullTimestamp: true,
}
}
return formatType
}
func setLogLevel(logLevel string) {
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Fatal(err)
}
log.SetLevel(level)
}