mirror of https://github.com/status-im/consul.git
Rename service-exports to partition-exports
Existing config entries prefixed by service- are specific to individual services. Since this config entry applies to partitions it is being renamed. Additionally, the Partition label was changed to Name because using Partition at the top-level and in the enterprise meta was leading to the enterprise meta partition being dropped by msgpack.
This commit is contained in:
parent
4ae2c8de9d
commit
5c24ed61a8
|
@ -360,7 +360,7 @@ func validateProposedConfigEntryInGraph(
|
|||
}
|
||||
case structs.ServiceIntentions:
|
||||
case structs.MeshConfig:
|
||||
case structs.ServiceExports:
|
||||
case structs.PartitionExports:
|
||||
default:
|
||||
return fmt.Errorf("unhandled kind %q during validation of %q", kindName.Kind, kindName.Name)
|
||||
}
|
||||
|
|
|
@ -177,12 +177,12 @@ func TestUsageReporter_emitNodeUsage_OSS(t *testing.T) {
|
|||
{Name: "kind", Value: "terminating-gateway"},
|
||||
},
|
||||
},
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=service-exports": {
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=partition-exports": {
|
||||
Name: "consul.usage.test.consul.state.config_entries",
|
||||
Value: 0,
|
||||
Labels: []metrics.Label{
|
||||
{Name: "datacenter", Value: "dc1"},
|
||||
{Name: "kind", Value: "service-exports"},
|
||||
{Name: "kind", Value: "partition-exports"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -362,12 +362,12 @@ func TestUsageReporter_emitNodeUsage_OSS(t *testing.T) {
|
|||
{Name: "kind", Value: "terminating-gateway"},
|
||||
},
|
||||
},
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=service-exports": {
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=partition-exports": {
|
||||
Name: "consul.usage.test.consul.state.config_entries",
|
||||
Value: 0,
|
||||
Labels: []metrics.Label{
|
||||
{Name: "datacenter", Value: "dc1"},
|
||||
{Name: "kind", Value: "service-exports"},
|
||||
{Name: "kind", Value: "partition-exports"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -575,12 +575,12 @@ func TestUsageReporter_emitServiceUsage_OSS(t *testing.T) {
|
|||
{Name: "kind", Value: "terminating-gateway"},
|
||||
},
|
||||
},
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=service-exports": {
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=partition-exports": {
|
||||
Name: "consul.usage.test.consul.state.config_entries",
|
||||
Value: 0,
|
||||
Labels: []metrics.Label{
|
||||
{Name: "datacenter", Value: "dc1"},
|
||||
{Name: "kind", Value: "service-exports"},
|
||||
{Name: "kind", Value: "partition-exports"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -802,12 +802,12 @@ func TestUsageReporter_emitServiceUsage_OSS(t *testing.T) {
|
|||
{Name: "kind", Value: "terminating-gateway"},
|
||||
},
|
||||
},
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=service-exports": {
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=partition-exports": {
|
||||
Name: "consul.usage.test.consul.state.config_entries",
|
||||
Value: 0,
|
||||
Labels: []metrics.Label{
|
||||
{Name: "datacenter", Value: "dc1"},
|
||||
{Name: "kind", Value: "service-exports"},
|
||||
{Name: "kind", Value: "partition-exports"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1006,12 +1006,12 @@ func TestUsageReporter_emitKVUsage_OSS(t *testing.T) {
|
|||
{Name: "kind", Value: "terminating-gateway"},
|
||||
},
|
||||
},
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=service-exports": {
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=partition-exports": {
|
||||
Name: "consul.usage.test.consul.state.config_entries",
|
||||
Value: 0,
|
||||
Labels: []metrics.Label{
|
||||
{Name: "datacenter", Value: "dc1"},
|
||||
{Name: "kind", Value: "service-exports"},
|
||||
{Name: "kind", Value: "partition-exports"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1200,12 +1200,12 @@ func TestUsageReporter_emitKVUsage_OSS(t *testing.T) {
|
|||
{Name: "kind", Value: "terminating-gateway"},
|
||||
},
|
||||
},
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=service-exports": {
|
||||
"consul.usage.test.consul.state.config_entries;datacenter=dc1;kind=partition-exports": {
|
||||
Name: "consul.usage.test.consul.state.config_entries",
|
||||
Value: 0,
|
||||
Labels: []metrics.Label{
|
||||
{Name: "datacenter", Value: "dc1"},
|
||||
{Name: "kind", Value: "service-exports"},
|
||||
{Name: "kind", Value: "partition-exports"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -27,7 +27,7 @@ const (
|
|||
TerminatingGateway string = "terminating-gateway"
|
||||
ServiceIntentions string = "service-intentions"
|
||||
MeshConfig string = "mesh"
|
||||
ServiceExports string = "service-exports"
|
||||
PartitionExports string = "partition-exports"
|
||||
|
||||
ProxyConfigGlobal string = "global"
|
||||
MeshConfigMesh string = "mesh"
|
||||
|
@ -45,7 +45,7 @@ var AllConfigEntryKinds = []string{
|
|||
TerminatingGateway,
|
||||
ServiceIntentions,
|
||||
MeshConfig,
|
||||
ServiceExports,
|
||||
PartitionExports,
|
||||
}
|
||||
|
||||
// ConfigEntry is the interface for centralized configuration stored in Raft.
|
||||
|
@ -532,8 +532,8 @@ func MakeConfigEntry(kind, name string) (ConfigEntry, error) {
|
|||
return &ServiceIntentionsConfigEntry{Name: name}, nil
|
||||
case MeshConfig:
|
||||
return &MeshConfigEntry{}, nil
|
||||
case ServiceExports:
|
||||
return &ServiceExportsConfigEntry{Partition: name}, nil
|
||||
case PartitionExports:
|
||||
return &PartitionExportsConfigEntry{Name: name}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid config entry kind: %s", kind)
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ import (
|
|||
"github.com/hashicorp/consul/acl"
|
||||
)
|
||||
|
||||
// ServiceExportsConfigEntry is the top-level struct for exporting a service to be exposed
|
||||
// PartitionExportsConfigEntry is the top-level struct for exporting a service to be exposed
|
||||
// across other admin partitions.
|
||||
type ServiceExportsConfigEntry struct {
|
||||
Partition string
|
||||
type PartitionExportsConfigEntry struct {
|
||||
Name string
|
||||
|
||||
// Services is a list of services to be exported and the list of partitions
|
||||
// to expose them to.
|
||||
|
@ -39,7 +39,7 @@ type ServiceConsumer struct {
|
|||
Partition string
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) Clone() *ServiceExportsConfigEntry {
|
||||
func (e *PartitionExportsConfigEntry) Clone() *PartitionExportsConfigEntry {
|
||||
e2 := *e
|
||||
e2.Services = make([]ExportedService, len(e.Services))
|
||||
for _, svc := range e.Services {
|
||||
|
@ -54,32 +54,30 @@ func (e *ServiceExportsConfigEntry) Clone() *ServiceExportsConfigEntry {
|
|||
return &e2
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) GetKind() string {
|
||||
return ServiceExports
|
||||
func (e *PartitionExportsConfigEntry) GetKind() string {
|
||||
return PartitionExports
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) GetName() string {
|
||||
func (e *PartitionExportsConfigEntry) GetName() string {
|
||||
if e == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return e.Partition
|
||||
return e.Name
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) GetMeta() map[string]string {
|
||||
func (e *PartitionExportsConfigEntry) GetMeta() map[string]string {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
return e.Meta
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) Normalize() error {
|
||||
func (e *PartitionExportsConfigEntry) Normalize() error {
|
||||
if e == nil {
|
||||
return fmt.Errorf("config entry is nil")
|
||||
}
|
||||
|
||||
meta := DefaultEnterpriseMetaInPartition(e.Partition)
|
||||
e.EnterpriseMeta.Merge(meta)
|
||||
e.EnterpriseMeta = *DefaultEnterpriseMetaInPartition(e.Name)
|
||||
e.EnterpriseMeta.Normalize()
|
||||
|
||||
for i := range e.Services {
|
||||
|
@ -89,12 +87,12 @@ func (e *ServiceExportsConfigEntry) Normalize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) Validate() error {
|
||||
if e.Partition == "" {
|
||||
return fmt.Errorf("Partition is required")
|
||||
func (e *PartitionExportsConfigEntry) Validate() error {
|
||||
if e.Name == "" {
|
||||
return fmt.Errorf("Name is required")
|
||||
}
|
||||
if e.Partition == WildcardSpecifier {
|
||||
return fmt.Errorf("service-exports Partition must be the name of a partition, and not a wildcard")
|
||||
if e.Name == WildcardSpecifier {
|
||||
return fmt.Errorf("partition-exports Name must be the name of a partition, and not a wildcard")
|
||||
}
|
||||
|
||||
validationErr := validateConfigEntryMeta(e.Meta)
|
||||
|
@ -116,19 +114,19 @@ func (e *ServiceExportsConfigEntry) Validate() error {
|
|||
return validationErr
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) CanRead(authz acl.Authorizer) bool {
|
||||
func (e *PartitionExportsConfigEntry) CanRead(authz acl.Authorizer) bool {
|
||||
var authzContext acl.AuthorizerContext
|
||||
e.FillAuthzContext(&authzContext)
|
||||
return authz.MeshRead(&authzContext) == acl.Allow
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) CanWrite(authz acl.Authorizer) bool {
|
||||
func (e *PartitionExportsConfigEntry) CanWrite(authz acl.Authorizer) bool {
|
||||
var authzContext acl.AuthorizerContext
|
||||
e.FillAuthzContext(&authzContext)
|
||||
return authz.MeshWrite(&authzContext) == acl.Allow
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) GetRaftIndex() *RaftIndex {
|
||||
func (e *PartitionExportsConfigEntry) GetRaftIndex() *RaftIndex {
|
||||
if e == nil {
|
||||
return &RaftIndex{}
|
||||
}
|
||||
|
@ -136,7 +134,7 @@ func (e *ServiceExportsConfigEntry) GetRaftIndex() *RaftIndex {
|
|||
return &e.RaftIndex
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) GetEnterpriseMeta() *EnterpriseMeta {
|
||||
func (e *PartitionExportsConfigEntry) GetEnterpriseMeta() *EnterpriseMeta {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1665,9 +1665,9 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "service-exports",
|
||||
name: "partition-exports",
|
||||
snake: `
|
||||
kind = "service-exports"
|
||||
kind = "partition-exports"
|
||||
partition = "foo"
|
||||
meta {
|
||||
"foo" = "bar"
|
||||
|
@ -1698,7 +1698,7 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
]
|
||||
`,
|
||||
camel: `
|
||||
Kind = "service-exports"
|
||||
Kind = "partition-exports"
|
||||
Partition = "foo"
|
||||
Meta {
|
||||
"foo" = "bar"
|
||||
|
@ -1728,8 +1728,7 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
}
|
||||
]
|
||||
`,
|
||||
expect: &ServiceExportsConfigEntry{
|
||||
Partition: "foo",
|
||||
expect: &PartitionExportsConfigEntry{
|
||||
Meta: map[string]string{
|
||||
"foo": "bar",
|
||||
"gir": "zim",
|
||||
|
|
|
@ -22,7 +22,7 @@ const (
|
|||
TerminatingGateway string = "terminating-gateway"
|
||||
ServiceIntentions string = "service-intentions"
|
||||
MeshConfig string = "mesh"
|
||||
ServiceExports string = "service-exports"
|
||||
PartitionExports string = "partition-exports"
|
||||
|
||||
ProxyConfigGlobal string = "global"
|
||||
MeshConfigMesh string = "mesh"
|
||||
|
@ -277,8 +277,8 @@ func makeConfigEntry(kind, name string) (ConfigEntry, error) {
|
|||
return &ServiceIntentionsConfigEntry{Kind: kind, Name: name}, nil
|
||||
case MeshConfig:
|
||||
return &MeshConfigEntry{}, nil
|
||||
case ServiceExports:
|
||||
return &ServiceExportsConfigEntry{Partition: name}, nil
|
||||
case PartitionExports:
|
||||
return &PartitionExportsConfigEntry{Name: name}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid config entry kind: %s", kind)
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@ package api
|
|||
|
||||
import "encoding/json"
|
||||
|
||||
// ServiceExportsConfigEntry manages the exported services for a single admin partition.
|
||||
// PartitionExportsConfigEntry manages the exported services for a single admin partition.
|
||||
// Admin Partitions are a Consul Enterprise feature.
|
||||
type ServiceExportsConfigEntry struct {
|
||||
// Partition is the partition the ServiceExportsConfigEntry applies to.
|
||||
type PartitionExportsConfigEntry struct {
|
||||
// Name is the name of the partition the PartitionExportsConfigEntry applies to.
|
||||
// Partitioning is a Consul Enterprise feature.
|
||||
Name string `json:",omitempty"`
|
||||
|
||||
// Partition is the partition where the PartitionExportsConfigEntry is stored.
|
||||
// If the partition does not match the name, the name will overwrite the partition.
|
||||
// Partitioning is a Consul Enterprise feature.
|
||||
Partition string `json:",omitempty"`
|
||||
|
||||
|
@ -44,23 +49,23 @@ type ServiceConsumer struct {
|
|||
Partition string
|
||||
}
|
||||
|
||||
func (e *ServiceExportsConfigEntry) GetKind() string { return ServiceExports }
|
||||
func (e *ServiceExportsConfigEntry) GetName() string { return e.Partition }
|
||||
func (e *ServiceExportsConfigEntry) GetPartition() string { return e.Partition }
|
||||
func (e *ServiceExportsConfigEntry) GetNamespace() string { return IntentionDefaultNamespace }
|
||||
func (e *ServiceExportsConfigEntry) GetMeta() map[string]string { return e.Meta }
|
||||
func (e *ServiceExportsConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
||||
func (e *ServiceExportsConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
||||
func (e *PartitionExportsConfigEntry) GetKind() string { return PartitionExports }
|
||||
func (e *PartitionExportsConfigEntry) GetName() string { return e.Name }
|
||||
func (e *PartitionExportsConfigEntry) GetPartition() string { return e.Name }
|
||||
func (e *PartitionExportsConfigEntry) GetNamespace() string { return IntentionDefaultNamespace }
|
||||
func (e *PartitionExportsConfigEntry) GetMeta() map[string]string { return e.Meta }
|
||||
func (e *PartitionExportsConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
||||
func (e *PartitionExportsConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
||||
|
||||
// MarshalJSON adds the Kind field so that the JSON can be decoded back into the
|
||||
// correct type.
|
||||
func (e *ServiceExportsConfigEntry) MarshalJSON() ([]byte, error) {
|
||||
type Alias ServiceExportsConfigEntry
|
||||
func (e *PartitionExportsConfigEntry) MarshalJSON() ([]byte, error) {
|
||||
type Alias PartitionExportsConfigEntry
|
||||
source := &struct {
|
||||
Kind string
|
||||
*Alias
|
||||
}{
|
||||
Kind: ServiceExports,
|
||||
Kind: PartitionExports,
|
||||
Alias: (*Alias)(e),
|
||||
}
|
||||
return json.Marshal(source)
|
||||
|
|
|
@ -2722,10 +2722,10 @@ func TestParseConfigEntry(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "service-exports",
|
||||
name: "partition-exports",
|
||||
snake: `
|
||||
kind = "service-exports"
|
||||
partition = "foo"
|
||||
kind = "partition-exports"
|
||||
name = "foo"
|
||||
meta {
|
||||
"foo" = "bar"
|
||||
"gir" = "zim"
|
||||
|
@ -2755,8 +2755,8 @@ func TestParseConfigEntry(t *testing.T) {
|
|||
]
|
||||
`,
|
||||
camel: `
|
||||
Kind = "service-exports"
|
||||
Partition = "foo"
|
||||
Kind = "partition-exports"
|
||||
Name = "foo"
|
||||
Meta {
|
||||
"foo" = "bar"
|
||||
"gir" = "zim"
|
||||
|
@ -2787,8 +2787,8 @@ func TestParseConfigEntry(t *testing.T) {
|
|||
`,
|
||||
snakeJSON: `
|
||||
{
|
||||
"kind": "service-exports",
|
||||
"partition": "foo",
|
||||
"kind": "partition-exports",
|
||||
"name": "foo",
|
||||
"meta": {
|
||||
"foo": "bar",
|
||||
"gir": "zim"
|
||||
|
@ -2820,8 +2820,8 @@ func TestParseConfigEntry(t *testing.T) {
|
|||
`,
|
||||
camelJSON: `
|
||||
{
|
||||
"Kind": "service-exports",
|
||||
"Partition": "foo",
|
||||
"Kind": "partition-exports",
|
||||
"Name": "foo",
|
||||
"Meta": {
|
||||
"foo": "bar",
|
||||
"gir": "zim"
|
||||
|
@ -2851,8 +2851,8 @@ func TestParseConfigEntry(t *testing.T) {
|
|||
]
|
||||
}
|
||||
`,
|
||||
expect: &api.ServiceExportsConfigEntry{
|
||||
Partition: "foo",
|
||||
expect: &api.PartitionExportsConfigEntry{
|
||||
Name: "foo",
|
||||
Meta: map[string]string{
|
||||
"foo": "bar",
|
||||
"gir": "zim",
|
||||
|
|
Loading…
Reference in New Issue