forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
109 lines (95 loc) · 2.94 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
package api
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/linkerd/linkerd2/controller/k8s"
"github.com/linkerd/linkerd2/pkg/admin"
"github.com/linkerd/linkerd2/pkg/flags"
"github.com/linkerd/linkerd2/pkg/trace"
log "github.com/sirupsen/logrus"
)
const defaultDomain = "cluster.local"
// Main executes the tap subcommand
func Main(args []string) {
cmd := flag.NewFlagSet("tap", flag.ExitOnError)
apiServerAddr := cmd.String("apiserver-addr", ":8089", "address to serve the apiserver on")
metricsAddr := cmd.String("metrics-addr", ":9998", "address to serve scrapable metrics on")
kubeConfigPath := cmd.String("kubeconfig", "", "path to kube config")
apiNamespace := cmd.String("api-namespace", "linkerd", "namespace in which Linkerd is installed")
tapPort := cmd.Uint("tap-port", 4190, "proxy tap port to connect to")
disableCommonNames := cmd.Bool("disable-common-names", false, "disable checks for Common Names (for development)")
trustDomain := cmd.String("identity-trust-domain", defaultDomain, "configures the name suffix used for identities")
enablePprof := cmd.Bool("enable-pprof", false, "Enable pprof endpoints on the admin server")
var ignoreHeaders = &stringMap{}
cmd.Var(ignoreHeaders, "ignore-headers", "list of headers to ignore")
traceCollector := flags.AddTraceFlags(cmd)
flags.ConfigureAndParse(cmd, args)
ready := false
adminServer := admin.NewServer(*metricsAddr, *enablePprof, &ready)
go func() {
log.Infof("starting admin server on %s", *metricsAddr)
if err := adminServer.ListenAndServe(); err != nil {
log.Errorf("failed to start tap admin server: %s", err)
}
}()
ctx := context.Background()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
k8sAPI, err := k8s.InitializeAPI(
ctx,
*kubeConfigPath,
true,
"local",
k8s.CJ,
k8s.DS,
k8s.SS,
k8s.Deploy,
k8s.Job,
k8s.NS,
k8s.Pod,
k8s.RC,
k8s.Svc,
k8s.RS,
k8s.Node,
)
if err != nil {
log.Fatalf("Failed to initialize K8s API: %s", err)
}
log.Infof("Using trust domain: %s", *trustDomain)
if *traceCollector != "" {
if err := trace.InitializeTracing("linkerd-tap", *traceCollector); err != nil {
log.Warnf("failed to initialize tracing: %s", err)
}
}
grpcTapServer, err := NewGrpcTapServer(*tapPort, *apiNamespace, *trustDomain, k8sAPI, *ignoreHeaders)
if err != nil {
log.Fatal(err.Error())
}
apiServer, err := NewServer(ctx, *apiServerAddr, k8sAPI, grpcTapServer, *disableCommonNames)
if err != nil {
log.Fatal(err.Error())
}
k8sAPI.Sync(nil)
go apiServer.Start(ctx)
ready = true
<-stop
log.Infof("shutting down APIServer on %s", *apiServerAddr)
apiServer.Shutdown(ctx)
adminServer.Shutdown(ctx)
}
type stringMap map[string]bool
func (m stringMap) String() string {
return fmt.Sprintf("%v", map[string]bool(m))
}
func (m stringMap) Set(value string) error {
parts := strings.Split(value, ",")
for _, p := range parts {
m[p] = true
}
return nil
}