From 52a6a0d907a5f5233dc72ffa85154e13a98304a6 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 28 Nov 2023 14:13:14 -0700 Subject: [PATCH] Write both sets of properties (#393) * Write both sets of properties * fix tests --- internal/fullnode/configmap_builder.go | 25 ++++++++++++++++--- internal/fullnode/configmap_builder_test.go | 13 ++++++++++ internal/fullnode/testdata/comet.toml | 6 +++++ .../fullnode/testdata/comet_defaults.toml | 1 + .../fullnode/testdata/comet_overrides.toml | 4 ++- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/internal/fullnode/configmap_builder.go b/internal/fullnode/configmap_builder.go index eb0780a1..1f7e408b 100644 --- a/internal/fullnode/configmap_builder.go +++ b/internal/fullnode/configmap_builder.go @@ -112,22 +112,31 @@ func addConfigToml(buf *bytes.Buffer, cmData map[string]string, crd *cosmosv1.Co ) if crd.Spec.Type == cosmosv1.Sentry { - base["priv_validator_laddr"] = fmt.Sprintf("tcp://0.0.0.0:%d", privvalPort) + privVal := fmt.Sprintf("tcp://0.0.0.0:%d", privvalPort) + base["priv_validator_laddr"] = privVal + base["priv-validator-laddr"] = privVal // Disable indexing for sentries; they should not serve queries. - base["tx_index"] = map[string]string{"indexer": "null"} + + txIndex := map[string]string{"indexer": "null"} + base["tx_index"] = txIndex + base["tx-index"] = txIndex } if v := spec.LogLevel; v != nil { base["log_level"] = v + base["log-level"] = v } if v := spec.LogFormat; v != nil { base["log_format"] = v + base["log-format"] = v } privatePeers := peers.Except(instance, crd.Namespace) privatePeerStr := commaDelimited(privatePeers.AllPrivate()...) comet := spec.Comet + persistentPeers := commaDelimited(privatePeerStr, comet.PersistentPeers) p2p := decodedToml{ - "persistent_peers": commaDelimited(privatePeerStr, comet.PersistentPeers), + "persistent_peers": persistentPeers, + "persistent-peers": persistentPeers, "seeds": comet.Seeds, } @@ -135,27 +144,35 @@ func addConfigToml(buf *bytes.Buffer, cmData map[string]string, crd *cosmosv1.Co privateIDs := commaDelimited(privateIDStr, comet.PrivatePeerIDs) if v := privateIDs; v != "" { p2p["private_peer_ids"] = v + p2p["private-peer-ids"] = v } unconditionalIDs := commaDelimited(privateIDStr, comet.UnconditionalPeerIDs) if v := unconditionalIDs; v != "" { p2p["unconditional_peer_ids"] = v + p2p["unconditional-peer-ids"] = v } if v := comet.MaxInboundPeers; v != nil { p2p["max_num_inbound_peers"] = comet.MaxInboundPeers + p2p["max-num-inbound-peers"] = comet.MaxInboundPeers } if v := comet.MaxOutboundPeers; v != nil { p2p["max_num_outbound_peers"] = comet.MaxOutboundPeers + p2p["max-num-outbound-peers"] = comet.MaxOutboundPeers } if v := peers.Get(instance, crd.Namespace).ExternalAddress; v != "" { p2p["external_address"] = v + p2p["external-address"] = v } base["p2p"] = p2p if v := comet.CorsAllowedOrigins; v != nil { - base["rpc"] = decodedToml{"cors_allowed_origins": v} + base["rpc"] = decodedToml{ + "cors_allowed_origins": v, + "cors-allowed-origins": v, + } } dst := defaultComet() diff --git a/internal/fullnode/configmap_builder_test.go b/internal/fullnode/configmap_builder_test.go index 1d9f5069..95db1b08 100644 --- a/internal/fullnode/configmap_builder_test.go +++ b/internal/fullnode/configmap_builder_test.go @@ -1,7 +1,9 @@ package fullnode import ( + "bytes" _ "embed" + "fmt" "strings" "testing" @@ -219,11 +221,13 @@ func TestBuildConfigMaps(t *testing.T) { [p2p] external_address = "override.example.com" + external-address = "override.example.com" seeds = "override@seed" new_field = "p2p" [rpc] cors_allowed_origins = ["override"] + cors-allowed-origins = ["override"] [new_section] test = "value" @@ -250,6 +254,15 @@ func TestBuildConfigMaps(t *testing.T) { _, err = toml.Decode(cm.Data["config-overlay.toml"], &got) require.NoError(t, err) + var gotBuffer bytes.Buffer + var wantBuffer bytes.Buffer + + require.NoError(t, toml.NewEncoder(&gotBuffer).Encode(got)) + require.NoError(t, toml.NewEncoder(&wantBuffer).Encode(want)) + + fmt.Printf("got:\n%s\n", gotBuffer.String()) + fmt.Printf("want:\n%s\n", wantBuffer.String()) + require.Equal(t, want, got) }) diff --git a/internal/fullnode/testdata/comet.toml b/internal/fullnode/testdata/comet.toml index 816c0115..2937ed32 100644 --- a/internal/fullnode/testdata/comet.toml +++ b/internal/fullnode/testdata/comet.toml @@ -1,17 +1,23 @@ log_format = "json" +log-format = "json" log_level = "debug" +log-level = "debug" priv_validator_laddr = "" [p2p] laddr = "tcp://0.0.0.0:26656" persistent_peers = "peer1@1.2.2.2:789,peer2@2.2.2.2:789,peer3@3.2.2.2:789" +persistent-peers = "peer1@1.2.2.2:789,peer2@2.2.2.2:789,peer3@3.2.2.2:789" seeds = "seed1@1.1.1.1:456,seed2@1.1.1.1:456" max_num_inbound_peers = 5 +max-num-inbound-peers = 5 max_num_outbound_peers = 15 +max-num-outbound-peers = 15 [rpc] laddr = "tcp://0.0.0.0:26657" cors_allowed_origins = ["*"] +cors-allowed-origins = ["*"] [tx_index] indexer = "kv" diff --git a/internal/fullnode/testdata/comet_defaults.toml b/internal/fullnode/testdata/comet_defaults.toml index 208622e0..10bb9c07 100644 --- a/internal/fullnode/testdata/comet_defaults.toml +++ b/internal/fullnode/testdata/comet_defaults.toml @@ -5,6 +5,7 @@ priv_validator_laddr = "" [p2p] laddr = "tcp://0.0.0.0:26656" persistent_peers = "peer1@1.2.2.2:789,peer2@2.2.2.2:789,peer3@3.2.2.2:789" +persistent-peers = "peer1@1.2.2.2:789,peer2@2.2.2.2:789,peer3@3.2.2.2:789" seeds = "seed1@1.1.1.1:456,seed2@1.1.1.1:456" max_num_inbound_peers = 20 max_num_outbound_peers = 20 diff --git a/internal/fullnode/testdata/comet_overrides.toml b/internal/fullnode/testdata/comet_overrides.toml index 93a935e8..c0c32e38 100644 --- a/internal/fullnode/testdata/comet_overrides.toml +++ b/internal/fullnode/testdata/comet_overrides.toml @@ -4,9 +4,11 @@ priv_validator_laddr = "" new_base = "new base value" [p2p] +external-address = "override.example.com" external_address = "override.example.com" laddr = "tcp://0.0.0.0:26656" persistent_peers = "peer1@1.2.2.2:789,peer2@2.2.2.2:789,peer3@3.2.2.2:789" +persistent-peers = "peer1@1.2.2.2:789,peer2@2.2.2.2:789,peer3@3.2.2.2:789" seeds = "override@seed" max_num_inbound_peers = 20 max_num_outbound_peers = 20 @@ -15,9 +17,9 @@ new_field = "p2p" [rpc] laddr = "tcp://0.0.0.0:26657" cors_allowed_origins = ["override"] +cors-allowed-origins = ["override"] [tx_index] - indexer = "null" [new_section]