Skip to content

Commit

Permalink
use new height map
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Oct 19, 2023
1 parent dcd6a4e commit 1f826cb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
4 changes: 2 additions & 2 deletions api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ type FullNodeStatus struct {
// +optional
SyncInfo *SyncInfoStatus `json:"syncInfo,omitempty"`

// Startup information. collected when node starts up.
// Latest Height information. collected when node starts up and when RPC is successfully queried.
// +optional
StartupHeight map[string]uint64 `json:"startupInfo,omitempty"`
Height map[string]uint64 `json:"height,omitempty"`
}

type SyncInfoStatus struct {
Expand Down
4 changes: 2 additions & 2 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmd/versioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func VersionCheckCmd(scheme *runtime.Scheme) *cobra.Command {
height := store.LatestVersion()
fmt.Printf("%d", height)

if crd.Status.StartupHeight == nil {
crd.Status.StartupHeight = make(map[string]uint64)
if crd.Status.Height == nil {
crd.Status.Height = make(map[string]uint64)
}

crd.Status.StartupHeight[thisPod.Name] = uint64(height)
crd.Status.Height[thisPod.Name] = uint64(height)

if err := kClient.Status().Update(
ctx, crd,
Expand Down
13 changes: 7 additions & 6 deletions config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5937,6 +5937,13 @@ spec:
status:
description: FullNodeStatus defines the observed state of CosmosFullNode
properties:
height:
additionalProperties:
format: int64
type: integer
description: Latest Height information. collected when node starts
up and when RPC is successfully queried.
type: object
observedGeneration:
description: The most recent generation observed by the controller.
format: int64
Expand Down Expand Up @@ -5995,12 +6002,6 @@ 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
8 changes: 8 additions & 0 deletions controllers/cosmosfullnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ func (r *CosmosFullNodeReconciler) updateStatus(ctx context.Context, crd *cosmos
status.StatusMessage = crd.Status.StatusMessage
status.Peers = crd.Status.Peers
status.SyncInfo = &consensus
for _, v := range consensus.Pods {
if v.Height != nil && *v.Height > 0 {
if status.Height == nil {
status.Height = make(map[string]uint64)
}
status.Height[v.Pod] = *v.Height
}
}
}); err != nil {
log.FromContext(ctx).Error(err, "Failed to patch status")
}
Expand Down
13 changes: 2 additions & 11 deletions internal/fullnode/build_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ 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 {
break
}
instanceHeight = *instance.Height
break
}
if height, ok := crd.Status.Height[pod.Name]; ok {
instanceHeight = height
}
var image string
for _, version := range crd.Spec.ChainSpec.Versions {
Expand Down
12 changes: 2 additions & 10 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,8 @@ 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 {
instanceHeight = *v.Height
}
break
}
if height, ok := crd.Status.Height[instance]; ok {
instanceHeight = height
}
haltHeight := uint64(0)
for i, v := range crd.Spec.ChainSpec.Versions {
Expand Down

0 comments on commit 1f826cb

Please sign in to comment.