mirror of https://github.com/status-im/consul.git
Merge pull request #9863 from hashicorp/dnephin/config-entry-kind-name
state: move ConfigEntryKindName
This commit is contained in:
commit
bd6332ae25
|
@ -6,12 +6,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/agent/consul/state"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
tokenStore "github.com/hashicorp/consul/agent/token"
|
tokenStore "github.com/hashicorp/consul/agent/token"
|
||||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||||
"github.com/hashicorp/consul/testrpc"
|
"github.com/hashicorp/consul/testrpc"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLeader_ReplicateIntentions(t *testing.T) {
|
func TestLeader_ReplicateIntentions(t *testing.T) {
|
||||||
|
@ -543,17 +545,17 @@ func TestLeader_LegacyIntentionMigration(t *testing.T) {
|
||||||
checkIntentions(t, s1, true, map[string]*structs.Intention{})
|
checkIntentions(t, s1, true, map[string]*structs.Intention{})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mapifyConfigs := func(entries interface{}) map[structs.ConfigEntryKindName]*structs.ServiceIntentionsConfigEntry {
|
mapifyConfigs := func(entries interface{}) map[state.ConfigEntryKindName]*structs.ServiceIntentionsConfigEntry {
|
||||||
m := make(map[structs.ConfigEntryKindName]*structs.ServiceIntentionsConfigEntry)
|
m := make(map[state.ConfigEntryKindName]*structs.ServiceIntentionsConfigEntry)
|
||||||
switch v := entries.(type) {
|
switch v := entries.(type) {
|
||||||
case []*structs.ServiceIntentionsConfigEntry:
|
case []*structs.ServiceIntentionsConfigEntry:
|
||||||
for _, entry := range v {
|
for _, entry := range v {
|
||||||
kn := structs.NewConfigEntryKindName(entry.Kind, entry.Name, &entry.EnterpriseMeta)
|
kn := state.NewConfigEntryKindName(entry.Kind, entry.Name, &entry.EnterpriseMeta)
|
||||||
m[kn] = entry
|
m[kn] = entry
|
||||||
}
|
}
|
||||||
case []structs.ConfigEntry:
|
case []structs.ConfigEntry:
|
||||||
for _, entry := range v {
|
for _, entry := range v {
|
||||||
kn := structs.NewConfigEntryKindName(entry.GetKind(), entry.GetName(), entry.GetEnterpriseMeta())
|
kn := state.NewConfigEntryKindName(entry.GetKind(), entry.GetName(), entry.GetEnterpriseMeta())
|
||||||
m[kn] = entry.(*structs.ServiceIntentionsConfigEntry)
|
m[kn] = entry.(*structs.ServiceIntentionsConfigEntry)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -629,8 +629,8 @@ func validateProposedConfigEntryInServiceGraph(
|
||||||
checkChains[sn.ToServiceID()] = struct{}{}
|
checkChains[sn.ToServiceID()] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
overrides := map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides := map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(kind, name, entMeta): proposedEntry,
|
NewConfigEntryKindName(kind, name, entMeta): proposedEntry,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -709,7 +709,7 @@ func validateProposedConfigEntryInServiceGraph(
|
||||||
func testCompileDiscoveryChain(
|
func testCompileDiscoveryChain(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
chainName string,
|
chainName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (string, *structs.DiscoveryGraphNode, error) {
|
) (string, *structs.DiscoveryGraphNode, error) {
|
||||||
_, speculativeEntries, err := readDiscoveryChainConfigEntriesTxn(tx, nil, chainName, overrides, entMeta)
|
_, speculativeEntries, err := readDiscoveryChainConfigEntriesTxn(tx, nil, chainName, overrides, entMeta)
|
||||||
|
@ -815,7 +815,7 @@ func (s *Store) ReadDiscoveryChainConfigEntries(
|
||||||
func (s *Store) readDiscoveryChainConfigEntries(
|
func (s *Store) readDiscoveryChainConfigEntries(
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.DiscoveryChainConfigEntries, error) {
|
) (uint64, *structs.DiscoveryChainConfigEntries, error) {
|
||||||
tx := s.db.Txn(false)
|
tx := s.db.Txn(false)
|
||||||
|
@ -827,7 +827,7 @@ func readDiscoveryChainConfigEntriesTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.DiscoveryChainConfigEntries, error) {
|
) (uint64, *structs.DiscoveryChainConfigEntries, error) {
|
||||||
res := structs.NewDiscoveryChainConfigEntries()
|
res := structs.NewDiscoveryChainConfigEntries()
|
||||||
|
@ -1016,7 +1016,7 @@ func getProxyConfigEntryTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
name string,
|
name string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.ProxyConfigEntry, error) {
|
) (uint64, *structs.ProxyConfigEntry, error) {
|
||||||
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ProxyDefaults, name, overrides, entMeta)
|
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ProxyDefaults, name, overrides, entMeta)
|
||||||
|
@ -1041,7 +1041,7 @@ func getServiceConfigEntryTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.ServiceConfigEntry, error) {
|
) (uint64, *structs.ServiceConfigEntry, error) {
|
||||||
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceDefaults, serviceName, overrides, entMeta)
|
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceDefaults, serviceName, overrides, entMeta)
|
||||||
|
@ -1066,7 +1066,7 @@ func getRouterConfigEntryTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.ServiceRouterConfigEntry, error) {
|
) (uint64, *structs.ServiceRouterConfigEntry, error) {
|
||||||
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceRouter, serviceName, overrides, entMeta)
|
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceRouter, serviceName, overrides, entMeta)
|
||||||
|
@ -1091,7 +1091,7 @@ func getSplitterConfigEntryTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.ServiceSplitterConfigEntry, error) {
|
) (uint64, *structs.ServiceSplitterConfigEntry, error) {
|
||||||
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceSplitter, serviceName, overrides, entMeta)
|
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceSplitter, serviceName, overrides, entMeta)
|
||||||
|
@ -1116,7 +1116,7 @@ func getResolverConfigEntryTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.ServiceResolverConfigEntry, error) {
|
) (uint64, *structs.ServiceResolverConfigEntry, error) {
|
||||||
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceResolver, serviceName, overrides, entMeta)
|
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceResolver, serviceName, overrides, entMeta)
|
||||||
|
@ -1141,7 +1141,7 @@ func getServiceIntentionsConfigEntryTxn(
|
||||||
tx ReadTxn,
|
tx ReadTxn,
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
name string,
|
name string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, *structs.ServiceIntentionsConfigEntry, error) {
|
) (uint64, *structs.ServiceIntentionsConfigEntry, error) {
|
||||||
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceIntentions, name, overrides, entMeta)
|
idx, entry, err := configEntryWithOverridesTxn(tx, ws, structs.ServiceIntentions, name, overrides, entMeta)
|
||||||
|
@ -1163,11 +1163,11 @@ func configEntryWithOverridesTxn(
|
||||||
ws memdb.WatchSet,
|
ws memdb.WatchSet,
|
||||||
kind string,
|
kind string,
|
||||||
name string,
|
name string,
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry,
|
overrides map[ConfigEntryKindName]structs.ConfigEntry,
|
||||||
entMeta *structs.EnterpriseMeta,
|
entMeta *structs.EnterpriseMeta,
|
||||||
) (uint64, structs.ConfigEntry, error) {
|
) (uint64, structs.ConfigEntry, error) {
|
||||||
if len(overrides) > 0 {
|
if len(overrides) > 0 {
|
||||||
kn := structs.NewConfigEntryKindName(kind, name, entMeta)
|
kn := NewConfigEntryKindName(kind, name, entMeta)
|
||||||
entry, ok := overrides[kn]
|
entry, ok := overrides[kn]
|
||||||
if ok {
|
if ok {
|
||||||
return 0, entry, nil // a nil entry implies it should act like it is erased
|
return 0, entry, nil // a nil entry implies it should act like it is erased
|
||||||
|
@ -1218,3 +1218,27 @@ func protocolForService(
|
||||||
}
|
}
|
||||||
return maxIdx, chain.Protocol, nil
|
return maxIdx, chain.Protocol, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfigEntryKindName is a value type useful for maps. You can use:
|
||||||
|
// map[ConfigEntryKindName]Payload
|
||||||
|
// instead of:
|
||||||
|
// map[string]map[string]Payload
|
||||||
|
type ConfigEntryKindName struct {
|
||||||
|
Kind string
|
||||||
|
Name string
|
||||||
|
structs.EnterpriseMeta
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConfigEntryKindName(kind, name string, entMeta *structs.EnterpriseMeta) ConfigEntryKindName {
|
||||||
|
ret := ConfigEntryKindName{
|
||||||
|
Kind: kind,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
if entMeta == nil {
|
||||||
|
entMeta = structs.DefaultEnterpriseMeta()
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.EnterpriseMeta = *entMeta
|
||||||
|
ret.EnterpriseMeta.Normalize()
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
|
@ -962,9 +962,9 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
entries []structs.ConfigEntry
|
entries []structs.ConfigEntry
|
||||||
expectBefore []structs.ConfigEntryKindName
|
expectBefore []ConfigEntryKindName
|
||||||
overrides map[structs.ConfigEntryKindName]structs.ConfigEntry
|
overrides map[ConfigEntryKindName]structs.ConfigEntry
|
||||||
expectAfter []structs.ConfigEntryKindName
|
expectAfter []ConfigEntryKindName
|
||||||
expectAfterErr string
|
expectAfterErr string
|
||||||
checkAfter func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries)
|
checkAfter func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries)
|
||||||
}{
|
}{
|
||||||
|
@ -977,13 +977,13 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
Protocol: "tcp",
|
Protocol: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil): nil,
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil): nil,
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
// nothing
|
// nothing
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -996,18 +996,18 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
Protocol: "tcp",
|
Protocol: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil): &structs.ServiceConfigEntry{
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil): &structs.ServiceConfigEntry{
|
||||||
Kind: structs.ServiceDefaults,
|
Kind: structs.ServiceDefaults,
|
||||||
Name: "main",
|
Name: "main",
|
||||||
Protocol: "grpc",
|
Protocol: "grpc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
},
|
},
|
||||||
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
||||||
defaults := entrySet.GetService(structs.NewServiceID("main", nil))
|
defaults := entrySet.GetService(structs.NewServiceID("main", nil))
|
||||||
|
@ -1029,15 +1029,15 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
Name: "main",
|
Name: "main",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceRouter, "main", nil),
|
NewConfigEntryKindName(structs.ServiceRouter, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceRouter, "main", nil): nil,
|
NewConfigEntryKindName(structs.ServiceRouter, "main", nil): nil,
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1074,13 +1074,13 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceRouter, "main", nil),
|
NewConfigEntryKindName(structs.ServiceRouter, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceRouter, "main", nil): &structs.ServiceRouterConfigEntry{
|
NewConfigEntryKindName(structs.ServiceRouter, "main", nil): &structs.ServiceRouterConfigEntry{
|
||||||
Kind: structs.ServiceRouter,
|
Kind: structs.ServiceRouter,
|
||||||
Name: "main",
|
Name: "main",
|
||||||
Routes: []structs.ServiceRoute{
|
Routes: []structs.ServiceRoute{
|
||||||
|
@ -1097,10 +1097,10 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceRouter, "main", nil),
|
NewConfigEntryKindName(structs.ServiceRouter, "main", nil),
|
||||||
},
|
},
|
||||||
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
||||||
router := entrySet.GetRouter(structs.NewServiceID("main", nil))
|
router := entrySet.GetRouter(structs.NewServiceID("main", nil))
|
||||||
|
@ -1137,15 +1137,15 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceSplitter, "main", nil),
|
NewConfigEntryKindName(structs.ServiceSplitter, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceSplitter, "main", nil): nil,
|
NewConfigEntryKindName(structs.ServiceSplitter, "main", nil): nil,
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1164,12 +1164,12 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceSplitter, "main", nil),
|
NewConfigEntryKindName(structs.ServiceSplitter, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceSplitter, "main", nil): &structs.ServiceSplitterConfigEntry{
|
NewConfigEntryKindName(structs.ServiceSplitter, "main", nil): &structs.ServiceSplitterConfigEntry{
|
||||||
Kind: structs.ServiceSplitter,
|
Kind: structs.ServiceSplitter,
|
||||||
Name: "main",
|
Name: "main",
|
||||||
Splits: []structs.ServiceSplit{
|
Splits: []structs.ServiceSplit{
|
||||||
|
@ -1178,9 +1178,9 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
NewConfigEntryKindName(structs.ServiceDefaults, "main", nil),
|
||||||
structs.NewConfigEntryKindName(structs.ServiceSplitter, "main", nil),
|
NewConfigEntryKindName(structs.ServiceSplitter, "main", nil),
|
||||||
},
|
},
|
||||||
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
||||||
splitter := entrySet.GetSplitter(structs.NewServiceID("main", nil))
|
splitter := entrySet.GetSplitter(structs.NewServiceID("main", nil))
|
||||||
|
@ -1203,13 +1203,13 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
Name: "main",
|
Name: "main",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil): nil,
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil): nil,
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
// nothing
|
// nothing
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1221,18 +1221,18 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
Name: "main",
|
Name: "main",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectBefore: []structs.ConfigEntryKindName{
|
expectBefore: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
||||||
},
|
},
|
||||||
overrides: map[structs.ConfigEntryKindName]structs.ConfigEntry{
|
overrides: map[ConfigEntryKindName]structs.ConfigEntry{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil): &structs.ServiceResolverConfigEntry{
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil): &structs.ServiceResolverConfigEntry{
|
||||||
Kind: structs.ServiceResolver,
|
Kind: structs.ServiceResolver,
|
||||||
Name: "main",
|
Name: "main",
|
||||||
ConnectTimeout: 33 * time.Second,
|
ConnectTimeout: 33 * time.Second,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectAfter: []structs.ConfigEntryKindName{
|
expectAfter: []ConfigEntryKindName{
|
||||||
structs.NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
NewConfigEntryKindName(structs.ServiceResolver, "main", nil),
|
||||||
},
|
},
|
||||||
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
checkAfter: func(t *testing.T, entrySet *structs.DiscoveryChainConfigEntries) {
|
||||||
resolver := entrySet.GetResolver(structs.NewServiceID("main", nil))
|
resolver := entrySet.GetResolver(structs.NewServiceID("main", nil))
|
||||||
|
@ -1276,31 +1276,31 @@ func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func entrySetToKindNames(entrySet *structs.DiscoveryChainConfigEntries) []structs.ConfigEntryKindName {
|
func entrySetToKindNames(entrySet *structs.DiscoveryChainConfigEntries) []ConfigEntryKindName {
|
||||||
var out []structs.ConfigEntryKindName
|
var out []ConfigEntryKindName
|
||||||
for _, entry := range entrySet.Routers {
|
for _, entry := range entrySet.Routers {
|
||||||
out = append(out, structs.NewConfigEntryKindName(
|
out = append(out, NewConfigEntryKindName(
|
||||||
entry.Kind,
|
entry.Kind,
|
||||||
entry.Name,
|
entry.Name,
|
||||||
&entry.EnterpriseMeta,
|
&entry.EnterpriseMeta,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
for _, entry := range entrySet.Splitters {
|
for _, entry := range entrySet.Splitters {
|
||||||
out = append(out, structs.NewConfigEntryKindName(
|
out = append(out, NewConfigEntryKindName(
|
||||||
entry.Kind,
|
entry.Kind,
|
||||||
entry.Name,
|
entry.Name,
|
||||||
&entry.EnterpriseMeta,
|
&entry.EnterpriseMeta,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
for _, entry := range entrySet.Resolvers {
|
for _, entry := range entrySet.Resolvers {
|
||||||
out = append(out, structs.NewConfigEntryKindName(
|
out = append(out, NewConfigEntryKindName(
|
||||||
entry.Kind,
|
entry.Kind,
|
||||||
entry.Name,
|
entry.Name,
|
||||||
&entry.EnterpriseMeta,
|
&entry.EnterpriseMeta,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
for _, entry := range entrySet.Services {
|
for _, entry := range entrySet.Services {
|
||||||
out = append(out, structs.NewConfigEntryKindName(
|
out = append(out, NewConfigEntryKindName(
|
||||||
entry.Kind,
|
entry.Kind,
|
||||||
entry.Name,
|
entry.Name,
|
||||||
&entry.EnterpriseMeta,
|
&entry.EnterpriseMeta,
|
||||||
|
|
|
@ -739,30 +739,6 @@ func (c *ConfigEntryResponse) UnmarshalBinary(data []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigEntryKindName is a value type useful for maps. You can use:
|
|
||||||
// map[ConfigEntryKindName]Payload
|
|
||||||
// instead of:
|
|
||||||
// map[string]map[string]Payload
|
|
||||||
type ConfigEntryKindName struct {
|
|
||||||
Kind string
|
|
||||||
Name string
|
|
||||||
EnterpriseMeta
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewConfigEntryKindName(kind, name string, entMeta *EnterpriseMeta) ConfigEntryKindName {
|
|
||||||
ret := ConfigEntryKindName{
|
|
||||||
Kind: kind,
|
|
||||||
Name: name,
|
|
||||||
}
|
|
||||||
if entMeta == nil {
|
|
||||||
entMeta = DefaultEnterpriseMeta()
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.EnterpriseMeta = *entMeta
|
|
||||||
ret.EnterpriseMeta.Normalize()
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateConfigEntryMeta(meta map[string]string) error {
|
func validateConfigEntryMeta(meta map[string]string) error {
|
||||||
var err error
|
var err error
|
||||||
if len(meta) > metaMaxKeyPairs {
|
if len(meta) > metaMaxKeyPairs {
|
||||||
|
|
Loading…
Reference in New Issue