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

playground: ignore version check error in some cases #1495

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tiup/components/playground/instance"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/localdata"
"github.com/pingcap/tiup/pkg/logger/log"
Expand All @@ -47,6 +48,7 @@ import (
"github.com/spf13/pflag"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -233,6 +235,43 @@ Examples:
}
}()

// expand version string
if !semver.IsValid(options.Version) {
var version utils.Version
var err error
// If any of the binpath arguments is set (which indicates the user is
// using a self build binary) and version number is not set, we assume
// it is a developer and use the latest release version by default.
// The platform string used to resolve the full version number is set
// to "linux-amd64" as this is the platform that every released version
// is available.
// For platforms lacks of support for some versions, e.g., darwin-amd64,
// specifically set a valid version for it, or use custom binpath for
// all components used.
// If none of the binpath arguments is set, use the platform of the
// playground binary itself.
if options.TiDB.BinPath != "" || options.TiKV.BinPath != "" ||
options.PD.BinPath != "" || options.TiFlash.BinPath != "" ||
options.TiCDC.BinPath != "" || options.Pump.BinPath != "" ||
options.Drainer.BinPath != "" && options.Version == "" {
version, err = env.V1Repository().ResolveComponentVersionWithPlatform(spec.ComponentTiDB, options.Version, "linux-amd64")
} else {
version, err = env.V1Repository().ResolveComponentVersion(spec.ComponentTiDB, options.Version)
}
if err != nil {
return errors.Annotate(err, fmt.Sprintf("can not expand version %s to a valid semver string", options.Version))
}
fmt.Println(color.YellowString(`Using the version %s for version constraint "%s".
If you'd like to use a TiDB version other than %s, cancel and retry with the following arguments:
Specify version manually: tiup playground <version>
Specify version range: tiup playground ^5
The nightly version: tiup playground nightly
`, version, options.Version, version))

options.Version = version.String()
}

bootErr := p.bootCluster(ctx, env, options)
if bootErr != nil {
// always kill all process started and wait before quit.
Expand Down
16 changes: 0 additions & 16 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,22 +678,6 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme
return fmt.Errorf("all components count must be great than 0 (tikv=%v, pd=%v)", options.TiKV.Num, options.PD.Num)
}

{
version, err := env.V1Repository().ResolveComponentVersion(spec.ComponentTiDB, options.Version)
if err != nil {
return err
}
fmt.Println(color.YellowString(`Using the version %s for version constraint "%s".

If you'd like to use a TiDB version other than %s, cancel and retry with the following arguments:
Specify version manually: tiup playground <version>
Specify version range: tiup playground ^5
The nightly version: tiup playground nightly
`, version, options.Version, version))

options.Version = version.String()
}

if !utils.Version(options.Version).IsNightly() {
if semver.Compare(options.Version, "v3.1.0") < 0 && options.TiFlash.Num != 0 {
fmt.Println(color.YellowString("Warning: current version %s doesn't support TiFlash", options.Version))
Expand Down
21 changes: 13 additions & 8 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1
return vi, nil
}

// ResolveComponentVersion resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Version, error) {
// ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error) {
manifest, err := r.FetchComponentManifest(id, false)
if err != nil {
return "", err
Expand All @@ -765,16 +765,16 @@ func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Ver
}
ver = v.String()
case utils.NightlyVersionAlias:
if !manifest.HasNightly(r.PlatformString()) {
return "", errors.Annotatef(ErrUnknownVersion, "component %s does not have nightly on %s", id, r.PlatformString())
if !manifest.HasNightly(platform) {
return "", errors.Annotatef(ErrUnknownVersion, "component %s does not have nightly on %s", id, platform)
}
ver = manifest.Nightly
default:
cons, err := utils.NewConstraint(constraint)
if err != nil {
return "", err
}
versions := manifest.VersionList(r.PlatformString())
versions := manifest.VersionList(platform)
verList := make([]string, 0, len(versions))
for v := range versions {
if v == manifest.Nightly {
Expand All @@ -793,15 +793,20 @@ func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Ver
}
}
if ver == "" {
return "", fmt.Errorf(`no version on %s for component %s satisfies constraint "%s"`, r.PlatformString(), id, constraint)
return "", fmt.Errorf(`no version on %s for component %s satisfies constraint "%s"`, platform, id, constraint)
}
vi := manifest.VersionItem(r.PlatformString(), ver, false)
vi := manifest.VersionItem(platform, ver, false)
if vi == nil {
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", ver, r.PlatformString(), id)
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", ver, platform, id)
}
return utils.Version(ver), nil
}

// ResolveComponentVersion resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Version, error) {
return r.ResolveComponentVersionWithPlatform(id, constraint, r.PlatformString())
}

// LatestNightlyVersion returns the latest nightly version of specific component
func (r *V1Repository) LatestNightlyVersion(id string) (utils.Version, *v1manifest.VersionItem, error) {
com, err := r.FetchComponentManifest(id, false)
Expand Down