From 5fa45dafcb5738d24984cb484338d3ded37e8b21 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Wed, 18 Oct 2023 02:39:23 -0600 Subject: [PATCH] use separate status map --- api/v1/cosmosfullnode_types.go | 4 ++++ api/v1/zz_generated.deepcopy.go | 7 +++++++ cmd/versioncheck.go | 18 +++++++----------- .../cosmos.strange.love_cosmosfullnodes.yaml | 6 ++++++ internal/fullnode/build_pods.go | 3 +++ internal/fullnode/configmap_builder.go | 3 +++ internal/fullnode/rbac_builder.go | 2 +- 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/api/v1/cosmosfullnode_types.go b/api/v1/cosmosfullnode_types.go index 6ea60ecf..39fe5b79 100644 --- a/api/v1/cosmosfullnode_types.go +++ b/api/v1/cosmosfullnode_types.go @@ -141,6 +141,10 @@ type FullNodeStatus struct { // Current sync information. Collected every 60s. // +optional SyncInfo *SyncInfoStatus `json:"syncInfo,omitempty"` + + // Startup information. collected when node starts up. + // +optional + StartupHeight map[string]uint64 `json:"startupInfo,omitempty"` } type SyncInfoStatus struct { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 33c8f467..13c062cb 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -342,6 +342,13 @@ func (in *FullNodeStatus) DeepCopyInto(out *FullNodeStatus) { *out = new(SyncInfoStatus) (*in).DeepCopyInto(*out) } + if in.StartupHeight != nil { + in, out := &in.StartupHeight, &out.StartupHeight + *out = make(map[string]uint64, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FullNodeStatus. diff --git a/cmd/versioncheck.go b/cmd/versioncheck.go index 766292f0..2e32f19f 100644 --- a/cmd/versioncheck.go +++ b/cmd/versioncheck.go @@ -6,7 +6,6 @@ package cmd import ( "fmt" "os" - "time" "cosmossdk.io/log" "cosmossdk.io/store/rootmulti" @@ -106,17 +105,14 @@ func VersionCheckCmd(scheme *runtime.Scheme) *cobra.Command { height := store.LatestVersion() fmt.Printf("%d", height) - if err := kClient.Status().Patch( + if crd.Status.StartupHeight == nil { + crd.Status.StartupHeight = make(map[string]uint64) + } + + crd.Status.StartupHeight[thisPod.Name] = uint64(height) + + if err := kClient.Status().Update( ctx, crd, - client.RawPatch( - types.MergePatchType, - []byte(fmt.Sprintf( - `{"syncInfo":{"pods":[{"pod":"%s","time":"%s","height":%d,"inSync": false}]}}`, - thisPod.Name, - time.Now().Format(time.RFC3339), - height, - )), - ), ); err != nil { panic(fmt.Errorf("failed to patch status: %w", err)) } diff --git a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml index b3f8ee18..5ee7a58f 100644 --- a/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml +++ b/config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml @@ -5995,6 +5995,12 @@ spec: - requestedSize type: object type: object + startupInfo: + additionalProperties: + format: int64 + type: integer + description: Startup information. collected when node starts up. + type: object status: description: A generic message for the user. May contain errors. type: string diff --git a/internal/fullnode/build_pods.go b/internal/fullnode/build_pods.go index 64c4c160..21f63f83 100644 --- a/internal/fullnode/build_pods.go +++ b/internal/fullnode/build_pods.go @@ -27,6 +27,9 @@ func BuildPods(crd *cosmosv1.CosmosFullNode, cksums ConfigChecksums) ([]diff.Res } if len(crd.Spec.ChainSpec.Versions) > 0 { instanceHeight := uint64(0) + if startupHeight, ok := crd.Status.StartupHeight[pod.Name]; ok { + instanceHeight = startupHeight + } for _, instance := range crd.Status.SyncInfo.Pods { if instance.Pod == pod.Name { if instance.Height == nil { diff --git a/internal/fullnode/configmap_builder.go b/internal/fullnode/configmap_builder.go index 352d4a84..f389c3c8 100644 --- a/internal/fullnode/configmap_builder.go +++ b/internal/fullnode/configmap_builder.go @@ -41,6 +41,9 @@ func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource appCfg := crd.Spec.ChainSpec.App if len(crd.Spec.ChainSpec.Versions) > 0 { instanceHeight := uint64(0) + if startupHeight, ok := crd.Status.StartupHeight[instance]; ok { + instanceHeight = startupHeight + } for _, v := range crd.Status.SyncInfo.Pods { if v.Pod == instance { if v.Height != nil { diff --git a/internal/fullnode/rbac_builder.go b/internal/fullnode/rbac_builder.go index e081b92f..876318fe 100644 --- a/internal/fullnode/rbac_builder.go +++ b/internal/fullnode/rbac_builder.go @@ -72,7 +72,7 @@ func BuildRoles(crd *cosmosv1.CosmosFullNode) []diff.Resource[*rbacv1.Role] { { APIGroups: []string{"cosmos.strange.love"}, Resources: []string{"cosmosfullnodes/status"}, - Verbs: []string{"patch"}, + Verbs: []string{"update"}, }, }, }