From 573d4ec56c4313e1ab928cf6394c48e8608cac80 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Thu, 16 Nov 2023 09:17:50 -0700 Subject: [PATCH] Support extra init args (#390) --- api/v1/cosmosfullnode_types.go | 4 ++++ api/v1/zz_generated.deepcopy.go | 5 +++++ config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml | 5 +++++ internal/fullnode/pod_builder.go | 5 ++++- internal/fullnode/pod_builder_test.go | 4 ++-- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/v1/cosmosfullnode_types.go b/api/v1/cosmosfullnode_types.go index 0622a653..33843605 100644 --- a/api/v1/cosmosfullnode_types.go +++ b/api/v1/cosmosfullnode_types.go @@ -543,6 +543,10 @@ type ChainSpec struct { // +optional Versions []ChainVersion `json:"versions"` + // Additional arguments to pass to the chain init command. + // +optional + AdditionalInitArgs []string `json:"additionalInitArgs"` + // Additional arguments to pass to the chain start command. // +optional AdditionalStartArgs []string `json:"additionalStartArgs"` diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 206dcb1b..854b312b 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -109,6 +109,11 @@ func (in *ChainSpec) DeepCopyInto(out *ChainSpec) { *out = make([]ChainVersion, len(*in)) copy(*out, *in) } + if in.AdditionalInitArgs != nil { + in, out := &in.AdditionalInitArgs, &out.AdditionalInitArgs + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.AdditionalStartArgs != nil { in, out := &in.AdditionalStartArgs, &out.AdditionalStartArgs *out = make([]string, len(*in)) diff --git a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml index c9c2afdd..48fc41c3 100644 --- a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml +++ b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml @@ -45,6 +45,11 @@ spec: chain: description: Blockchain-specific configuration. properties: + additionalInitArgs: + description: Additional arguments to pass to the chain init command. + items: + type: string + type: array additionalStartArgs: description: Additional arguments to pass to the chain start command. items: diff --git a/internal/fullnode/pod_builder.go b/internal/fullnode/pod_builder.go index 903e52e2..73c85c37 100644 --- a/internal/fullnode/pod_builder.go +++ b/internal/fullnode/pod_builder.go @@ -319,7 +319,10 @@ func initContainers(crd *cosmosv1.CosmosFullNode, moniker string) []corev1.Conta addrbookCmd, addrbookArgs := DownloadAddrbookCommand(crd.Spec.ChainSpec) env := envVars(crd) - initCmd := fmt.Sprintf("%s init %s --chain-id %s", binary, moniker, crd.Spec.ChainSpec.ChainID) + initCmd := fmt.Sprintf("%s --chain-id %s init %s", binary, crd.Spec.ChainSpec.ChainID, moniker) + if len(crd.Spec.ChainSpec.AdditionalInitArgs) > 0 { + initCmd += " " + strings.Join(crd.Spec.ChainSpec.AdditionalInitArgs, " ") + } required := []corev1.Container{ { Name: "clean-init", diff --git a/internal/fullnode/pod_builder_test.go b/internal/fullnode/pod_builder_test.go index bdb393be..bd6f62e6 100644 --- a/internal/fullnode/pod_builder_test.go +++ b/internal/fullnode/pod_builder_test.go @@ -287,8 +287,8 @@ func TestPodBuilder(t *testing.T) { require.Contains(t, freshCont.Args[1], `rm -rf "$HOME/.tmp/*"`) initCont := pod.Spec.InitContainers[1] - require.Contains(t, initCont.Args[1], `osmosisd init osmosis-6 --chain-id osmosis-123 --home "$CHAIN_HOME"`) - require.Contains(t, initCont.Args[1], `osmosisd init osmosis-6 --chain-id osmosis-123 --home "$HOME/.tmp"`) + require.Contains(t, initCont.Args[1], `osmosisd --chain-id osmosis-123 init osmosis-6 --home "$CHAIN_HOME"`) + require.Contains(t, initCont.Args[1], `osmosisd --chain-id osmosis-123 init osmosis-6 --home "$HOME/.tmp"`) mergeConfig1 := pod.Spec.InitContainers[3] // The order of config-merge arguments is important. Rightmost takes precedence.