diff --git a/internal/praefect/config/config.go b/internal/praefect/config/config.go index 4d948f69955b62627a92a467508f442072a7946d..1b01b33b2ac271db82ff8e98fb6067355b6932ad 100644 --- a/internal/praefect/config/config.go +++ b/internal/praefect/config/config.go @@ -21,9 +21,12 @@ type Failover struct { // Config is a container for everything found in the TOML config file type Config struct { - ListenAddr string `toml:"listen_addr"` - SocketPath string `toml:"socket_path"` - VirtualStorages []*VirtualStorage `toml:"virtual_storage"` + ListenAddr string `toml:"listen_addr"` + SocketPath string `toml:"socket_path"` + VirtualStorages []*VirtualStorage `toml:"virtual_storage"` + //TODO: Remove VirtualStorageName and Nodes once omnibus and gdk are updated with support for + // VirtualStorages + VirtualStorageName string `toml:"virtual_storage_name"` Nodes []*models.Node `toml:"node"` Logging log.Config `toml:"logging"` Sentry sentry.Config `toml:"sentry"` @@ -54,6 +57,19 @@ func FromFile(filePath string) (Config, error) { _, err = toml.DecodeReader(cfgFile, config) + // TODO: Remove this after the virtual storages change is merged in omnibus + // and gdk. This is for backwards compatibility purposes only + if len(config.VirtualStorages) == 0 && config.VirtualStorageName != "" && len(config.Nodes) > 0 { + config.VirtualStorages = []*VirtualStorage{ + &VirtualStorage{ + Name: config.VirtualStorageName, + Nodes: config.Nodes, + }, + } + config.VirtualStorageName = "" + config.Nodes = nil + } + // TODO: Remove this after failover_enabled has moved under a separate failover section. This is for // backwards compatibility only if config.FailoverEnabled { diff --git a/internal/praefect/config/config_test.go b/internal/praefect/config/config_test.go index eed4abe3bddc606b9a12e66684a96727189446e2..4a01db1a4790936086a28a6c39cc61d68edde1dc 100644 --- a/internal/praefect/config/config_test.go +++ b/internal/praefect/config/config_test.go @@ -182,6 +182,41 @@ func TestConfigParsing(t *testing.T) { PostgresQueueEnabled: true, }, }, + //TODO: Remove this test, as well as the fixture in testdata/single-virtual-storage.config.toml + // once omnibus and gdk are updated with support for VirtualStorages + { + filePath: "testdata/single-virtual-storage.config.toml", + expected: Config{ + Logging: log.Config{ + Level: "info", + Format: "json", + }, + Sentry: sentry.Config{ + DSN: "abcd123", + Environment: "production", + }, + VirtualStorages: []*VirtualStorage{ + &VirtualStorage{ + Name: "praefect", + Nodes: []*models.Node{ + &models.Node{ + Address: "tcp://gitaly-internal-1.example.com", + Storage: "praefect-internal-1", + DefaultPrimary: true, + }, + { + Address: "tcp://gitaly-internal-2.example.com", + Storage: "praefect-internal-2", + }, + { + Address: "tcp://gitaly-internal-3.example.com", + Storage: "praefect-internal-3", + }, + }, + }, + }, + }, + }, } for _, tc := range testCases { diff --git a/internal/praefect/config/testdata/single-virtual-storage.config.toml b/internal/praefect/config/testdata/single-virtual-storage.config.toml new file mode 100644 index 0000000000000000000000000000000000000000..e983818758a322e28daba2bba82f49f5a450847e --- /dev/null +++ b/internal/praefect/config/testdata/single-virtual-storage.config.toml @@ -0,0 +1,25 @@ +listen_addr = "" +socket_path = "" +prometheus_listen_addr = "" +virtual_storage_name = "praefect" + +[logging] + format = "json" + level = "info" + +[sentry] + sentry_environment = "production" + sentry_dsn = "abcd123" + +[[node]] + address = "tcp://gitaly-internal-1.example.com" + storage = "praefect-internal-1" + primary = true + +[[node]] + address = "tcp://gitaly-internal-2.example.com" + storage = "praefect-internal-2" + +[[node]] + address = "tcp://gitaly-internal-3.example.com" + storage = "praefect-internal-3"