Skip to content

Commit

Permalink
use separate status map
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Oct 18, 2023
1 parent 5616659 commit 5fa45da
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 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.

18 changes: 7 additions & 11 deletions cmd/versioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"fmt"
"os"
"time"

"cosmossdk.io/log"
"cosmossdk.io/store/rootmulti"
Expand Down Expand Up @@ -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))
}
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/fullnode/build_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/fullnode/rbac_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
}
Expand Down

0 comments on commit 5fa45da

Please sign in to comment.