2023-11-02 19:25:48 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
package topoutil
|
|
|
|
|
|
|
|
import (
|
2023-11-08 23:20:00 +00:00
|
|
|
"fmt"
|
2023-11-02 19:25:48 +00:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/testing/deployer/topology"
|
|
|
|
)
|
|
|
|
|
|
|
|
const HashicorpDockerProxy = "docker.mirror.hashicorp.services"
|
|
|
|
|
2023-11-10 19:22:06 +00:00
|
|
|
func NewFortioWorkloadWithDefaults(
|
2023-11-02 19:25:48 +00:00
|
|
|
cluster string,
|
2023-11-10 19:22:06 +00:00
|
|
|
sid topology.ID,
|
|
|
|
mut func(*topology.Workload),
|
|
|
|
) *topology.Workload {
|
2023-11-02 19:25:48 +00:00
|
|
|
const (
|
|
|
|
httpPort = 8080
|
|
|
|
grpcPort = 8079
|
2023-11-08 23:20:00 +00:00
|
|
|
tcpPort = 8078
|
2023-11-02 19:25:48 +00:00
|
|
|
adminPort = 19000
|
|
|
|
)
|
|
|
|
sid.Normalize()
|
|
|
|
|
2023-11-10 19:22:06 +00:00
|
|
|
wrk := &topology.Workload{
|
2023-11-02 19:25:48 +00:00
|
|
|
ID: sid,
|
|
|
|
Image: HashicorpDockerProxy + "/fortio/fortio",
|
|
|
|
EnvoyAdminPort: adminPort,
|
2024-05-07 15:24:50 +00:00
|
|
|
Port: httpPort,
|
2023-11-02 19:25:48 +00:00
|
|
|
CheckTCP: "127.0.0.1:" + strconv.Itoa(httpPort),
|
|
|
|
Env: []string{
|
|
|
|
"FORTIO_NAME=" + cluster + "::" + sid.String(),
|
|
|
|
},
|
|
|
|
Command: []string{
|
|
|
|
"server",
|
|
|
|
"-http-port", strconv.Itoa(httpPort),
|
|
|
|
"-grpc-port", strconv.Itoa(grpcPort),
|
2023-11-08 23:20:00 +00:00
|
|
|
"-tcp-port", strconv.Itoa(tcpPort),
|
2023-11-02 19:25:48 +00:00
|
|
|
"-redirect-port", "-disabled",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-11-08 23:20:00 +00:00
|
|
|
if mut != nil {
|
2023-11-10 19:22:06 +00:00
|
|
|
mut(wrk)
|
2023-11-08 23:20:00 +00:00
|
|
|
}
|
2023-11-10 19:22:06 +00:00
|
|
|
return wrk
|
2023-11-08 23:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 19:22:06 +00:00
|
|
|
func NewBlankspaceWorkloadWithDefaults(
|
2023-11-08 23:20:00 +00:00
|
|
|
cluster string,
|
2023-11-10 19:22:06 +00:00
|
|
|
sid topology.ID,
|
|
|
|
mut func(*topology.Workload),
|
|
|
|
) *topology.Workload {
|
2023-11-08 23:20:00 +00:00
|
|
|
const (
|
|
|
|
httpPort = 8080
|
|
|
|
grpcPort = 8079
|
|
|
|
tcpPort = 8078
|
|
|
|
adminPort = 19000
|
|
|
|
)
|
|
|
|
sid.Normalize()
|
|
|
|
|
2023-11-10 19:22:06 +00:00
|
|
|
wrk := &topology.Workload{
|
2023-11-08 23:20:00 +00:00
|
|
|
ID: sid,
|
|
|
|
Image: HashicorpDockerProxy + "/rboyer/blankspace",
|
|
|
|
EnvoyAdminPort: adminPort,
|
2024-05-07 15:24:50 +00:00
|
|
|
Port: httpPort,
|
2023-11-08 23:20:00 +00:00
|
|
|
CheckTCP: "127.0.0.1:" + strconv.Itoa(httpPort),
|
|
|
|
Command: []string{
|
|
|
|
"-name", cluster + "::" + sid.String(),
|
|
|
|
"-http-addr", fmt.Sprintf(":%d", httpPort),
|
|
|
|
"-grpc-addr", fmt.Sprintf(":%d", grpcPort),
|
|
|
|
"-tcp-addr", fmt.Sprintf(":%d", tcpPort),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-11-02 19:25:48 +00:00
|
|
|
if mut != nil {
|
2023-11-10 19:22:06 +00:00
|
|
|
mut(wrk)
|
2023-11-02 19:25:48 +00:00
|
|
|
}
|
2023-11-10 19:22:06 +00:00
|
|
|
return wrk
|
2023-11-02 19:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTopologyServerSet(
|
|
|
|
namePrefix string,
|
|
|
|
num int,
|
|
|
|
networks []string,
|
|
|
|
mutateFn func(i int, node *topology.Node),
|
|
|
|
) []*topology.Node {
|
|
|
|
var out []*topology.Node
|
|
|
|
for i := 1; i <= num; i++ {
|
|
|
|
name := namePrefix + strconv.Itoa(i)
|
|
|
|
|
|
|
|
node := &topology.Node{
|
|
|
|
Kind: topology.NodeKindServer,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
for _, net := range networks {
|
|
|
|
node.Addresses = append(node.Addresses, &topology.Address{Network: net})
|
|
|
|
}
|
|
|
|
|
|
|
|
if mutateFn != nil {
|
|
|
|
mutateFn(i, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, node)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTopologyMeshGatewaySet(
|
|
|
|
nodeKind topology.NodeKind,
|
|
|
|
partition string,
|
|
|
|
namePrefix string,
|
|
|
|
num int,
|
|
|
|
networks []string,
|
|
|
|
mutateFn func(i int, node *topology.Node),
|
|
|
|
) []*topology.Node {
|
|
|
|
var out []*topology.Node
|
2023-11-10 19:22:06 +00:00
|
|
|
sid := topology.ID{
|
2023-11-03 16:43:43 +00:00
|
|
|
Name: "mesh-gateway",
|
2023-11-10 19:22:06 +00:00
|
|
|
Partition: topology.DefaultToEmpty(partition),
|
2023-11-03 16:43:43 +00:00
|
|
|
}
|
2023-11-02 19:25:48 +00:00
|
|
|
for i := 1; i <= num; i++ {
|
|
|
|
name := namePrefix + strconv.Itoa(i)
|
|
|
|
|
|
|
|
node := &topology.Node{
|
|
|
|
Kind: nodeKind,
|
2023-11-07 16:11:42 +00:00
|
|
|
Partition: sid.Partition,
|
2023-11-02 19:25:48 +00:00
|
|
|
Name: name,
|
2023-11-10 19:22:06 +00:00
|
|
|
Workloads: []*topology.Workload{{
|
2023-11-03 16:43:43 +00:00
|
|
|
ID: sid,
|
2023-11-02 19:25:48 +00:00
|
|
|
Port: 8443,
|
|
|
|
EnvoyAdminPort: 19000,
|
|
|
|
IsMeshGateway: true,
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
for _, net := range networks {
|
|
|
|
node.Addresses = append(node.Addresses, &topology.Address{Network: net})
|
|
|
|
}
|
|
|
|
|
|
|
|
if mutateFn != nil {
|
|
|
|
mutateFn(i, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, node)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
2023-11-03 16:43:43 +00:00
|
|
|
|
|
|
|
// Since CE config entries do not contain the partition field,
|
|
|
|
// this func converts default partition to empty string.
|
|
|
|
func ConfigEntryPartition(p string) string {
|
|
|
|
if p == "default" {
|
|
|
|
return "" // make this CE friendly
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|