Skip to content

Commit

Permalink
fix(upgrade): make upgrade tool to work with non-acl cluster (#7674)
Browse files Browse the repository at this point in the history
For the upgrade in versions <= 20.07, dgraph upgrade tool updates the acl relates data. Hence, it had --acl flag. With the update of the upgrade tool for 21.03, it should work without ACL as well. This PR adds that support.
  • Loading branch information
NamanJain8 authored Apr 1, 2021
1 parent 0f59807 commit dded71f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
8 changes: 4 additions & 4 deletions upgrade/change_v21.03.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func dropDeprecated(dg *dgo.Dgraph) error {
}

func upgradePersitentQuery() error {
dg, cb := x.GetDgraphClient(Upgrade.Conf, true)
dg, cb := x.GetDgraphClient(Upgrade.Conf, hasAclCreds())
defer cb()

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

func upgradeCORS() error {
dg, cb := x.GetDgraphClient(Upgrade.Conf, true)
dg, cb := x.GetDgraphClient(Upgrade.Conf, hasAclCreds())
defer cb()

jwt, err := getAccessJwt()
Expand All @@ -215,7 +215,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 +239,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
7 changes: 7 additions & 0 deletions upgrade/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ import (
"github.com/pkg/errors"
)

func hasAclCreds() bool {
return len(Upgrade.Conf.GetString(user)) > 0
}

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

0 comments on commit dded71f

Please sign in to comment.