Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Add partition identity to envoy deployment #537

Merged
merged 2 commits into from
Mar 21, 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
3 changes: 3 additions & 0 deletions .changelog/537.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Fix envoy deployments not properly identifying themselves when deployed to non-default partitions.
```
5 changes: 5 additions & 0 deletions internal/commands/exec/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (c *Command) Run(args []string) (ret int) {
Host: c.flagGatewayHost,
Name: c.flagGatewayName,
Namespace: c.flagGatewayNamespace,
Partition: getPartition(),
},
EnvoyConfig: EnvoyConfig{
CACertificateFile: cfg.TLSConfig.CAFile,
Expand Down Expand Up @@ -286,3 +287,7 @@ func init() {
}
}
}

func getPartition() string {
return os.Getenv("CONSUL_PARTITION")
}
3 changes: 3 additions & 0 deletions internal/commands/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type GatewayConfig struct {
Host string
Name string
Namespace string
Partition string
}

type EnvoyConfig struct {
Expand Down Expand Up @@ -101,6 +102,7 @@ func RunExec(config ExecConfig) (ret int) {
client,
config.GatewayConfig.Name,
config.GatewayConfig.Namespace,
config.GatewayConfig.Partition,
config.GatewayConfig.Host,
)
if config.isTest {
Expand Down Expand Up @@ -129,6 +131,7 @@ func RunExec(config ExecConfig) (ret int) {
envoy.ManagerConfig{
ID: registry.ID(),
Namespace: registry.Namespace(),
Partition: registry.Partition(),
ConsulCA: config.EnvoyConfig.CACertificateFile,
ConsulAddress: config.EnvoyConfig.XDSAddress,
ConsulXDSPort: config.EnvoyConfig.XDSPort,
Expand Down
10 changes: 9 additions & 1 deletion internal/consul/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ServiceRegistry struct {
id string
name string
namespace string
partition string
host string
tags []string

Expand All @@ -45,13 +46,14 @@ type ServiceRegistry struct {
}

// NewServiceRegistry creates a new service registry instance
func NewServiceRegistry(logger hclog.Logger, client Client, service, namespace, host string) *ServiceRegistry {
func NewServiceRegistry(logger hclog.Logger, client Client, service, namespace, partition, host string) *ServiceRegistry {
return &ServiceRegistry{
logger: logger,
client: client,
id: uuid.New().String(),
name: service,
namespace: namespace,
partition: partition,
host: host,
tries: defaultMaxAttempts,
backoffInterval: defaultBackoffInterval,
Expand Down Expand Up @@ -94,6 +96,7 @@ func (s *ServiceRegistry) RegisterGateway(ctx context.Context, ttl bool) error {
ID: s.id,
Name: s.name,
Namespace: s.namespace,
Partition: s.partition,
Address: s.host,
Tags: s.tags,
Meta: map[string]string{
Expand All @@ -110,6 +113,7 @@ func (s *ServiceRegistry) Register(ctx context.Context) error {
ID: s.id,
Name: s.name,
Namespace: s.namespace,
Partition: s.partition,
Address: s.host,
Tags: s.tags,
Checks: api.AgentServiceChecks{{
Expand Down Expand Up @@ -231,3 +235,7 @@ func (s *ServiceRegistry) ID() string {
func (s *ServiceRegistry) Namespace() string {
return s.namespace
}

func (s *ServiceRegistry) Partition() string {
return s.partition
}
4 changes: 2 additions & 2 deletions internal/consul/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestRegister(t *testing.T) {
}

server := runRegistryServer(t, test.failures, id)
registry := NewServiceRegistry(hclog.NewNullLogger(), NewTestClient(server.consul), service, namespace, test.host).WithTries(maxAttempts)
registry := NewServiceRegistry(hclog.NewNullLogger(), NewTestClient(server.consul), service, namespace, "", test.host).WithTries(maxAttempts)

registry.backoffInterval = 0
registry.id = id
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestDeregister(t *testing.T) {
}

server := runRegistryServer(t, test.failures, id)
registry := NewServiceRegistry(hclog.NewNullLogger(), NewTestClient(server.consul), service, "", "").WithTries(maxAttempts)
registry := NewServiceRegistry(hclog.NewNullLogger(), NewTestClient(server.consul), service, "", "", "").WithTries(maxAttempts)
registry.backoffInterval = 0
registry.id = id
err := registry.Deregister(context.Background())
Expand Down
6 changes: 5 additions & 1 deletion internal/envoy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
type bootstrapArgs struct {
ID string
Namespace string
Partition string
ConsulCA string
ConsulAddress string
ConsulXDSPort int
Expand All @@ -48,6 +49,7 @@ func init() {
type ManagerConfig struct {
ID string
Namespace string
Partition string
ConsulCA string
ConsulAddress string
ConsulXDSPort int
Expand Down Expand Up @@ -117,6 +119,7 @@ func (m *Manager) RenderBootstrap(sdsConfig string) error {
SDSCluster: sdsConfig,
ID: m.ID,
Namespace: m.Namespace,
Partition: m.Partition,
ConsulCA: m.ConsulCA,
ConsulAddress: m.ConsulAddress,
ConsulXDSPort: m.ConsulXDSPort,
Expand Down Expand Up @@ -144,7 +147,8 @@ const bootstrapJSONTemplate = `{
"cluster": "{{ .ID }}",
"id": "{{ .ID }}",
"metadata": {
"namespace": "{{if ne .Namespace ""}}{{ .Namespace }}{{else}}default{{end}}"
"namespace": "{{if ne .Namespace ""}}{{ .Namespace }}{{else}}default{{end}}",
"partition": "{{if ne .Partition ""}}{{ .Partition }}{{else}}default{{end}}"
}
},
"static_resources": {
Expand Down
3 changes: 2 additions & 1 deletion internal/envoy/testdata/basic.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"cluster": "6f164d52-7846-45d1-97b1-fc984795572b",
"id": "6f164d52-7846-45d1-97b1-fc984795572b",
"metadata": {
"namespace": "default"
"namespace": "default",
"partition": "default"
}
},
"static_resources": {
Expand Down
3 changes: 2 additions & 1 deletion internal/envoy/testdata/empty.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"cluster": "",
"id": "",
"metadata": {
"namespace": "default"
"namespace": "default",
"partition": "default"
}
},
"static_resources": {
Expand Down
3 changes: 2 additions & 1 deletion internal/envoy/testdata/sds.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"cluster": "",
"id": "",
"metadata": {
"namespace": "default"
"namespace": "default",
"partition": "default"
}
},
"static_resources": {
Expand Down
3 changes: 2 additions & 1 deletion internal/envoy/testdata/tls.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"cluster": "feaf6c11-f46f-4869-ba53-b0cc07f09659",
"id": "feaf6c11-f46f-4869-ba53-b0cc07f09659",
"metadata": {
"namespace": "default"
"namespace": "default",
"partition": "default"
}
},
"static_resources": {
Expand Down