Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version check patch #383

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading