This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
minions.go
107 lines (92 loc) · 2.61 KB
/
minions.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
package main
import (
"fmt"
"os"
pluginIPAM "github.com/docker/go-plugins-helpers/ipam"
pluginNetwork "github.com/docker/go-plugins-helpers/network"
"github.com/pkg/errors"
"github.com/projectcalico/libcalico-go/lib/apiconfig"
calicov3 "github.com/projectcalico/libcalico-go/lib/clientv3"
cli "github.com/urfave/cli/v2"
dockerClient "github.com/docker/docker/client"
"github.com/projecteru2/minions/barrel"
"github.com/projecteru2/minions/barrel/etcd"
"github.com/projecteru2/minions/driver"
"github.com/projecteru2/minions/versioninfo"
log "github.com/sirupsen/logrus"
_ "go.uber.org/automaxprocs"
)
func serve(c *cli.Context) error {
log.SetOutput(os.Stdout)
if c.Bool("debug") {
log.SetLevel(log.DebugLevel)
log.Debugln("Debug logging enabled")
}
var (
config *apiconfig.CalicoAPIConfig
calicoCli calicov3.Interface
barrelMeta barrel.Meta
dockerCli *dockerClient.Client
err error
)
if config, err = apiconfig.LoadClientConfig(""); err != nil {
return err
}
if calicoCli, err = calicov3.New(*config); err != nil {
return err
}
if barrelMeta, err = etcd.NewEtcdClient(c.Context, *config); err != nil {
return err
}
if dockerCli, err = dockerClient.NewClientWithOpts(dockerClient.FromEnv); err != nil {
return errors.Wrap(err, "Error while attempting to instantiate docker client from env")
}
errChannel := make(chan error)
networkHandler := pluginNetwork.NewHandler(driver.NewNetworkDriver(calicoCli, dockerCli, barrelMeta))
ipamHandler := pluginIPAM.NewHandler(driver.NewIPAMDriver(calicoCli, barrelMeta))
go func() {
log.Infoln("calico-net has started.")
err := networkHandler.ServeUnix(c.String("cnm"), 0)
log.Infoln("calico-net has stopped working.")
errChannel <- err
}()
go func() {
log.Infoln("calico-ipam has started.")
err := ipamHandler.ServeUnix(c.String("ipam"), 0)
log.Infoln("calico-ipam has stopped working.")
errChannel <- err
}()
return <-errChannel
}
func main() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Print(versioninfo.VersionString())
}
app := cli.NewApp()
app.Name = versioninfo.NAME
app.Usage = "Run eru minions"
app.Version = versioninfo.VERSION
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "cnm",
Value: "calico",
Usage: "CNM name",
EnvVars: []string{"CALICO_CNM"},
},
&cli.StringFlag{
Name: "ipam",
Value: "calico-ipam",
Usage: "ipam name",
EnvVars: []string{"CALICO_IPAM"},
},
&cli.BoolFlag{
Name: "debug",
Usage: "debug or not",
EnvVars: []string{"CALICO_DEBUG"},
},
}
app.Action = serve
if err := app.Run(os.Args); err != nil {
log.Fatalln(err)
}
}