diff --git a/cmd/versioncheck.go b/cmd/versioncheck.go index 64e54b07..b642b84d 100644 --- a/cmd/versioncheck.go +++ b/cmd/versioncheck.go @@ -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 @@ -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": diff --git a/internal/fullnode/rbac_builder.go b/internal/fullnode/rbac_builder.go index 219e313b..6e4022a8 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{"update"}, + Verbs: []string{"patch"}, }, }, }