mvu: optionally skip drift check in autoupgrade (#53992)

Previously we ignored drift in autougprade and performed an upgrade
anyway. This PR adds another env var SRC_AUTOUPGRADE_IGNORE_DRIFT that
defaults to false, which acts like how enabling auto-upgrade via the UI
works (disallowed until drift is resolved)

## Test plan


![image](https://github.com/sourcegraph/sourcegraph/assets/18282288/b33fc37d-60de-4264-83bc-b822b2a6e034)
This commit is contained in:
Noah S-C 2023-06-26 14:11:18 +01:00 committed by GitHub
parent b28444350f
commit b601bbeaaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 24 deletions

View File

@ -234,7 +234,6 @@ go_library(
"//cmd/frontend/internal/processrestart",
"//cmd/frontend/internal/search/logs",
"//cmd/frontend/internal/siteid",
"//cmd/migrator/shared",
"//enterprise/cmd/worker/shared/sourcegraphoperator",
"//internal/actor",
"//internal/adminanalytics",

View File

@ -18,7 +18,6 @@ import (
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app/updatecheck"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/siteid"
migratorshared "github.com/sourcegraph/sourcegraph/cmd/migrator/shared"
"github.com/sourcegraph/sourcegraph/internal/actor"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/auth"
@ -338,7 +337,7 @@ var devSchemaFactory = schemas.NewExpectedSchemaFactory(
)
var schemaFactories = append(
migratorshared.DefaultSchemaFactories,
schemas.DefaultSchemaFactories,
// Special schema factory for dev environment.
devSchemaFactory,
)

View File

@ -49,7 +49,6 @@ go_library(
"//internal/database/dbconn",
"//internal/database/dbutil",
"//internal/database/migration",
"//internal/database/migration/cliutil",
"//internal/database/migration/multiversion",
"//internal/database/migration/runner",
"//internal/database/migration/schemas",

View File

@ -15,7 +15,6 @@ import (
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
connections "github.com/sourcegraph/sourcegraph/internal/database/connections/live"
"github.com/sourcegraph/sourcegraph/internal/database/migration"
"github.com/sourcegraph/sourcegraph/internal/database/migration/cliutil"
"github.com/sourcegraph/sourcegraph/internal/database/migration/multiversion"
"github.com/sourcegraph/sourcegraph/internal/database/migration/runner"
"github.com/sourcegraph/sourcegraph/internal/database/migration/schemas"
@ -56,7 +55,7 @@ func tryAutoUpgrade(ctx context.Context, obsvCtx *observation.Context, ready ser
} else if err != nil {
return errors.Wrap(err, "autoupgradestore.GetAutoUpgrade")
}
if !dbShouldAutoUpgrade && !cliutil.EnvShouldAutoUpgrade {
if !dbShouldAutoUpgrade && !multiversion.EnvShouldAutoUpgrade {
return nil
}
@ -195,12 +194,12 @@ func runMigration(
runner.ApplyPrivilegedMigrations,
nil, // only needed when ^ is NoopPrivilegedMigrations
true,
true,
multiversion.EnvAutoUpgradeSkipDrift,
false,
true,
false,
registerMigrators,
nil, // only needed for drift
schemas.DefaultSchemaFactories,
out,
)
}

View File

@ -23,14 +23,6 @@ const appName = "migrator"
var out = output.NewOutput(os.Stdout, output.OutputOpts{})
// DefaultSchemaFactories is a list of schema factories to be used in
// non-exceptional cases.
var DefaultSchemaFactories = []schemas.ExpectedSchemaFactory{
schemas.LocalExpectedSchemaFactory,
schemas.GitHubExpectedSchemaFactory,
schemas.GCSExpectedSchemaFactory,
}
func Start(logger log.Logger, registerEnterpriseMigrators store.RegisterMigratorsUsingConfAndStoreFactoryFunc) error {
observationCtx := observation.NewContext(logger)
@ -58,10 +50,10 @@ func Start(logger log.Logger, registerEnterpriseMigrators store.RegisterMigrator
cliutil.DownTo(appName, newRunner, outputFactory, false),
cliutil.Validate(appName, newRunner, outputFactory),
cliutil.Describe(appName, newRunner, outputFactory),
cliutil.Drift(appName, newRunner, outputFactory, false, DefaultSchemaFactories...),
cliutil.Drift(appName, newRunner, outputFactory, false, schemas.DefaultSchemaFactories...),
cliutil.AddLog(appName, newRunner, outputFactory),
cliutil.Upgrade(appName, newRunnerWithSchemas, outputFactory, registerMigrators, DefaultSchemaFactories...),
cliutil.Downgrade(appName, newRunnerWithSchemas, outputFactory, registerMigrators, DefaultSchemaFactories...),
cliutil.Upgrade(appName, newRunnerWithSchemas, outputFactory, registerMigrators, schemas.DefaultSchemaFactories...),
cliutil.Downgrade(appName, newRunnerWithSchemas, outputFactory, registerMigrators, schemas.DefaultSchemaFactories...),
cliutil.RunOutOfBandMigrations(appName, newRunner, outputFactory, registerMigrators),
},
}

View File

@ -31,7 +31,6 @@ go_library(
"//internal/database/migration/runner",
"//internal/database/migration/schemas",
"//internal/database/migration/store",
"//internal/env",
"//internal/observation",
"//internal/oobmigration",
"//internal/oobmigration/migrations",

View File

@ -8,9 +8,9 @@ import (
"github.com/jackc/pgerrcode"
"github.com/urfave/cli/v2"
"github.com/sourcegraph/sourcegraph/internal/database/migration/multiversion"
"github.com/sourcegraph/sourcegraph/internal/database/migration/runner"
"github.com/sourcegraph/sourcegraph/internal/database/migration/store"
"github.com/sourcegraph/sourcegraph/internal/env"
"github.com/sourcegraph/sourcegraph/internal/oobmigration"
"github.com/sourcegraph/sourcegraph/internal/version"
"github.com/sourcegraph/sourcegraph/internal/version/upgradestore"
@ -18,8 +18,6 @@ import (
"github.com/sourcegraph/sourcegraph/lib/output"
)
var EnvShouldAutoUpgrade = env.MustGetBool("SRC_AUTOUPGRADE", false, "If you forgot to set intent to autoupgrade before shutting down the instance, set this env var.")
func Up(commandName string, factory RunnerFactory, outFactory OutputFactory, development bool) *cli.Command {
schemaNamesFlag := &cli.StringSliceFlag{
Name: "schema",
@ -124,7 +122,7 @@ func Up(commandName string, factory RunnerFactory, outFactory OutputFactory, dev
return err
}
if EnvShouldAutoUpgrade || dbShouldAutoUpgrade {
if multiversion.EnvShouldAutoUpgrade || dbShouldAutoUpgrade {
out.WriteLine(output.Emoji(output.EmojiInfo, "Auto-upgrade flag is set, delegating upgrade to frontend instance"))
return nil
}

View File

@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "multiversion",
srcs = [
"autoupgrade.go",
"drift.go",
"plan.go",
"run.go",
@ -18,6 +19,7 @@ go_library(
"//internal/database/migration/schemas",
"//internal/database/migration/shared",
"//internal/database/migration/store",
"//internal/env",
"//internal/observation",
"//internal/oobmigration",
"//internal/oobmigration/migrations",

View File

@ -0,0 +1,8 @@
package multiversion
import "github.com/sourcegraph/sourcegraph/internal/env"
var (
EnvShouldAutoUpgrade = env.MustGetBool("SRC_AUTOUPGRADE", false, "If you forgot to set intent to autoupgrade before shutting down the instance, or you're upgrading from pre-5.1, set this env var.")
EnvAutoUpgradeSkipDrift = env.MustGetBool("SRC_AUTOUPGRADE_IGNORE_DRIFT", false, "Skip drift checking when performing an autoupgrade.")
)

View File

@ -13,6 +13,14 @@ import (
"github.com/sourcegraph/sourcegraph/lib/errors"
)
// DefaultSchemaFactories is a list of schema factories to be used in
// non-exceptional cases.
var DefaultSchemaFactories = []ExpectedSchemaFactory{
LocalExpectedSchemaFactory,
GitHubExpectedSchemaFactory,
GCSExpectedSchemaFactory,
}
// ExpectedSchemaFactory converts the given filename and version into a schema description, calling on some
// external persistent source. When invoked, this function should return a self-describing name, which notably
// should include _where_ the factory looked for easier debugging on failure, the schema description, and any