-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
109 lines (86 loc) · 3.68 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
// kolumbus will watch docker for specific labels and create a dns server that
// enables envoyproxy to create a dynamic microservice mesh
package main
import (
"log"
"os"
"time"
"github.com/namsral/flag"
"github.com/pkg/errors"
)
func main() {
// initialize the configuration
config := Config{}
// get the container host name
config.Hostname = os.Getenv("HOSTNAME")
var discoveryInterval string
flag.IntVar(&config.DataPlanePort, "dataplane", 1492, "port to start the envoyproxy data plane discovery service on")
flag.IntVar(&config.LocalProxyPort, "local-proxy", 1494, "port to start local proxy service of the internal envoyproxy instance on")
flag.StringVar(&config.RemoteProxyMode, "remote-proxy-mode", MODE_NONE, "modus to use for remote proxy service (none/outbound/inbound)")
flag.IntVar(&config.RemoteProxyPort, "remote-proxy-port", 1498, "(inbound) port to start the remote proxy service on the internal envoyproxy instance on")
flag.StringVar(&config.RemoteProxyAddress, "remote-proxy-address", "", "(outbound) address of the remote proxy service to call")
flag.StringVar(&discoveryInterval, "discovery-interval", "5s", "interval at which new services in network will be searched (in ms/s/m/h")
flag.Parse()
// initialize a channel of errors
errorChan := make(chan error)
var err error
config.DiscoveryInterval, err = time.ParseDuration(discoveryInterval)
if err != nil {
errorChan <- errors.Wrap(err, "could not parse discovery interval")
}
// log the configuration
log.Printf("- configuration: %+v\n", config)
kolumbus := FindABraveNewWorld()
// log any errors in a separate go routine
go func() {
for err := range errorChan {
log.Printf("%+v\n", err)
if cause := errors.Cause(err); cause != nil {
log.Printf("-- %+v\n", cause)
}
}
}()
kolumbus.IdentifyContainer(config, errorChan)
log.Println("- start identifying container")
// start watching docker containers for services
kolumbus.StartDockerWatch(config, errorChan)
log.Println("- docker container watch started")
// start an envoyproxy and optionally open a port for
// external communication
kolumbus.StartEnvoyproxy(config, errorChan)
log.Println("- envoy proxy started")
// start a data plane discovery service for envoyproxies to automatically
// create a service mesh
kolumbus.StartEnvoyDataPlaneServer(config, errorChan)
log.Println("- envoy discovery server started")
// keep application running
run := make(chan bool)
<-run
}
// Config is used to define customizable configuration options
type Config struct {
// define a port for envoy proxy data plane server that will be checked
// by all envoyproxy instances for configuration information
DataPlanePort int
// define a port for a local envoyproxy instance that will be used
// as local proxy for development
LocalProxyPort int
// define a port for a local envoyproxy instance that will be used for
// remote connections to the cluster. connections are secured with tls
// the mode (inbound/outbound) will define if envoyproxy will listen to
// requests or send out requests to a remote cluster
RemoteProxyMode string // inbound or outbound
RemoteProxyPort int // port to start the remote service on (inbound)
RemoteProxyAddress string // address for a remote service to call (outbound)
// hostname of the container. this is used to identify the corresponding
// container in the docker container list
Hostname string
// interval at which kolumbus searches for new services in the same network,
// if a new service will be discovered, its network address will be added
// to the network list
DiscoveryInterval time.Duration
}
// nolint
const MODE_NONE = "none"
const MODE_INBOUND = "inbound"
const MODE_OUTBOUND = "outbound"