/
server.go
45 lines (36 loc) · 849 Bytes
/
server.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
package proxy
import (
"github.com/hexiaodai/fence/internal/config"
"github.com/hexiaodai/fence/internal/healthz"
httpproxy "github.com/hexiaodai/fence/internal/proxy"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"
)
func getServerCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "proxy",
Aliases: []string{"proxy"},
Short: "Fence Proxy",
RunE: func(cmd *cobra.Command, args []string) error {
return server()
},
}
return cmd
}
func server() error {
return setupRunners()
}
func setupRunners() error {
ctx := ctrl.SetupSignalHandler()
server := config.New()
proxyrunner := httpproxy.New(server)
if err := proxyrunner.Start(ctx); err != nil {
return err
}
healthzRunner := healthz.New(server)
if err := healthzRunner.Start(); err != nil {
return err
}
<-ctx.Done()
return nil
}