Skip to content

Commit

Permalink
Allow overriding instance external IP (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Dec 5, 2023
1 parent 52a6a0d commit dedff84
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions internal/fullnode/configmap_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit dedff84

Please sign in to comment.