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

fix(upgrade): make upgrade tool to work with non-acl cluster #7674

Merged
merged 2 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions upgrade/change_v21.03.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func dropDeprecated(dg *dgo.Dgraph) error {
}

func upgradePersitentQuery() error {
dg, cb := x.GetDgraphClient(Upgrade.Conf, true)
login := len(Upgrade.Conf.GetString(user)) > 0
dg, cb := x.GetDgraphClient(Upgrade.Conf, login)
defer cb()

jwt, err := getAccessJwt()
Expand Down Expand Up @@ -205,7 +206,8 @@ func upgradePersitentQuery() error {
}

func upgradeCORS() error {
dg, cb := x.GetDgraphClient(Upgrade.Conf, true)
login := len(Upgrade.Conf.GetString(user)) > 0
dg, cb := x.GetDgraphClient(Upgrade.Conf, login)
defer cb()

jwt, err := getAccessJwt()
Expand All @@ -215,7 +217,7 @@ func upgradeCORS() error {

// Get CORS.
corsData := make(map[string][]cors)
if err = getQueryResult(dg, queryCORS_v21_03_0, &corsData); err != nil {
if err := getQueryResult(dg, queryCORS_v21_03_0, &corsData); err != nil {
return errors.Wrap(err, "error querying cors")
}

Expand All @@ -239,7 +241,7 @@ func upgradeCORS() error {

// Get GraphQL schema.
schemaData := make(map[string][]sch)
if err = getQueryResult(dg, querySchema_v21_03_0, &schemaData); err != nil {
if err := getQueryResult(dg, querySchema_v21_03_0, &schemaData); err != nil {
return errors.Wrap(err, "error querying graphql schema")
}

Expand Down
16 changes: 1 addition & 15 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var (
type versionComparisonResult uint8

const (
acl = "acl"
dryRun = "dry-run"
alpha = "alpha"
slashGrpc = "slash_grpc_endpoint"
Expand Down Expand Up @@ -151,9 +150,9 @@ func init() {
},
Annotations: map[string]string{"group": "tool"},
}
Upgrade.EnvPrefix = "DGRAPH_UPGRADE"
Upgrade.Cmd.SetHelpTemplate(x.NonRootTemplate)
flag := Upgrade.Cmd.Flags()
flag.Bool(acl, false, "upgrade ACL from v1.2.2 to >=v20.03.0")
flag.Bool(dryRun, false, "dry-run the upgrade")
flag.StringP(alpha, "a", "127.0.0.1:9080",
"Comma separated list of Dgraph Alpha gRPC server address")
Expand Down Expand Up @@ -188,24 +187,11 @@ func run() {
}

func validateAndParseInput() (*commandInput, error) {
if !Upgrade.Conf.GetBool(acl) {
return nil, formatAsFlagParsingError(acl,
fmt.Errorf("we only support acl upgrade as of now"))
}

_, _, err := net.SplitHostPort(strings.TrimSpace(Upgrade.Conf.GetString(alpha)))
if err != nil {
return nil, formatAsFlagParsingError(alpha, err)
}

if strings.TrimSpace(Upgrade.Conf.GetString(user)) == "" {
return nil, formatAsFlagRequiredError(user)
}

if strings.TrimSpace(Upgrade.Conf.GetString(password)) == "" {
return nil, formatAsFlagRequiredError(password)
}

fromVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(from))
if err != nil {
return nil, formatAsFlagParsingError(from, err)
Expand Down
3 changes: 3 additions & 0 deletions upgrade/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (

// getAccessJwt gets the access jwt token from by logging into the cluster.
func getAccessJwt() (*api.Jwt, error) {
if len(Upgrade.Conf.GetString(user)) == 0 {
return &api.Jwt{}, nil
}
user := Upgrade.Conf.GetString(user)
password := Upgrade.Conf.GetString(password)
header := http.Header{}
Expand Down