Skip to content

Commit

Permalink
fix scheme, reconcile heights
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Oct 18, 2023
1 parent 2d2d54a commit 5616659
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ type ChainSpec struct {

type ChainVersion struct {
// UpgradeHeight is the block height when this version is applied.
UpgradeHeight uint64 `json:"minHeight"`
UpgradeHeight uint64 `json:"height"`

// Image is the docker image for this version in "repository:tag" format. E.g. busybox:latest.
Image string `json:"image"`
Expand Down
10 changes: 3 additions & 7 deletions cmd/versioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"
cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -30,7 +31,7 @@ const (
// It panics if the wrong image is specified for the pod for the height,
// restarting the pod so that the correct image is used from the patched height.
// this command is intended to be run as an init container.
func VersionCheckCmd() *cobra.Command {
func VersionCheckCmd(scheme *runtime.Scheme) *cobra.Command {
cmd := &cobra.Command{
Use: "versioncheck",
Short: "Confirm correct image used for current node height",
Expand Down Expand Up @@ -61,11 +62,6 @@ func VersionCheckCmd() *cobra.Command {

cosmosFullNodeName := thisPod.Labels["app.kubernetes.io/name"]

scheme, err := cosmosv1.SchemeBuilder.Build()
if err != nil {
panic(fmt.Errorf("failed to build scheme: %w", err))
}

kClient, err := client.New(config, client.Options{
Scheme: scheme,
})
Expand Down Expand Up @@ -113,7 +109,7 @@ func VersionCheckCmd() *cobra.Command {
if err := kClient.Status().Patch(
ctx, crd,
client.RawPatch(
types.StrategicMergePatchType,
types.MergePatchType,
[]byte(fmt.Sprintf(
`{"syncInfo":{"pods":[{"pod":"%s","time":"%s","height":%d,"inSync": false}]}}`,
thisPod.Name,
Expand Down
12 changes: 6 additions & 6 deletions config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,18 @@ spec:
specified in the pod spec.
items:
properties:
image:
description: Image is the docker image for this version
in "repository:tag" format. E.g. busybox:latest.
type: string
minHeight:
height:
description: UpgradeHeight is the block height when this
version is applied.
format: int64
type: integer
image:
description: Image is the docker image for this version
in "repository:tag" format. E.g. busybox:latest.
type: string
required:
- height
- image
- minHeight
type: object
type: array
required:
Expand Down
19 changes: 18 additions & 1 deletion controllers/cosmosfullnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,24 @@ func (r *CosmosFullNodeReconciler) updateStatus(ctx context.Context, crd *cosmos
status.Phase = crd.Status.Phase
status.StatusMessage = crd.Status.StatusMessage
status.Peers = crd.Status.Peers
status.SyncInfo = &consensus
if len(status.SyncInfo.Pods) != len(consensus.Pods) {
status.SyncInfo = &consensus
} else {
for i := range consensus.Pods {
if consensus.Pods[i].Height != nil {
status.SyncInfo.Pods[i].Height = consensus.Pods[i].Height
}
if consensus.Pods[i].InSync != nil {
status.SyncInfo.Pods[i].InSync = consensus.Pods[i].InSync
}
if consensus.Pods[i].Error != nil {
status.SyncInfo.Pods[i].Error = consensus.Pods[i].Error
}
if !consensus.Pods[i].Timestamp.IsZero() {
status.SyncInfo.Pods[i].Timestamp = consensus.Pods[i].Timestamp
}
}
}
}); err != nil {
log.FromContext(ctx).Error(err, "Failed to patch status")
}
Expand Down
7 changes: 6 additions & 1 deletion internal/fullnode/rbac_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ func BuildRoles(crd *cosmosv1.CosmosFullNode) []diff.Resource[*rbacv1.Role] {
{
APIGroups: []string{"cosmos.strange.love"},
Resources: []string{"cosmosfullnodes"},
Verbs: []string{"get", "list", "patch"},
Verbs: []string{"get"},
},
{
APIGroups: []string{"cosmos.strange.love"},
Resources: []string{"cosmosfullnodes/status"},
Verbs: []string{"patch"},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func rootCmd() *cobra.Command {

// Add subcommands here
root.AddCommand(opcmd.HealthCheckCmd())
root.AddCommand(opcmd.VersionCheckCmd())
root.AddCommand(opcmd.VersionCheckCmd(scheme))
root.AddCommand(&cobra.Command{
Short: "Print the version",
Use: "version",
Expand Down

0 comments on commit 5616659

Please sign in to comment.