-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: R.B. Boyer <[email protected]> Co-authored-by: R.B. Boyer <[email protected]> Co-authored-by: Freddy <[email protected]>
- Loading branch information
1 parent
07fce86
commit 6200536
Showing
60 changed files
with
7,818 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/terraform | ||
/workdir | ||
/sample-cli | ||
workdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
[![GoDoc](https://pkg.go.dev/badge/github.com/hashicorp/consul/testing/deployer)](https://pkg.go.dev/github.com/hashicorp/consul/testing/deployer) | ||
|
||
## Summary | ||
|
||
This is a Go library used to launch one or more Consul clusters that can be | ||
peered using the cluster peering feature. Under the covers `terraform` is used | ||
in conjunction with the | ||
[`kreuzwerker/docker`](https://registry.terraform.io/providers/kreuzwerker/docker/latest) | ||
provider to manage a fleet of local docker containers and networks. | ||
|
||
### Configuration | ||
|
||
The complete topology of Consul clusters is defined using a topology.Config | ||
which allows you to define a set of networks and reference those networks when | ||
assigning nodes and services to clusters. Both Consul clients and | ||
`consul-dataplane` instances are supported. | ||
|
||
Here is an example configuration with two peered clusters: | ||
|
||
``` | ||
cfg := &topology.Config{ | ||
Networks: []*topology.Network{ | ||
{Name: "dc1"}, | ||
{Name: "dc2"}, | ||
{Name: "wan", Type: "wan"}, | ||
}, | ||
Clusters: []*topology.Cluster{ | ||
{ | ||
Name: "dc1", | ||
Nodes: []*topology.Node{ | ||
{ | ||
Kind: topology.NodeKindServer, | ||
Name: "dc1-server1", | ||
Addresses: []*topology.Address{ | ||
{Network: "dc1"}, | ||
{Network: "wan"}, | ||
}, | ||
}, | ||
{ | ||
Kind: topology.NodeKindClient, | ||
Name: "dc1-client1", | ||
Services: []*topology.Service{ | ||
{ | ||
ID: topology.ServiceID{Name: "mesh-gateway"}, | ||
Port: 8443, | ||
EnvoyAdminPort: 19000, | ||
IsMeshGateway: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Kind: topology.NodeKindClient, | ||
Name: "dc1-client2", | ||
Services: []*topology.Service{ | ||
{ | ||
ID: topology.ServiceID{Name: "ping"}, | ||
Image: "rboyer/pingpong:latest", | ||
Port: 8080, | ||
EnvoyAdminPort: 19000, | ||
Command: []string{ | ||
"-bind", "0.0.0.0:8080", | ||
"-dial", "127.0.0.1:9090", | ||
"-pong-chaos", | ||
"-dialfreq", "250ms", | ||
"-name", "ping", | ||
}, | ||
Upstreams: []*topology.Upstream{{ | ||
ID: topology.ServiceID{Name: "pong"}, | ||
LocalPort: 9090, | ||
Peer: "peer-dc2-default", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
InitialConfigEntries: []api.ConfigEntry{ | ||
&api.ExportedServicesConfigEntry{ | ||
Name: "default", | ||
Services: []api.ExportedService{{ | ||
Name: "ping", | ||
Consumers: []api.ServiceConsumer{{ | ||
Peer: "peer-dc2-default", | ||
}}, | ||
}}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "dc2", | ||
Nodes: []*topology.Node{ | ||
{ | ||
Kind: topology.NodeKindServer, | ||
Name: "dc2-server1", | ||
Addresses: []*topology.Address{ | ||
{Network: "dc2"}, | ||
{Network: "wan"}, | ||
}, | ||
}, | ||
{ | ||
Kind: topology.NodeKindClient, | ||
Name: "dc2-client1", | ||
Services: []*topology.Service{ | ||
{ | ||
ID: topology.ServiceID{Name: "mesh-gateway"}, | ||
Port: 8443, | ||
EnvoyAdminPort: 19000, | ||
IsMeshGateway: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Kind: topology.NodeKindDataplane, | ||
Name: "dc2-client2", | ||
Services: []*topology.Service{ | ||
{ | ||
ID: topology.ServiceID{Name: "pong"}, | ||
Image: "rboyer/pingpong:latest", | ||
Port: 8080, | ||
EnvoyAdminPort: 19000, | ||
Command: []string{ | ||
"-bind", "0.0.0.0:8080", | ||
"-dial", "127.0.0.1:9090", | ||
"-pong-chaos", | ||
"-dialfreq", "250ms", | ||
"-name", "pong", | ||
}, | ||
Upstreams: []*topology.Upstream{{ | ||
ID: topology.ServiceID{Name: "ping"}, | ||
LocalPort: 9090, | ||
Peer: "peer-dc1-default", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
InitialConfigEntries: []api.ConfigEntry{ | ||
&api.ExportedServicesConfigEntry{ | ||
Name: "default", | ||
Services: []api.ExportedService{{ | ||
Name: "ping", | ||
Consumers: []api.ServiceConsumer{{ | ||
Peer: "peer-dc2-default", | ||
}}, | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Peerings: []*topology.Peering{{ | ||
Dialing: topology.PeerCluster{ | ||
Name: "dc1", | ||
}, | ||
Accepting: topology.PeerCluster{ | ||
Name: "dc2", | ||
}, | ||
}}, | ||
} | ||
``` | ||
|
||
Once you have a topology configuration, you simply call the appropriate | ||
`Launch` function to validate and boot the cluster. | ||
|
||
You may also modify your original configuration (in some allowed ways) and call | ||
`Relaunch` on an existing topology which will differentially adjust the running | ||
infrastructure. This can be useful to do things like upgrade instances in place | ||
or subly reconfigure them. | ||
|
||
### For Testing | ||
|
||
It is meant to be consumed primarily by unit tests desiring a complex | ||
reasonably realistic Consul setup. For that use case use the `sprawl/sprawltest` wrapper: | ||
|
||
``` | ||
func TestSomething(t *testing.T) { | ||
cfg := &topology.Config{...} | ||
sp := sprawltest.Launch(t, cfg) | ||
// do stuff with 'sp' | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Missing things that should probably be added; | ||
|
||
- consul-dataplane support for running mesh gateways | ||
- consul-dataplane health check updates (automatic; manual) | ||
- ServerExternalAddresses in a peering; possibly rig up a DNS name for this. | ||
- after creating a token, verify it exists on all servers before proceding (rather than sleep looping on not-founds) | ||
- investigate strange gRPC bug that is currently papered over | ||
- allow services to override their mesh gateway modes | ||
- remove some of the debug prints of various things |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module github.com/hashicorp/consul/testing/deployer | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/google/go-cmp v0.5.9 | ||
github.com/hashicorp/consul/api v1.20.0 | ||
github.com/hashicorp/consul/sdk v0.13.1 | ||
github.com/hashicorp/go-cleanhttp v0.5.2 | ||
github.com/hashicorp/go-hclog v1.5.0 | ||
github.com/hashicorp/go-multierror v1.1.1 | ||
github.com/hashicorp/hcl/v2 v2.16.2 | ||
github.com/mitchellh/copystructure v1.2.0 | ||
github.com/rboyer/safeio v0.2.2 | ||
github.com/stretchr/testify v1.8.2 | ||
golang.org/x/crypto v0.7.0 | ||
) | ||
|
||
require ( | ||
github.com/agext/levenshtein v1.2.1 // indirect | ||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect | ||
github.com/armon/go-metrics v0.3.10 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect | ||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect | ||
github.com/hashicorp/go-uuid v1.0.3 // indirect | ||
github.com/hashicorp/go-version v1.2.1 // indirect | ||
github.com/hashicorp/golang-lru v0.5.4 // indirect | ||
github.com/hashicorp/serf v0.10.1 // indirect | ||
github.com/mattn/go-colorable v0.1.12 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/mitchellh/go-wordwrap v1.0.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/zclconf/go-cty v1.12.1 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/text v0.8.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.