Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse the config returned by the loadbalancer-api and turn that into a valid haproxy config #15

Merged
merged 18 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ FROM nats:latest as nats
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${GO_VERSION}-bullseye

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install --no-install-recommends bash-completion vim
apt-get -y install --no-install-recommends bash-completion vim

RUN go install github.com/nats-io/natscli/nats@latest
2 changes: 2 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ var (
ErrNATSAuthRequired = errors.New("nats creds are required and cannot be empty")
// ErrHAProxyBaseConfigRequired is returned when the base HAProxy config is missing
ErrHAProxyBaseConfigRequired = errors.New("base haproxy config is required and cannot be empty")
// ErrLBAPIURLRequired is returned when the LB API url is missing
ErrLBAPIURLRequired = errors.New("loadbalancer api url is required and cannot be empty")
)
11 changes: 10 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os/signal"
"strings"

"go.infratographer.com/loadbalancer-manager-haproxy/internal/dataplaneapi"
"go.infratographer.com/loadbalancer-manager-haproxy/internal/lbapi"
"go.infratographer.com/loadbalancer-manager-haproxy/internal/pkg"

"github.com/nats-io/nats.go"
Expand Down Expand Up @@ -76,13 +78,16 @@ func run(cmdCtx context.Context, v *viper.Viper) error {
defer natsConn.Close()

// init other components
dpc := pkg.NewDataPlaneClient(viper.GetString("dataplane.url"))
dpc := dataplaneapi.NewClient(viper.GetString("dataplane.url"))
lbc := lbapi.NewClient(viper.GetString("loadbalancerapi.url"))

mgr := &pkg.ManagerConfig{
Context: ctx,
Logger: logger,
NatsConn: natsConn,
DataPlaneClient: dpc,
LBClient: lbc,
BaseCfgPath: viper.GetString("haproxy.config.base"),
}

if err := mgr.Run(); err != nil {
Expand All @@ -108,6 +113,10 @@ func validateMandatoryFlags() error {
errs = append(errs, ErrHAProxyBaseConfigRequired.Error())
}

if viper.GetString("loadbalancerapi.url") == "" {
errs = append(errs, ErrLBAPIURLRequired.Error())
}

if len(errs) == 0 {
return nil
}
Expand Down
32 changes: 18 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ go 1.19

require (
github.com/haproxytech/config-parser/v4 v4.1.0
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/mitchellh/go-homedir v1.1.0
github.com/nats-io/nats.go v1.21.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
go.infratographer.com/x v0.0.3
go.uber.org/zap v1.24.0
gocloud.dev v0.27.0
gocloud.dev/pubsub/natspubsub v0.27.0
)

Expand All @@ -21,34 +24,35 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/renameio v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/haproxytech/go-logger v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
gocloud.dev v0.27.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.102.0 // indirect
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading