Skip to content

Commit

Permalink
version check patch (#383)
Browse files Browse the repository at this point in the history
* use patch instead of update for height updates from version-check

* tidy

* fix test
  • Loading branch information
agouin authored Nov 6, 2023
1 parent ff3610b commit a2fbafa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
41 changes: 31 additions & 10 deletions cmd/versioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,8 @@ func checkVersion(
}
}

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

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

if err := kClient.Status().Update(
ctx, crd,
); 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 @@ -192,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
2 changes: 1 addition & 1 deletion internal/fullnode/rbac_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestBuildRBAC(t *testing.T) {
{
APIGroups: []string{"cosmos.strange.love"},
Resources: []string{"cosmosfullnodes/status"},
Verbs: []string{"update"},
Verbs: []string{"patch"},
},
}, role.Rules)

Expand Down

0 comments on commit a2fbafa

Please sign in to comment.