Skip to content

Commit

Permalink
Loosen the DC/OS version check
Browse files Browse the repository at this point in the history
Currently it only accepts DC/OS 1.XX. This uses a library instead of a
regex for more flexibility.

It also avoids false-positive by just printing a warning if we can't
parse the version for some reason. It might then still be possible for
the setup flow to install the default plugins, through Cosmos for example.
  • Loading branch information
bamarni committed Sep 2, 2019
1 parent 3d411de commit 064b8b9
Show file tree
Hide file tree
Showing 12 changed files with 1,089 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -17,6 +17,7 @@ require (
github.com/go-openapi/strfmt v0.19.0 // indirect
github.com/go-openapi/swag v0.19.0 // indirect
github.com/go-openapi/validate v0.19.0 // indirect
github.com/hashicorp/go-version v1.2.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pty v1.1.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -70,6 +70,8 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
27 changes: 25 additions & 2 deletions pkg/setup/setup.go
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/dcos/dcos-cli/pkg/mesos"
"github.com/dcos/dcos-cli/pkg/plugin"
"github.com/dcos/dcos-cli/pkg/prompt"
goversion "github.com/hashicorp/go-version"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/vbauerster/mpb"
Expand Down Expand Up @@ -295,8 +296,8 @@ func (s *Setup) installDefaultPlugins(httpClient *httpclient.Client) error {
return fmt.Errorf("unable to get DC/OS version, installation of the plugins aborted: %s", err)
}

if regexp.MustCompile(`^1\.[7-9]\D*`).MatchString(version.Version) {
return errors.New("DC/OS version of the cluster < 1.10, installation of the plugins aborted")
if err = s.checkDefaultPluginsRequirements(version.Version); err != nil {
return err
}

var wg sync.WaitGroup
Expand Down Expand Up @@ -526,3 +527,25 @@ Do you trust it? [y/n] `
fingerprintBuf.String(),
), "")
}

// checkDefaultPluginsRequirements makes sure the default plugins can be installed.
//
// Currently the only requirement is to have DC/OS 1.10 or greater.
func (s *Setup) checkDefaultPluginsRequirements(version string) error {
minVersion, err := goversion.NewVersion("1.10")
if err != nil {
return err
}

clusterVersion, err := goversion.NewVersion(version)
if err != nil {
// To avoid false-positives, we don't fail in case the cluster version cannot be parsed.
s.logger.Warnf(`Couldn't parse DC/OS version "%s".`, version)
return nil
}

if clusterVersion.LessThan(minVersion) {
return errors.New("DC/OS version of the cluster < 1.10, installation of the plugins aborted")
}
return nil
}
25 changes: 25 additions & 0 deletions pkg/setup/setup_test.go
Expand Up @@ -5,6 +5,8 @@ import (
"net/http/httptest"
"testing"

"github.com/sirupsen/logrus"
logrustest "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -22,3 +24,26 @@ func TestCanonicalURLHostCase(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "https://www.example.org", canonicalURL)
}

func TestDefaultPluginsRequirements(t *testing.T) {
logger, hook := logrustest.NewNullLogger()
flow := New(Opts{
Logger: logger,
})

require.Error(t, flow.checkDefaultPluginsRequirements("1.7.5"))
require.Error(t, flow.checkDefaultPluginsRequirements("1.8.4"))
require.Error(t, flow.checkDefaultPluginsRequirements("1.9.3"))

require.NoError(t, flow.checkDefaultPluginsRequirements("1.10.0"))
require.NoError(t, flow.checkDefaultPluginsRequirements("1.11.4"))
require.NoError(t, flow.checkDefaultPluginsRequirements("1.12.2"))
require.NoError(t, flow.checkDefaultPluginsRequirements("1.13.1"))
require.NoError(t, flow.checkDefaultPluginsRequirements("2.0.0-alpha"))
require.NoError(t, flow.checkDefaultPluginsRequirements("2.0.74"))

require.NoError(t, flow.checkDefaultPluginsRequirements("V3"))
entry := hook.LastEntry()
require.Equal(t, logrus.WarnLevel, entry.Level)
require.Equal(t, `Couldn't parse DC/OS version "V3".`, entry.Message)
}
13 changes: 13 additions & 0 deletions vendor/github.com/hashicorp/go-version/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 064b8b9

Please sign in to comment.