Skip to content

Commit 165f52a

Browse files
authored
Basic outline (#1)
Adds project layout and basic functionality of the consul-dataplane process.
1 parent 38f39ea commit 165f52a

File tree

18 files changed

+3507
-0
lines changed

18 files changed

+3507
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: consul-dataplane-checks
2+
3+
on:
4+
push:
5+
branches:
6+
main
7+
pull_request:
8+
9+
jobs:
10+
unit-tests:
11+
name: unit-tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-go@v3
16+
with:
17+
go-version: '1.18'
18+
- run: go test ./...
19+
golangci:
20+
name: lint
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/setup-go@v3
24+
with:
25+
go-version: 1.18
26+
- uses: actions/checkout@v3
27+
- name: golangci-lint
28+
uses: golangci/golangci-lint-action@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cmd/consul-dataplane/main
2+
/consul-dataplane

buf.gen.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: v1
2+
managed:
3+
enabled: true
4+
go_package_prefix:
5+
default: github.com/hashicorp/consul-dataplane/internal/consul-proto
6+
plugins:
7+
- name: go
8+
out: internal/consul-proto
9+
opt:
10+
- paths=source_relative
11+
- name: go-grpc
12+
out: internal/consul-proto
13+
opt:
14+
- paths=source_relative

cmd/consul-dataplane/main.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log"
7+
"strings"
8+
9+
"github.com/hashicorp/consul-dataplane/pkg/consuldp"
10+
)
11+
12+
var (
13+
addresses string
14+
grpcPort int
15+
logLevel string
16+
logJSON bool
17+
)
18+
19+
func init() {
20+
flag.StringVar(&addresses, "addresses", "", "Consul server addresses. Value can be:\n"+
21+
"1. DNS name (that resolves to servers or DNS name of a load-balancer front of Consul servers); OR\n"+
22+
"2.'exec=<executable with optional args>'. The executable\n"+
23+
" a) on success - should exit 0 and print to stdout whitespace delimited IP (v4/v6) addresses\n"+
24+
" b) on failure - exit with a non-zero code and optionally print an error message of upto 1024 bytes to stderr.\n"+
25+
" Refer to https://github.com/hashicorp/go-netaddrs#summary for more details and examples.")
26+
27+
flag.IntVar(&grpcPort, "grpc-port", 8502, "gRPC port on Consul servers")
28+
29+
flag.StringVar(&logLevel, "log-level", "info", "Log level of the messages to print. "+
30+
"Available log levels are \"trace\", \"debug\", \"info\", \"warn\", and \"error\".")
31+
32+
flag.BoolVar(&logJSON, "log-json", false, "Controls consul-dataplane logging in JSON format. By default this is false.")
33+
}
34+
35+
// validateFlags performs semantic validation of the flag values
36+
func validateFlags() {
37+
switch strings.ToUpper(logLevel) {
38+
case "TRACE", "DEBUG", "INFO", "WARN", "ERROR":
39+
default:
40+
log.Fatal("invalid log level. valid values - TRACE, DEBUG, INFO, WARN, ERROR")
41+
}
42+
}
43+
44+
func main() {
45+
46+
flag.Parse()
47+
48+
validateFlags()
49+
50+
consuldpCfg := &consuldp.Config{
51+
Consul: &consuldp.ConsulConfig{Addresses: addresses, GRPCPort: grpcPort},
52+
Logging: &consuldp.LoggingConfig{
53+
Name: "consul-dataplane",
54+
LogLevel: strings.ToUpper(logLevel),
55+
LogJSON: logJSON,
56+
},
57+
}
58+
consuldpInstance, err := consuldp.NewConsulDP(consuldpCfg)
59+
if err != nil {
60+
log.Fatal(err)
61+
}
62+
// TODO: Pass cancellable context
63+
err = consuldpInstance.Run(context.Background())
64+
if err != nil {
65+
log.Fatal(err)
66+
}
67+
}

go.mod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module github.com/hashicorp/consul-dataplane
2+
3+
go 1.18
4+
5+
require (
6+
github.com/hashicorp/go-hclog v1.2.2
7+
github.com/hashicorp/go-netaddrs v0.0.0-20220509001840-90ed9d26ec46
8+
github.com/stretchr/testify v1.8.0
9+
google.golang.org/grpc v1.48.0
10+
google.golang.org/protobuf v1.28.1
11+
)
12+
13+
require (
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/fatih/color v1.13.0 // indirect
16+
github.com/golang/protobuf v1.5.2 // indirect
17+
github.com/google/go-cmp v0.5.8 // indirect
18+
github.com/mattn/go-colorable v0.1.12 // indirect
19+
github.com/mattn/go-isatty v0.0.14 // indirect
20+
github.com/pmezard/go-difflib v1.0.0 // indirect
21+
github.com/stretchr/objx v0.4.0 // indirect
22+
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
23+
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
24+
golang.org/x/text v0.3.7 // indirect
25+
google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f // indirect
26+
gopkg.in/yaml.v3 v3.0.1 // indirect
27+
)

go.sum

Lines changed: 169 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)