diff --git a/api/v1/cosmosfullnode_types.go b/api/v1/cosmosfullnode_types.go index 33843605..8eb8bffe 100644 --- a/api/v1/cosmosfullnode_types.go +++ b/api/v1/cosmosfullnode_types.go @@ -759,6 +759,10 @@ type InstanceOverridesSpec struct { // Overrides an individual instance's Image. // +optional Image string `json:"image"` + + // Sets an individual instance's external address. + // +optional + ExternalAddress *string `json:"externalAddress"` } type DisableStrategy string diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 854b312b..796331a6 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -390,6 +390,11 @@ func (in *InstanceOverridesSpec) DeepCopyInto(out *InstanceOverridesSpec) { *out = new(PersistentVolumeClaimSpec) (*in).DeepCopyInto(*out) } + if in.ExternalAddress != nil { + in, out := &in.ExternalAddress, &out.ExternalAddress + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InstanceOverridesSpec. diff --git a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml index 48fc41c3..a803438e 100644 --- a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml +++ b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml @@ -375,6 +375,9 @@ spec: - Pod - All type: string + externalAddress: + description: Sets an individual instance's external address. + type: string image: description: Overrides an individual instance's Image. type: string diff --git a/internal/fullnode/configmap_builder.go b/internal/fullnode/configmap_builder.go index 1f7e408b..af9bbb51 100644 --- a/internal/fullnode/configmap_builder.go +++ b/internal/fullnode/configmap_builder.go @@ -161,9 +161,22 @@ func addConfigToml(buf *bytes.Buffer, cmData map[string]string, crd *cosmosv1.Co 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 + + var externalOverride bool + if crd.Spec.InstanceOverrides != nil { + if override, ok := crd.Spec.InstanceOverrides[instance]; ok && override.ExternalAddress != nil { + addr := *override.ExternalAddress + p2p["external_address"] = addr + p2p["external-address"] = addr + externalOverride = true + } + } + + if !externalOverride { + if v := peers.Get(instance, crd.Namespace).ExternalAddress; v != "" { + p2p["external_address"] = v + p2p["external-address"] = v + } } base["p2p"] = p2p diff --git a/internal/fullnode/configmap_builder_test.go b/internal/fullnode/configmap_builder_test.go index 95db1b08..56dac97b 100644 --- a/internal/fullnode/configmap_builder_test.go +++ b/internal/fullnode/configmap_builder_test.go @@ -392,6 +392,34 @@ func TestBuildConfigMaps(t *testing.T) { require.Equal(t, want, got) }) + t.Run("external address overrides", func(t *testing.T) { + overrides := crd.DeepCopy() + + overrides.Spec.InstanceOverrides = make(map[string]cosmosv1.InstanceOverridesSpec) + overrideAddr0 := "override0.example.com:26656" + overrideAddr1 := "override1.example.com:26656" + overrides.Spec.InstanceOverrides["osmosis-0"] = cosmosv1.InstanceOverridesSpec{ + ExternalAddress: &overrideAddr0, + } + overrides.Spec.InstanceOverrides["osmosis-1"] = cosmosv1.InstanceOverridesSpec{ + ExternalAddress: &overrideAddr1, + } + cms, err := BuildConfigMaps(overrides, nil) + require.NoError(t, err) + + var config map[string]any + + _, err = toml.Decode(cms[0].Object().Data["config-overlay.toml"], &config) + require.NoError(t, err) + require.Equal(t, overrideAddr0, config["p2p"].(map[string]any)["external_address"]) + require.Equal(t, overrideAddr0, config["p2p"].(map[string]any)["external-address"]) + + _, err = toml.Decode(cms[1].Object().Data["config-overlay.toml"], &config) + require.NoError(t, err) + require.Equal(t, overrideAddr1, config["p2p"].(map[string]any)["external_address"]) + require.Equal(t, overrideAddr1, config["p2p"].(map[string]any)["external-address"]) + }) + t.Run("invalid toml", func(t *testing.T) { malformed := crd.DeepCopy() malformed.Spec.ChainSpec.App.TomlOverrides = ptr(`invalid_toml = should be invalid`)