mirror of https://github.com/status-im/consul.git
Merge pull request #10045 from hashicorp/dnephin/state-proxy-defaults
state: remove config-entries kind index
This commit is contained in:
commit
2e4dc7b705
|
@ -327,7 +327,7 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
|
||||||
// Pass the WatchSet to both the service and proxy config lookups. If either is updated during the
|
// Pass the WatchSet to both the service and proxy config lookups. If either is updated during the
|
||||||
// blocking query, this function will be rerun and these state store lookups will both be current.
|
// blocking query, this function will be rerun and these state store lookups will both be current.
|
||||||
// We use the default enterprise meta to look up the global proxy defaults because they are not namespaced.
|
// We use the default enterprise meta to look up the global proxy defaults because they are not namespaced.
|
||||||
_, proxyEntry, err := state.ConfigEntry(ws, structs.ProxyDefaults, structs.ProxyConfigGlobal, structs.DefaultEnterpriseMeta())
|
_, proxyEntry, err := state.ConfigEntry(ws, structs.ProxyDefaults, structs.ProxyConfigGlobal, &args.EnterpriseMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ type ConfigEntryLinkIndex struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type discoveryChainConfigEntry interface {
|
type discoveryChainConfigEntry interface {
|
||||||
structs.ConfigEntry
|
|
||||||
// ListRelatedServices returns a list of other names of services referenced
|
// ListRelatedServices returns a list of other names of services referenced
|
||||||
// in this config entry.
|
// in this config entry.
|
||||||
ListRelatedServices() []structs.ServiceID
|
ListRelatedServices() []structs.ServiceID
|
||||||
|
@ -426,7 +425,7 @@ func (s *Store) discoveryChainSourcesTxn(tx ReadTxn, ws memdb.WatchSet, dc strin
|
||||||
queue := []structs.ServiceName{destination}
|
queue := []structs.ServiceName{destination}
|
||||||
for len(queue) > 0 {
|
for len(queue) > 0 {
|
||||||
// The "link" index returns config entries that reference a service
|
// The "link" index returns config entries that reference a service
|
||||||
iter, err := tx.Get(tableConfigEntries, "link", queue[0].ToServiceID())
|
iter, err := tx.Get(tableConfigEntries, indexLink, queue[0].ToServiceID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
@ -598,7 +597,7 @@ func validateProposedConfigEntryInServiceGraph(
|
||||||
sid := structs.NewServiceID(name, entMeta)
|
sid := structs.NewServiceID(name, entMeta)
|
||||||
checkChains[sid] = struct{}{}
|
checkChains[sid] = struct{}{}
|
||||||
|
|
||||||
iter, err := tx.Get(tableConfigEntries, "link", sid)
|
iter, err := tx.Get(tableConfigEntries, indexLink, sid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -853,7 +852,7 @@ func readDiscoveryChainConfigEntriesTxn(
|
||||||
sid := structs.NewServiceID(serviceName, entMeta)
|
sid := structs.NewServiceID(serviceName, entMeta)
|
||||||
|
|
||||||
// Grab the proxy defaults if they exist.
|
// Grab the proxy defaults if they exist.
|
||||||
idx, proxy, err := getProxyConfigEntryTxn(tx, ws, structs.ProxyConfigGlobal, overrides, structs.DefaultEnterpriseMeta())
|
idx, proxy, err := getProxyConfigEntryTxn(tx, ws, structs.ProxyConfigGlobal, overrides, entMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
} else if proxy != nil {
|
} else if proxy != nil {
|
||||||
|
@ -1169,6 +1168,7 @@ func configEntryWithOverridesTxn(
|
||||||
) (uint64, structs.ConfigEntry, error) {
|
) (uint64, structs.ConfigEntry, error) {
|
||||||
if len(overrides) > 0 {
|
if len(overrides) > 0 {
|
||||||
kn := NewConfigEntryKindName(kind, name, entMeta)
|
kn := NewConfigEntryKindName(kind, name, entMeta)
|
||||||
|
kn.Normalize()
|
||||||
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
|
||||||
|
@ -1186,7 +1186,7 @@ func protocolForService(
|
||||||
svc structs.ServiceName,
|
svc structs.ServiceName,
|
||||||
) (uint64, string, error) {
|
) (uint64, string, error) {
|
||||||
// Get the global proxy defaults (for default protocol)
|
// Get the global proxy defaults (for default protocol)
|
||||||
maxIdx, proxyConfig, err := configEntryTxn(tx, ws, structs.ProxyDefaults, structs.ProxyConfigGlobal, structs.DefaultEnterpriseMeta())
|
maxIdx, proxyConfig, err := configEntryTxn(tx, ws, structs.ProxyDefaults, structs.ProxyConfigGlobal, &svc.EnterpriseMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", err
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
@ -1230,6 +1230,11 @@ type ConfigEntryKindName struct {
|
||||||
structs.EnterpriseMeta
|
structs.EnterpriseMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewConfigEntryKindName returns a new ConfigEntryKindName. The EnterpriseMeta
|
||||||
|
// values will be normalized based on the kind.
|
||||||
|
//
|
||||||
|
// Any caller which modifies the EnterpriseMeta field must call Normalize before
|
||||||
|
// persisting or using the value as a map key.
|
||||||
func NewConfigEntryKindName(kind, name string, entMeta *structs.EnterpriseMeta) ConfigEntryKindName {
|
func NewConfigEntryKindName(kind, name string, entMeta *structs.EnterpriseMeta) ConfigEntryKindName {
|
||||||
ret := ConfigEntryKindName{
|
ret := ConfigEntryKindName{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
|
@ -1240,7 +1245,7 @@ func NewConfigEntryKindName(kind, name string, entMeta *structs.EnterpriseMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.EnterpriseMeta = *entMeta
|
ret.EnterpriseMeta = *entMeta
|
||||||
ret.EnterpriseMeta.Normalize()
|
ret.Normalize()
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1253,3 +1258,15 @@ type ConfigEntryKindQuery struct {
|
||||||
Kind string
|
Kind string
|
||||||
structs.EnterpriseMeta
|
structs.EnterpriseMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NamespaceOrDefault exists because structs.EnterpriseMeta uses a pointer
|
||||||
|
// receiver for this method. Remove once that is fixed.
|
||||||
|
func (q ConfigEntryKindQuery) NamespaceOrDefault() string {
|
||||||
|
return q.EnterpriseMeta.NamespaceOrDefault()
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionOrDefault exists because structs.EnterpriseMeta uses a pointer
|
||||||
|
// receiver for this method. Remove once that is fixed.
|
||||||
|
func (q ConfigEntryKindQuery) PartitionOrDefault() string {
|
||||||
|
return q.EnterpriseMeta.PartitionOrDefault()
|
||||||
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ func configIntentionGetTxn(tx ReadTxn, ws memdb.WatchSet, id string) (uint64, *s
|
||||||
idx = 1
|
idx = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
watchCh, existing, err := tx.FirstWatch(tableConfigEntries, "intention-legacy-id", id)
|
watchCh, existing, err := tx.FirstWatch(tableConfigEntries, indexIntentionLegacyID, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, nil, fmt.Errorf("failed config entry lookup: %s", err)
|
return 0, nil, nil, fmt.Errorf("failed config entry lookup: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ func readSourceIntentionsFromConfigEntriesTxn(tx ReadTxn, ws memdb.WatchSet, ser
|
||||||
func readSourceIntentionsFromConfigEntriesForServiceTxn(tx ReadTxn, ws memdb.WatchSet, serviceName string, entMeta *structs.EnterpriseMeta, results structs.Intentions) (structs.Intentions, error) {
|
func readSourceIntentionsFromConfigEntriesForServiceTxn(tx ReadTxn, ws memdb.WatchSet, serviceName string, entMeta *structs.EnterpriseMeta, results structs.Intentions) (structs.Intentions, error) {
|
||||||
sn := structs.NewServiceName(serviceName, entMeta)
|
sn := structs.NewServiceName(serviceName, entMeta)
|
||||||
|
|
||||||
iter, err := tx.Get(tableConfigEntries, "intention-source", sn)
|
iter, err := tx.Get(tableConfigEntries, indexSource, sn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed config entry lookup: %s", err)
|
return nil, fmt.Errorf("failed config entry lookup: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func indexFromConfigEntryKindName(arg interface{}) ([]byte, error) {
|
func indexFromConfigEntryKindName(arg interface{}) ([]byte, error) {
|
||||||
n, ok := arg.(ConfigEntryKindName)
|
var b indexBuilder
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("invalid type for ConfigEntryKindName query: %T", arg)
|
switch n := arg.(type) {
|
||||||
|
case *structs.EnterpriseMeta:
|
||||||
|
return nil, nil
|
||||||
|
case structs.EnterpriseMeta:
|
||||||
|
return b.Bytes(), nil
|
||||||
|
case ConfigEntryKindQuery:
|
||||||
|
b.String(strings.ToLower(n.Kind))
|
||||||
|
return b.Bytes(), nil
|
||||||
|
case ConfigEntryKindName:
|
||||||
|
b.String(strings.ToLower(n.Kind))
|
||||||
|
b.String(strings.ToLower(n.Name))
|
||||||
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var b indexBuilder
|
return nil, fmt.Errorf("invalid type for ConfigEntryKindName query: %T", arg)
|
||||||
b.String(strings.ToLower(n.Kind))
|
|
||||||
b.String(strings.ToLower(n.Name))
|
|
||||||
return b.Bytes(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateConfigEntryEnterprise(_ ReadTxn, _ structs.ConfigEntry) error {
|
func validateConfigEntryEnterprise(_ ReadTxn, _ structs.ConfigEntry) error {
|
||||||
|
@ -32,7 +40,7 @@ func getAllConfigEntriesWithTxn(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.Re
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||||
return tx.Get(tableConfigEntries, indexKind, ConfigEntryKindQuery{Kind: kind})
|
return tx.Get(tableConfigEntries, indexID+"_prefix", ConfigEntryKindQuery{Kind: kind})
|
||||||
}
|
}
|
||||||
|
|
||||||
func configIntentionsConvertToList(iter memdb.ResultIterator, _ *structs.EnterpriseMeta) structs.Intentions {
|
func configIntentionsConvertToList(iter memdb.ResultIterator, _ *structs.EnterpriseMeta) structs.Intentions {
|
||||||
|
|
|
@ -18,17 +18,15 @@ func testIndexerTableConfigEntries() map[string]indexerTestCase {
|
||||||
source: &structs.ProxyConfigEntry{Name: "NaMe"},
|
source: &structs.ProxyConfigEntry{Name: "NaMe"},
|
||||||
expected: []byte("proxy-defaults\x00name\x00"),
|
expected: []byte("proxy-defaults\x00name\x00"),
|
||||||
},
|
},
|
||||||
},
|
prefix: []indexValue{
|
||||||
indexKind: {
|
{
|
||||||
read: indexValue{
|
source: structs.EnterpriseMeta{},
|
||||||
source: ConfigEntryKindQuery{
|
expected: nil,
|
||||||
Kind: "Service-Defaults",
|
},
|
||||||
|
{
|
||||||
|
source: ConfigEntryKindQuery{Kind: "Proxy-Defaults"},
|
||||||
|
expected: []byte("proxy-defaults\x00"),
|
||||||
},
|
},
|
||||||
expected: []byte("service-defaults\x00"),
|
|
||||||
},
|
|
||||||
write: indexValue{
|
|
||||||
source: &structs.ServiceConfigEntry{},
|
|
||||||
expected: []byte("service-defaults\x00"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,6 @@ func configTableSchema() *memdb.TableSchema {
|
||||||
prefixIndex: indexFromConfigEntryKindName,
|
prefixIndex: indexFromConfigEntryKindName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
indexKind: {
|
|
||||||
Name: indexKind,
|
|
||||||
AllowMissing: false,
|
|
||||||
Unique: false,
|
|
||||||
Indexer: indexerSingle{
|
|
||||||
readIndex: indexFromConfigEntryKindQuery,
|
|
||||||
writeIndex: indexKindFromConfigEntry,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
indexLink: {
|
indexLink: {
|
||||||
Name: indexLink,
|
Name: indexLink,
|
||||||
AllowMissing: true,
|
AllowMissing: true,
|
||||||
|
@ -80,17 +71,6 @@ func indexFromConfigEntry(raw interface{}) ([]byte, error) {
|
||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexFromConfigEntryKindQuery(raw interface{}) ([]byte, error) {
|
|
||||||
q, ok := raw.(ConfigEntryKindQuery)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("type must be ConfigEntryKindQuery: %T", raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
var b indexBuilder
|
|
||||||
b.String(strings.ToLower(q.Kind))
|
|
||||||
return b.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// indexKindFromConfigEntry indexes kinds without a namespace for any config
|
// indexKindFromConfigEntry indexes kinds without a namespace for any config
|
||||||
// entries that span all namespaces.
|
// entries that span all namespaces.
|
||||||
func indexKindFromConfigEntry(raw interface{}) ([]byte, error) {
|
func indexKindFromConfigEntry(raw interface{}) ([]byte, error) {
|
||||||
|
|
|
@ -50,6 +50,14 @@ func (m *EnterpriseMeta) NamespaceOrEmpty() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *EnterpriseMeta) PartitionOrDefault() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *EnterpriseMeta) PartitionOrEmpty() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func NewEnterpriseMeta(_ string) EnterpriseMeta {
|
func NewEnterpriseMeta(_ string) EnterpriseMeta {
|
||||||
return emptyEnterpriseMeta
|
return emptyEnterpriseMeta
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue