diff --git a/agent/consul/state/config_entry.go b/agent/consul/state/config_entry.go index 68cbbd73c..cb70373b4 100644 --- a/agent/consul/state/config_entry.go +++ b/agent/consul/state/config_entry.go @@ -12,10 +12,6 @@ import ( "github.com/hashicorp/consul/lib" ) -const ( - configTableName = "config-entries" -) - type ConfigEntryLinkIndex struct { } diff --git a/agent/consul/state/config_entry_oss.go b/agent/consul/state/config_entry_oss.go index bea2c01bc..eefe83272 100644 --- a/agent/consul/state/config_entry_oss.go +++ b/agent/consul/state/config_entry_oss.go @@ -3,63 +3,10 @@ package state import ( - "github.com/hashicorp/consul/agent/structs" memdb "github.com/hashicorp/go-memdb" -) -// configTableSchema returns a new table schema used to store global -// config entries. -func configTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: configTableName, - Indexes: map[string]*memdb.IndexSchema{ - "id": { - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Kind", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "Name", - Lowercase: true, - }, - }, - }, - }, - "kind": { - Name: "kind", - AllowMissing: false, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "Kind", - Lowercase: true, - }, - }, - "link": { - Name: "link", - AllowMissing: true, - Unique: false, - Indexer: &ConfigEntryLinkIndex{}, - }, - "intention-legacy-id": { - Name: "intention-legacy-id", - AllowMissing: true, - Unique: true, - Indexer: &ServiceIntentionLegacyIDIndex{}, - }, - "intention-source": { - Name: "intention-source", - AllowMissing: true, - Unique: false, - Indexer: &ServiceIntentionSourceIndex{}, - }, - }, - } -} + "github.com/hashicorp/consul/agent/structs" +) func firstConfigEntryWithTxn(tx ReadTxn, kind, name string, _ *structs.EnterpriseMeta) (interface{}, error) { return tx.First(configTableName, "id", kind, name) diff --git a/agent/consul/state/config_entry_schema.go b/agent/consul/state/config_entry_schema.go new file mode 100644 index 000000000..72a6320b0 --- /dev/null +++ b/agent/consul/state/config_entry_schema.go @@ -0,0 +1,65 @@ +package state + +import "github.com/hashicorp/go-memdb" + +const ( + configTableName = "config-entries" + + indexLink = "link" + indexIntentionLegacyID = "intention-legacy-id" + indexSource = "intention-source" +) + +// configTableSchema returns a new table schema used to store global +// config entries. +func configTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: configTableName, + Indexes: map[string]*memdb.IndexSchema{ + indexID: { + Name: indexID, + AllowMissing: false, + Unique: true, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Kind", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "Name", + Lowercase: true, + }, + }, + }, + }, + indexKind: { + Name: indexKind, + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "Kind", + Lowercase: true, + }, + }, + indexLink: { + Name: indexLink, + AllowMissing: true, + Unique: false, + Indexer: &ConfigEntryLinkIndex{}, + }, + indexIntentionLegacyID: { + Name: indexIntentionLegacyID, + AllowMissing: true, + Unique: true, + Indexer: &ServiceIntentionLegacyIDIndex{}, + }, + indexSource: { + Name: indexSource, + AllowMissing: true, + Unique: false, + Indexer: &ServiceIntentionSourceIndex{}, + }, + }, + } +}