diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 8e7b3d5c..67268712 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '>=1.20.2' + go-version: '>=1.21' - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: @@ -29,6 +29,6 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '>=1.20.2' + go-version: '>=1.21' - name: unit tests run: make test diff --git a/.github/workflows/manifests.yaml b/.github/workflows/manifests.yaml index fd96a968..30628482 100644 --- a/.github/workflows/manifests.yaml +++ b/.github/workflows/manifests.yaml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '>=1.20.2' + go-version: '>=1.21' - run: make generate manifests - uses: CatChen/check-git-status-action@v1 diff --git a/api/v1/cosmosfullnode_types.go b/api/v1/cosmosfullnode_types.go index a4c3f11d..c5ad6921 100644 --- a/api/v1/cosmosfullnode_types.go +++ b/api/v1/cosmosfullnode_types.go @@ -51,6 +51,14 @@ type FullNodeSpec struct { // +optional Type FullNodeType `json:"type"` + // Different kinds of chains supported by the operator + // 'Cosmos' configures the node using defaults for a Cosmos based chain + // 'Custom' configures the node with more flexible options that allow for support other chains + // If not set, defaults to Cosmos + // +kubebuilder:validation:Enum:=Cosmos;Custom + // +optional + ChainType ChainType `json:"chainType"` + // Blockchain-specific configuration. ChainSpec ChainSpec `json:"chain"` @@ -102,6 +110,13 @@ const ( Sentry FullNodeType = "Sentry" ) +type ChainType string + +const ( + Cosmos ChainType = "Cosmos" + Custom ChainType = "Custom" +) + // FullNodeStatus defines the observed state of CosmosFullNode type FullNodeStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster @@ -450,6 +465,14 @@ type ChainSpec struct { // +optional LogFormat *string `json:"logFormat"` + // Specify shell (sh) script commands to initialize the chain + // +optional + InitScript *string `json:"initScript"` + + // Specify shell (sh) script commands to start the chain + // +optional + StartScript *string `json:"startScript"` + // URL to address book file to download from the internet. // The operator detects and properly handles the following file extensions: // .json, .json.gz, .tar, .tar.gz, .tar.gzip, .zip diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index f709859c..1ed1cfff 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -63,6 +63,16 @@ func (in *ChainSpec) DeepCopyInto(out *ChainSpec) { *out = new(string) **out = **in } + if in.InitScript != nil { + in, out := &in.InitScript, &out.InitScript + *out = new(string) + **out = **in + } + if in.StartScript != nil { + in, out := &in.StartScript, &out.StartScript + *out = new(string) + **out = **in + } if in.AddrbookURL != nil { in, out := &in.AddrbookURL, &out.AddrbookURL *out = new(string) diff --git a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml index 457e90d2..f31a8609 100644 --- a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml +++ b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml @@ -283,6 +283,10 @@ spec: Therefore, this option was introduced to mitigate those edge cases, so that you can specify the home directory to match the chain's default home dir. type: string + initScript: + description: Specify shell (sh) script commands to initialize + the chain + type: string logFormat: description: |- One of plain or json. @@ -345,6 +349,9 @@ spec: .tar, .tar.gz, .tar.gzip, .tar.lz4 Use SnapshotScript if the snapshot archive is unconventional or requires special handling. type: string + startScript: + description: Specify shell (sh) script commands to start the chain + type: string versions: description: |- Versions of the chain and which height they should be applied. @@ -376,6 +383,15 @@ spec: - chainID - network type: object + chainType: + description: Different kinds of chains supported by the operator 'Cosmos' + configures the node using defaults for a Cosmos based chain 'Custom' + configures the node with more flexible options that allow for support + other chains If not set, defaults to Cosmos + enum: + - Cosmos + - Custom + type: string instanceOverrides: additionalProperties: description: InstanceOverridesSpec allows overriding an instance diff --git a/internal/fullnode/addrbook.go b/internal/fullnode/commands/addrbook.go similarity index 98% rename from internal/fullnode/addrbook.go rename to internal/fullnode/commands/addrbook.go index d1f94664..44a18ef4 100644 --- a/internal/fullnode/addrbook.go +++ b/internal/fullnode/commands/addrbook.go @@ -1,4 +1,4 @@ -package fullnode +package commands import ( _ "embed" diff --git a/internal/fullnode/addrbook_test.go b/internal/fullnode/commands/addrbook_test.go similarity index 88% rename from internal/fullnode/addrbook_test.go rename to internal/fullnode/commands/addrbook_test.go index 5ca8e783..c39c769f 100644 --- a/internal/fullnode/addrbook_test.go +++ b/internal/fullnode/commands/addrbook_test.go @@ -1,8 +1,9 @@ -package fullnode +package commands import ( "testing" + "github.com/samber/lo" cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" "github.com/stretchr/testify/require" ) @@ -33,7 +34,7 @@ func TestDownloadAddrbookCommand(t *testing.T) { t.Run("download", func(t *testing.T) { cfg := cosmosv1.ChainSpec{ - AddrbookURL: ptr("https://example.com/addrbook.json"), + AddrbookURL: lo.ToPtr("https://example.com/addrbook.json"), } cmd, args := DownloadAddrbookCommand(cfg) require.Equal(t, "sh", cmd) @@ -53,8 +54,8 @@ func TestDownloadAddrbookCommand(t *testing.T) { t.Run("custom", func(t *testing.T) { cfg := cosmosv1.ChainSpec{ // Keeping this to assert that custom script takes precedence. - AddrbookURL: ptr("https://example.com/addrbook.json"), - AddrbookScript: ptr("echo hi"), + AddrbookURL: lo.ToPtr("https://example.com/addrbook.json"), + AddrbookScript: lo.ToPtr("echo hi"), } cmd, args := DownloadAddrbookCommand(cfg) require.Equal(t, "sh", cmd) diff --git a/internal/fullnode/genesis.go b/internal/fullnode/commands/genesis.go similarity index 98% rename from internal/fullnode/genesis.go rename to internal/fullnode/commands/genesis.go index f02e5b3e..1df77abe 100644 --- a/internal/fullnode/genesis.go +++ b/internal/fullnode/commands/genesis.go @@ -1,4 +1,4 @@ -package fullnode +package commands import ( _ "embed" diff --git a/internal/fullnode/genesis_test.go b/internal/fullnode/commands/genesis_test.go similarity index 88% rename from internal/fullnode/genesis_test.go rename to internal/fullnode/commands/genesis_test.go index 0cc8a7af..4d0fa887 100644 --- a/internal/fullnode/genesis_test.go +++ b/internal/fullnode/commands/genesis_test.go @@ -1,8 +1,9 @@ -package fullnode +package commands import ( "testing" + "github.com/samber/lo" cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" "github.com/stretchr/testify/require" ) @@ -34,7 +35,7 @@ func TestDownloadGenesisCommand(t *testing.T) { t.Run("download", func(t *testing.T) { cfg := cosmosv1.ChainSpec{ - GenesisURL: ptr("https://example.com/genesis.json"), + GenesisURL: lo.ToPtr("https://example.com/genesis.json"), } cmd, args := DownloadGenesisCommand(cfg) require.Equal(t, "sh", cmd) @@ -54,8 +55,8 @@ func TestDownloadGenesisCommand(t *testing.T) { t.Run("custom", func(t *testing.T) { cfg := cosmosv1.ChainSpec{ // Keeping this to assert that custom script takes precedence. - GenesisURL: ptr("https://example.com/genesis.json"), - GenesisScript: ptr("echo hi"), + GenesisURL: lo.ToPtr("https://example.com/genesis.json"), + GenesisScript: lo.ToPtr("echo hi"), } cmd, args := DownloadGenesisCommand(cfg) require.Equal(t, "sh", cmd) diff --git a/internal/fullnode/commands/init.go b/internal/fullnode/commands/init.go new file mode 100644 index 00000000..f590d5f2 --- /dev/null +++ b/internal/fullnode/commands/init.go @@ -0,0 +1,47 @@ +package commands + +import ( + _ "embed" + "fmt" + + cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" +) + +const initScriptWrapper = ` +set -eu + +echo CHAIN_HOME: $CHAIN_HOME + +if [ ! -d "$CHAIN_HOME/.penumbra" ]; then + echo "Initializing chain..." + %s +else + echo "Skipping chain init; already initialized." +fi +echo "Done" +` + +const cosmosInitScriptWrapper = ` +set -eu +if [ ! -d "$CHAIN_HOME/data" ]; then + echo "Initializing chain..." + %s --home "$CHAIN_HOME" +else + echo "Skipping chain init; already initialized." +fi + +echo "Initializing into tmp dir for downstream processing..." +%s --home "$HOME/.tmp"` + +func InitCommand(chainSpec cosmosv1.ChainSpec, moniker string) (string, []string) { + args := []string{"-c"} + switch { + case chainSpec.InitScript != nil: + args = append(args, fmt.Sprintf(initScriptWrapper, *chainSpec.InitScript)) + default: + initScript := fmt.Sprintf("%s init --chain-id %s %s", chainSpec.Binary, chainSpec.ChainID, moniker) + args = append(args, fmt.Sprintf(cosmosInitScriptWrapper, initScript, initScript)) + } + + return "sh", args +} diff --git a/internal/fullnode/commands/init_test.go b/internal/fullnode/commands/init_test.go new file mode 100644 index 00000000..b96840a6 --- /dev/null +++ b/internal/fullnode/commands/init_test.go @@ -0,0 +1,52 @@ +package commands + +import ( + "testing" + + cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" + "github.com/stretchr/testify/require" +) + +func TestInitCommand(t *testing.T) { + t.Parallel() + + t.Run("given cosmos chain", func(t *testing.T) { + t.Run("returns init command", func(t *testing.T) { + var cfg = cosmosv1.ChainSpec{ + Binary: "gaiad", + ChainID: "cosmoshub-4", + } + + cmd, args := InitCommand(cfg, "strangelove") + require.Equal(t, "sh", cmd) + + require.Len(t, args, 2) + + require.Equal(t, "-c", args[0]) + + got := args[1] + require.Contains(t, got, "if [ ! -d \"$CHAIN_HOME/data\" ]; then") + require.Contains(t, got, "gaiad init --chain-id cosmoshub-4 strangelove --home \"$CHAIN_HOME\"") + }) + }) + + t.Run("given custom chain", func(t *testing.T) { + t.Run("returns init command", func(t *testing.T) { + var initScript = "pd testnet --testnet-dir /home/operator/cosmos/.penumbra/testnet_data join --external-address 127.0.0.1:26656 --moniker strangelove" + var cfg = cosmosv1.ChainSpec{ + InitScript: &initScript, + } + + cmd, args := InitCommand(cfg, "strangelove") + require.Equal(t, "sh", cmd) + + require.Len(t, args, 2) + + require.Equal(t, "-c", args[0]) + + got := args[1] + require.Contains(t, got, "if [ ! -d \"$CHAIN_HOME/.penumbra\" ]; then") + require.Contains(t, got, "pd testnet --testnet-dir /home/operator/cosmos/.penumbra/testnet_data join --external-address 127.0.0.1:26656 --moniker strangelove") + }) + }) +} diff --git a/internal/fullnode/script/download-addrbook.sh b/internal/fullnode/commands/script/download-addrbook.sh similarity index 100% rename from internal/fullnode/script/download-addrbook.sh rename to internal/fullnode/commands/script/download-addrbook.sh diff --git a/internal/fullnode/script/download-genesis.sh b/internal/fullnode/commands/script/download-genesis.sh similarity index 100% rename from internal/fullnode/script/download-genesis.sh rename to internal/fullnode/commands/script/download-genesis.sh diff --git a/internal/fullnode/script/download-snapshot.sh b/internal/fullnode/commands/script/download-snapshot.sh similarity index 100% rename from internal/fullnode/script/download-snapshot.sh rename to internal/fullnode/commands/script/download-snapshot.sh diff --git a/internal/fullnode/script/use-init-genesis.sh b/internal/fullnode/commands/script/use-init-genesis.sh similarity index 100% rename from internal/fullnode/script/use-init-genesis.sh rename to internal/fullnode/commands/script/use-init-genesis.sh diff --git a/internal/fullnode/snapshot.go b/internal/fullnode/commands/snapshot.go similarity index 98% rename from internal/fullnode/snapshot.go rename to internal/fullnode/commands/snapshot.go index e66f791b..2ac7e62b 100644 --- a/internal/fullnode/snapshot.go +++ b/internal/fullnode/commands/snapshot.go @@ -1,4 +1,4 @@ -package fullnode +package commands import ( _ "embed" diff --git a/internal/fullnode/snapshot_test.go b/internal/fullnode/commands/snapshot_test.go similarity index 86% rename from internal/fullnode/snapshot_test.go rename to internal/fullnode/commands/snapshot_test.go index 76cbaf0a..132a24be 100644 --- a/internal/fullnode/snapshot_test.go +++ b/internal/fullnode/commands/snapshot_test.go @@ -1,8 +1,9 @@ -package fullnode +package commands import ( "testing" + "github.com/samber/lo" cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" "github.com/stretchr/testify/require" ) @@ -19,7 +20,7 @@ fi` ) t.Run("snapshot url", func(t *testing.T) { var cfg cosmosv1.ChainSpec - cfg.SnapshotURL = ptr(testURL) + cfg.SnapshotURL = lo.ToPtr(testURL) cmd, args := DownloadSnapshotCommand(cfg) require.Equal(t, "sh", cmd) @@ -38,8 +39,8 @@ fi` t.Run("snapshot script", func(t *testing.T) { var cfg cosmosv1.ChainSpec - cfg.SnapshotURL = ptr(testURL) // Asserts SnapshotScript takes precedence. - cfg.SnapshotScript = ptr("echo hello") + cfg.SnapshotURL = lo.ToPtr(testURL) // Asserts SnapshotScript takes precedence. + cfg.SnapshotScript = lo.ToPtr("echo hello") _, args := DownloadSnapshotCommand(cfg) require.Len(t, args, 2) diff --git a/internal/fullnode/commands/start.go b/internal/fullnode/commands/start.go new file mode 100644 index 00000000..aaa7f246 --- /dev/null +++ b/internal/fullnode/commands/start.go @@ -0,0 +1,55 @@ +package commands + +import ( + "fmt" + "strings" + + cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" +) + +const startScriptWrapper = ` +%s +` + +func StartCmdAndArgs(crd *cosmosv1.CosmosFullNode, homeDir string) (string, []string) { + if crd.Spec.ChainSpec.StartScript == nil { + var ( + binary = crd.Spec.ChainSpec.Binary + args = StartCommandArgs(crd, homeDir) + privvalSleep int32 = 10 + ) + if v := crd.Spec.ChainSpec.PrivvalSleepSeconds; v != nil { + privvalSleep = *v + } + + if crd.Spec.Type == cosmosv1.Sentry && privvalSleep > 0 { + shellBody := fmt.Sprintf(`sleep %d +%s %s`, privvalSleep, binary, strings.Join(args, " ")) + return "sh", []string{"-c", shellBody} + } + + return binary, args + } else { + args := []string{"-c"} + args = append(args, fmt.Sprintf(startScriptWrapper, *crd.Spec.ChainSpec.StartScript)) + return "sh", args + } +} + +func StartCommandArgs(crd *cosmosv1.CosmosFullNode, homeDir string) []string { + args := []string{"start", "--home", homeDir} + cfg := crd.Spec.ChainSpec + if cfg.SkipInvariants { + args = append(args, "--x-crisis-skip-assert-invariants") + } + if lvl := cfg.LogLevel; lvl != nil { + args = append(args, "--log_level", *lvl) + } + if format := cfg.LogFormat; format != nil { + args = append(args, "--log_format", *format) + } + if len(crd.Spec.ChainSpec.AdditionalStartArgs) > 0 { + args = append(args, crd.Spec.ChainSpec.AdditionalStartArgs...) + } + return args +} diff --git a/internal/fullnode/commands/start_test.go b/internal/fullnode/commands/start_test.go new file mode 100644 index 00000000..41e50892 --- /dev/null +++ b/internal/fullnode/commands/start_test.go @@ -0,0 +1,52 @@ +package commands + +import ( + "testing" + + cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" + "github.com/stretchr/testify/require" +) + +func TestStartCommand(t *testing.T) { + t.Parallel() + + t.Run("given cosmos chain", func(t *testing.T) { + t.Run("returns init command", func(t *testing.T) { + var cfg = cosmosv1.ChainSpec{ + Binary: "gaiad", + ChainID: "cosmoshub-4", + } + + cmd, args := InitCommand(cfg, "strangelove") + require.Equal(t, "sh", cmd) + + require.Len(t, args, 2) + + require.Equal(t, "-c", args[0]) + + got := args[1] + require.Contains(t, got, "if [ ! -d \"$CHAIN_HOME/data\" ]; then") + require.Contains(t, got, "gaiad init --chain-id cosmoshub-4 strangelove --home \"$CHAIN_HOME\"") + }) + }) + + t.Run("given custom chain", func(t *testing.T) { + t.Run("returns init command", func(t *testing.T) { + var initScript = "pd testnet --testnet-dir /home/operator/cosmos/.penumbra/testnet_data join --external-address 127.0.0.1:26656 --moniker strangelove" + var cfg = cosmosv1.ChainSpec{ + InitScript: &initScript, + } + + cmd, args := InitCommand(cfg, "strangelove") + require.Equal(t, "sh", cmd) + + require.Len(t, args, 2) + + require.Equal(t, "-c", args[0]) + + got := args[1] + require.Contains(t, got, "if [ ! -d \"$CHAIN_HOME/.penumbra\" ]; then") + require.Contains(t, got, "pd testnet --testnet-dir /home/operator/cosmos/.penumbra/testnet_data join --external-address 127.0.0.1:26656 --moniker strangelove") + }) + }) +} diff --git a/internal/fullnode/pod_builder.go b/internal/fullnode/pod_builder.go index 2c81a011..96e091b9 100644 --- a/internal/fullnode/pod_builder.go +++ b/internal/fullnode/pod_builder.go @@ -10,6 +10,7 @@ import ( "github.com/samber/lo" cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" + "github.com/strangelove-ventures/cosmos-operator/internal/fullnode/commands" "github.com/strangelove-ventures/cosmos-operator/internal/healthcheck" "github.com/strangelove-ventures/cosmos-operator/internal/kube" "github.com/strangelove-ventures/cosmos-operator/internal/version" @@ -43,7 +44,7 @@ func NewPodBuilder(crd *cosmosv1.CosmosFullNode) PodBuilder { var ( tpl = crd.Spec.PodTemplate - startCmd, startArgs = startCmdAndArgs(crd) + startCmd, startArgs = commands.StartCmdAndArgs(crd, ChainHomeDir(crd)) probes = podReadinessProbes(crd) ) @@ -111,7 +112,7 @@ func NewPodBuilder(crd *cosmosv1.CosmosFullNode) PodBuilder { }, } - if len(crd.Spec.ChainSpec.Versions) > 0 { + if crd.Spec.ChainType == cosmosv1.Cosmos && len(crd.Spec.ChainSpec.Versions) > 0 { // version check sidecar, runs on inverval in case the instance is halting for upgrade. pod.Spec.Containers = append(pod.Spec.Containers, corev1.Container{ Name: "version-check-interval", @@ -346,12 +347,11 @@ func resolveInfraToolImage() string { func initContainers(crd *cosmosv1.CosmosFullNode, moniker string) []corev1.Container { tpl := crd.Spec.PodTemplate - binary := crd.Spec.ChainSpec.Binary - genesisCmd, genesisArgs := DownloadGenesisCommand(crd.Spec.ChainSpec) - addrbookCmd, addrbookArgs := DownloadAddrbookCommand(crd.Spec.ChainSpec) + initCmd, initArgs := commands.InitCommand(crd.Spec.ChainSpec, moniker) + genesisCmd, genesisArgs := commands.DownloadGenesisCommand(crd.Spec.ChainSpec) + addrbookCmd, addrbookArgs := commands.DownloadAddrbookCommand(crd.Spec.ChainSpec) env := envVars(crd) - initCmd := fmt.Sprintf("%s init --chain-id %s %s", binary, crd.Spec.ChainSpec.ChainID, moniker) if len(crd.Spec.ChainSpec.AdditionalInitArgs) > 0 { initCmd += " " + strings.Join(crd.Spec.ChainSpec.AdditionalInitArgs, " ") } @@ -366,28 +366,14 @@ func initContainers(crd *cosmosv1.CosmosFullNode, moniker string) []corev1.Conta WorkingDir: workDir, }, { - Name: chainInitContainer, - Image: tpl.Image, - Command: []string{"sh"}, - Args: []string{"-c", - fmt.Sprintf(` -set -eu -if [ ! -d "$CHAIN_HOME/data" ]; then - echo "Initializing chain..." - %s --home "$CHAIN_HOME" -else - echo "Skipping chain init; already initialized." -fi - -echo "Initializing into tmp dir for downstream processing..." -%s --home "$HOME/.tmp" -`, initCmd, initCmd), - }, + Name: chainInitContainer, + Image: tpl.Image, + Command: []string{initCmd}, + Args: initArgs, Env: env, ImagePullPolicy: tpl.ImagePullPolicy, WorkingDir: workDir, }, - { Name: "genesis-init", Image: resolveInfraToolImage(), @@ -406,37 +392,44 @@ echo "Initializing into tmp dir for downstream processing..." ImagePullPolicy: tpl.ImagePullPolicy, WorkingDir: workDir, }, - { - Name: "config-merge", - Image: resolveInfraToolImage(), - Command: []string{"sh"}, - Args: []string{"-c", - ` -set -eu -CONFIG_DIR="$CHAIN_HOME/config" -TMP_DIR="$HOME/.tmp/config" -OVERLAY_DIR="$HOME/.config" - -# This is a hack to prevent adding another init container. -# Ideally, this step is not concerned with merging config, so it would live elsewhere. -# The node key is a secret mounted into the main "node" container, so we do not need this one. -echo "Removing node key from chain's init subcommand..." -rm -rf "$CONFIG_DIR/node_key.json" - -echo "Merging config..." -set -x -config-merge -f toml "$TMP_DIR/config.toml" "$OVERLAY_DIR/config-overlay.toml" > "$CONFIG_DIR/config.toml" -config-merge -f toml "$TMP_DIR/app.toml" "$OVERLAY_DIR/app-overlay.toml" > "$CONFIG_DIR/app.toml" -`, + } + + if crd.Spec.ChainType == cosmosv1.Cosmos { + mrg := []corev1.Container{ + { + Name: "config-merge", + Image: resolveInfraToolImage(), + Command: []string{"sh"}, + Args: []string{"-c", + ` + set -eu + CONFIG_DIR="$CHAIN_HOME/config" + TMP_DIR="$HOME/.tmp/config" + OVERLAY_DIR="$HOME/.config" + + # This is a hack to prevent adding another init container. + # Ideally, this step is not concerned with merging config, so it would live elsewhere. + # The node key is a secret mounted into the main "node" container, so we do not need this one. + echo "Removing node key from chain's init subcommand..." + rm -rf "$CONFIG_DIR/node_key.json" + + echo "Merging config..." + set -x + config-merge -f toml "$TMP_DIR/config.toml" "$OVERLAY_DIR/config-overlay.toml" > "$CONFIG_DIR/config.toml" + config-merge -f toml "$TMP_DIR/app.toml" "$OVERLAY_DIR/app-overlay.toml" > "$CONFIG_DIR/app.toml" + `, + }, + Env: env, + ImagePullPolicy: tpl.ImagePullPolicy, + WorkingDir: workDir, }, - Env: env, - ImagePullPolicy: tpl.ImagePullPolicy, - WorkingDir: workDir, - }, + } + + required = append(required, mrg[0]) } if willRestoreFromSnapshot(crd) { - cmd, args := DownloadSnapshotCommand(crd.Spec.ChainSpec) + cmd, args := commands.DownloadSnapshotCommand(crd.Spec.ChainSpec) required = append(required, corev1.Container{ Name: "snapshot-restore", Image: resolveInfraToolImage(), @@ -458,60 +451,25 @@ config-merge -f toml "$TMP_DIR/app.toml" "$OVERLAY_DIR/app-overlay.toml" > "$CON // This initContainer will update the crd status with the current height for the pod, // And then panic if the image version is not correct for the current height. // After the status is patched, the pod will be restarted with the correct image. - required = append(required, corev1.Container{ - Name: "version-check", - Image: "ghcr.io/strangelove-ventures/cosmos-operator:" + version.DockerTag(), - Command: versionCheckCmd, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("5m"), - corev1.ResourceMemory: resource.MustParse("16Mi"), + if crd.Spec.ChainType == cosmosv1.Cosmos { + required = append(required, corev1.Container{ + Name: "version-check", + Image: "ghcr.io/strangelove-ventures/cosmos-operator:" + version.DockerTag(), + Command: versionCheckCmd, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("5m"), + corev1.ResourceMemory: resource.MustParse("16Mi"), + }, }, - }, - Env: env, - ImagePullPolicy: tpl.ImagePullPolicy, - WorkingDir: workDir, - SecurityContext: &corev1.SecurityContext{}, - }) - - return required -} - -func startCmdAndArgs(crd *cosmosv1.CosmosFullNode) (string, []string) { - var ( - binary = crd.Spec.ChainSpec.Binary - args = startCommandArgs(crd) - privvalSleep int32 = 10 - ) - if v := crd.Spec.ChainSpec.PrivvalSleepSeconds; v != nil { - privvalSleep = *v - } - - if crd.Spec.Type == cosmosv1.Sentry && privvalSleep > 0 { - shellBody := fmt.Sprintf(`sleep %d -%s %s`, privvalSleep, binary, strings.Join(args, " ")) - return "sh", []string{"-c", shellBody} + Env: env, + ImagePullPolicy: tpl.ImagePullPolicy, + WorkingDir: workDir, + SecurityContext: &corev1.SecurityContext{}, + }) } - return binary, args -} - -func startCommandArgs(crd *cosmosv1.CosmosFullNode) []string { - args := []string{"start", "--home", ChainHomeDir(crd)} - cfg := crd.Spec.ChainSpec - if cfg.SkipInvariants { - args = append(args, "--x-crisis-skip-assert-invariants") - } - if lvl := cfg.LogLevel; lvl != nil { - args = append(args, "--log_level", *lvl) - } - if format := cfg.LogFormat; format != nil { - args = append(args, "--log_format", *format) - } - if len(crd.Spec.ChainSpec.AdditionalStartArgs) > 0 { - args = append(args, crd.Spec.ChainSpec.AdditionalStartArgs...) - } - return args + return required } func willRestoreFromSnapshot(crd *cosmosv1.CosmosFullNode) bool {