Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 6, 2023
1 parent 9410556 commit 367ca8a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 31 additions & 11 deletions cmd/versioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,8 @@ func checkVersion(
}
}

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

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

if err := kClient.Status().Patch(
ctx, patch, client.StrategicMergeFrom(crd.DeepCopy()),
); err != nil {
return fmt.Errorf("failed to patch status: %w", err)
if err := patchStatusHeightIfNecessary(ctx, kClient, crd, thisPod.Name, uint64(height)); err != nil {
return err
}

var image string
Expand All @@ -193,6 +184,35 @@ func checkVersion(
return nil
}

func patchStatusHeightIfNecessary(
ctx context.Context,
kClient client.Client,
crd *cosmosv1.CosmosFullNode,
instanceName string,
height uint64,
) error {
if crd.Status.Height != nil {
if h, ok := crd.Status.Height[instanceName]; ok && h == height {
// Status is up to date already.
return nil
}
}

patch := crd.DeepCopy()
if patch.Status.Height == nil {
patch.Status.Height = make(map[string]uint64)
}
patch.Status.Height[instanceName] = height

if err := kClient.Status().Patch(
ctx, patch, client.MergeFrom(crd.DeepCopy()),
); err != nil {
return fmt.Errorf("failed to patch status: %w", err)
}

return nil
}

func getBackend(backend string) dbm.BackendType {
switch backend {
case "goleveldb":
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{"update"},
Verbs: []string{"patch"},
},
},
}
Expand Down

0 comments on commit 367ca8a

Please sign in to comment.