From e0bf77605497db56b3be7117f9fb32f1c7a8eb06 Mon Sep 17 00:00:00 2001 From: Andy Pliszka Date: Tue, 14 May 2024 15:58:38 -0400 Subject: [PATCH] feat: adds ChainType to support non Cosmos chains --- api/v1/cosmosfullnode_types.go | 15 +++++++++++++++ .../cosmos.strange.love_cosmosfullnodes.yaml | 9 +++++++++ internal/fullnode/pod_builder.go | 6 +++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/api/v1/cosmosfullnode_types.go b/api/v1/cosmosfullnode_types.go index 54f9be30..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 diff --git a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml index 69982006..de5e7bb2 100644 --- a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml +++ b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml @@ -365,6 +365,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/pod_builder.go b/internal/fullnode/pod_builder.go index e9317b1a..6fa0c4a0 100644 --- a/internal/fullnode/pod_builder.go +++ b/internal/fullnode/pod_builder.go @@ -111,7 +111,7 @@ func NewPodBuilder(crd *cosmosv1.CosmosFullNode) PodBuilder { }, } - if crd.Spec.ChainSpec.InitScript == nil && 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", @@ -361,7 +361,7 @@ func initContainers(crd *cosmosv1.CosmosFullNode, moniker string) []corev1.Conta }, } - if crd.Spec.ChainSpec.InitScript == nil { + if crd.Spec.ChainType == cosmosv1.Cosmos { mrg := []corev1.Container{ { Name: "config-merge", @@ -418,7 +418,7 @@ func initContainers(crd *cosmosv1.CosmosFullNode, moniker string) []corev1.Conta // 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. - if crd.Spec.ChainSpec.InitScript == nil { + if crd.Spec.ChainType == cosmosv1.Cosmos { required = append(required, corev1.Container{ Name: "version-check", Image: "ghcr.io/strangelove-ventures/cosmos-operator:" + version.DockerTag(),