Skip to content

Commit

Permalink
skip version check if versions are not populated in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Oct 18, 2023
1 parent 80e6251 commit a881273
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions cmd/versioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ func VersionCheckCmd() *cobra.Command {
Short: "Confirm correct image used for current node height",
Long: `Open the Cosmos SDK chain database, get the height, update the crd status with the height, then check the image for the height and panic if it is incorrect.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("height called")

dataDir := os.Getenv("DATA_DIR")
backend, _ := cmd.Flags().GetString(flagBackend)

s, err := os.Stat(dataDir)
if err != nil {
panic(fmt.Errorf("failed to stat %s: %w", dataDir, err))
}

if !s.IsDir() {
panic(fmt.Errorf("%s is not a directory", dataDir))
}

db, err := dbm.NewDB("application", getBackend(backend), dataDir)
if err != nil {
panic(fmt.Errorf("failed to open db: %w", err))
}

store := rootmulti.NewStore(db, log.NewNopLogger(), nil)

height := store.LatestVersion()
fmt.Printf("%d", height)

nsbz, err := os.ReadFile(namespaceFile)
if err != nil {
panic(fmt.Errorf("failed to read namespace from service account: %w", err))
Expand Down Expand Up @@ -100,6 +76,33 @@ func VersionCheckCmd() *cobra.Command {
panic(fmt.Errorf("failed to get crd: %w", err))
}

if len(crd.Spec.ChainSpec.Versions) == 0 {
fmt.Println("No versions specified, skipping version check")
return
}

dataDir := os.Getenv("DATA_DIR")
backend, _ := cmd.Flags().GetString(flagBackend)

s, err := os.Stat(dataDir)
if err != nil {
panic(fmt.Errorf("failed to stat %s: %w", dataDir, err))
}

if !s.IsDir() {
panic(fmt.Errorf("%s is not a directory", dataDir))
}

db, err := dbm.NewDB("application", getBackend(backend), dataDir)
if err != nil {
panic(fmt.Errorf("failed to open db: %w", err))
}

store := rootmulti.NewStore(db, log.NewNopLogger(), nil)

height := store.LatestVersion()
fmt.Printf("%d", height)

if err := kClient.Status().Patch(
ctx, crd,
client.RawPatch(
Expand Down

0 comments on commit a881273

Please sign in to comment.