mirror of
https://github.com/status-im/consul.git
synced 2025-02-02 08:56:43 +00:00
4b85aa5a97
This updates the testing/deployer (aka "topology test") framework to allow for a v2-oriented topology to opt services into enabling TransparentProxy. The restrictions are similar to that of #19046 The multiport Ports map that was added in #19046 was changed to allow for the protocol to be specified at this time, but for now the only supported protocol is TCP as only L4 functions currently on main. As part of making transparent proxy work, the DNS server needed a new zonefile for responding to virtual.consul requests, since there is no Kubernetes DNS and the Consul DNS work for v2 has not happened yet. Once Consul DNS supports v2 we should switch over. For now the format of queries is: <service>--<namespace>--<partition>.virtual.consul Additionally: - All transparent proxy enabled services are assigned a virtual ip in the 10.244.0/24 range. This is something Consul will do in v2 at a later date, likely during 1.18. - All services with exposed ports (non-mesh) are assigned a virtual port number for use with tproxy - The consul-dataplane image has been made un-distroless, and gotten the necessary tools to execute consul connect redirect-traffic before running dataplane, thus simulating a kubernetes init container in plain docker.
145 lines
3.1 KiB
Go
145 lines
3.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package topology
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type Images struct {
|
|
// Consul is the image used for creating the container,
|
|
// Use ChooseConsul() to control which image (ConsulCE or ConsulEnterprise) assign to Consul
|
|
Consul string `json:",omitempty"`
|
|
// ConsulCE sets the CE image
|
|
ConsulCE string `json:",omitempty"`
|
|
// ConsulEnterprise sets the ent image
|
|
ConsulEnterprise string `json:",omitempty"`
|
|
Envoy string
|
|
Dataplane string
|
|
}
|
|
|
|
func (i Images) LocalDataplaneImage() string {
|
|
if i.Dataplane == "" {
|
|
return ""
|
|
}
|
|
|
|
img, tag, ok := strings.Cut(i.Dataplane, ":")
|
|
if !ok {
|
|
tag = "latest"
|
|
}
|
|
|
|
repo, name, ok := strings.Cut(img, "/")
|
|
if ok {
|
|
name = repo + "-" + name
|
|
}
|
|
|
|
// ex: local/hashicorp-consul-dataplane:1.1.0
|
|
return "local/" + name + ":" + tag
|
|
}
|
|
|
|
func (i Images) LocalDataplaneTProxyImage() string {
|
|
return spliceImageNamesAndTags(i.Dataplane, i.Consul, "tproxy")
|
|
}
|
|
|
|
func (i Images) EnvoyConsulImage() string {
|
|
return spliceImageNamesAndTags(i.Consul, i.Envoy, "")
|
|
}
|
|
|
|
func spliceImageNamesAndTags(base1, base2, nameSuffix string) string {
|
|
if base1 == "" || base2 == "" {
|
|
return ""
|
|
}
|
|
|
|
img1, tag1, ok1 := strings.Cut(base1, ":")
|
|
img2, tag2, ok2 := strings.Cut(base2, ":")
|
|
if !ok1 {
|
|
tag1 = "latest"
|
|
}
|
|
if !ok2 {
|
|
tag2 = "latest"
|
|
}
|
|
|
|
repo1, name1, ok1 := strings.Cut(img1, "/")
|
|
repo2, name2, ok2 := strings.Cut(img2, "/")
|
|
|
|
if ok1 {
|
|
name1 = repo1 + "-" + name1
|
|
} else {
|
|
name1 = repo1
|
|
}
|
|
if ok2 {
|
|
name2 = repo2 + "-" + name2
|
|
} else {
|
|
name2 = repo2
|
|
}
|
|
|
|
if nameSuffix != "" {
|
|
nameSuffix = "-" + nameSuffix
|
|
}
|
|
|
|
// ex: local/hashicorp-consul-and-envoyproxy-envoy:1.15.0-with-v1.26.2
|
|
return "local/" + name1 + "-and-" + name2 + nameSuffix + ":" + tag1 + "-with-" + tag2
|
|
}
|
|
|
|
// TODO: what is this for and why do we need to do this and why is it named this?
|
|
func (i Images) ChooseNode(kind NodeKind) Images {
|
|
switch kind {
|
|
case NodeKindServer:
|
|
i.Envoy = ""
|
|
i.Dataplane = ""
|
|
case NodeKindClient:
|
|
i.Dataplane = ""
|
|
case NodeKindDataplane:
|
|
i.Envoy = ""
|
|
default:
|
|
// do nothing
|
|
}
|
|
return i
|
|
}
|
|
|
|
// ChooseConsul controls which image assigns to Consul
|
|
func (i Images) ChooseConsul(enterprise bool) Images {
|
|
if enterprise {
|
|
i.Consul = i.ConsulEnterprise
|
|
} else {
|
|
i.Consul = i.ConsulCE
|
|
}
|
|
i.ConsulEnterprise = ""
|
|
i.ConsulCE = ""
|
|
return i
|
|
}
|
|
|
|
func (i Images) OverrideWith(i2 Images) Images {
|
|
if i2.Consul != "" {
|
|
i.Consul = i2.Consul
|
|
}
|
|
if i2.ConsulCE != "" {
|
|
i.ConsulCE = i2.ConsulCE
|
|
}
|
|
if i2.ConsulEnterprise != "" {
|
|
i.ConsulEnterprise = i2.ConsulEnterprise
|
|
}
|
|
if i2.Envoy != "" {
|
|
i.Envoy = i2.Envoy
|
|
}
|
|
if i2.Dataplane != "" {
|
|
i.Dataplane = i2.Dataplane
|
|
}
|
|
return i
|
|
}
|
|
|
|
// DefaultImages controls which specific docker images are used as default
|
|
// values for topology components that do not specify values.
|
|
//
|
|
// These can be bulk-updated using the make target 'make update-defaults'
|
|
func DefaultImages() Images {
|
|
return Images{
|
|
Consul: "",
|
|
ConsulCE: DefaultConsulImage,
|
|
ConsulEnterprise: DefaultConsulEnterpriseImage,
|
|
Envoy: DefaultEnvoyImage,
|
|
Dataplane: DefaultDataplaneImage,
|
|
}
|
|
}
|