From a881273e3c258812cf2fd9a40707fa3b953f98ed Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Wed, 18 Oct 2023 00:14:18 -0600 Subject: [PATCH] skip version check if versions are not populated in spec --- cmd/versioncheck.go | 51 ++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/cmd/versioncheck.go b/cmd/versioncheck.go index f0a01e6e..c5413f88 100644 --- a/cmd/versioncheck.go +++ b/cmd/versioncheck.go @@ -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)) @@ -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(