Skip to content

Commit

Permalink
Remove direct dependency on github.com/hashicorp/go-version (#43735) (#…
Browse files Browse the repository at this point in the history
…43744)

Teleport had 3 dependencies to parse semantic versions:
- golang.org/x/mod/semver
- github.com/coreos/go-semver/semver
- github.com/hashicorp/go-version

The last of the three was only used in `integrations/lib.AssertServerVersion`
which was a clone of `lib/utils.CheckVersion`. By converting all
code in integrations to use `lib/utils.CheckVersion` the direct
dependency on github.com/hashicorp/go-version can be dropped. The
depguard rules have also been updated to prevent it from sneaking
back into the dependency tree. A follow up change will further
consolidate semver dependencies to a single package.
  • Loading branch information
rosstimothy authored Jul 2, 2024
1 parent a47b407 commit 2b76656
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 51 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ linters-settings:
desc: 'use "github.com/sirupsen/logrus" instead'
- pkg: go.uber.org/atomic
desc: 'use "sync/atomic" instead'
- pkg: golang.design
desc: 'experimental project, not to be confused with official Go packages'
- pkg: github.com/hashicorp/go-version
desc: 'use "golang.org/x/mod/semver" or "coreos/go-semver/semver" instead'
gci:
sections:
- standard # Standard section: captures all standard packages.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ require (
github.com/gravitational/ttlmap v0.0.0-20171116003245-91fd36b9004c
github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2 v2.0.0-rc.3
github.com/guptarohit/asciigraph v0.5.6
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/golang-lru/v2 v2.0.6
github.com/icza/mjpeg v0.0.0-20220812133530-f79265a232f2
github.com/jackc/pgconn v1.14.3
Expand Down Expand Up @@ -332,6 +331,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down
3 changes: 2 additions & 1 deletion integrations/access/common/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/gravitational/teleport/integrations/access/common/teleport"
"github.com/gravitational/teleport/integrations/lib"
"github.com/gravitational/teleport/integrations/lib/logger"
"github.com/gravitational/teleport/lib/utils"
)

const (
Expand Down Expand Up @@ -94,7 +95,7 @@ func (a *BaseApp) checkTeleportVersion(ctx context.Context) (proto.PingResponse,
}
return pong, trace.Wrap(err, "Unable to get Teleport server version")
}
err = lib.AssertServerVersion(pong, minServerVersion)
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
return pong, trace.Wrap(err)
}

Expand Down
3 changes: 2 additions & 1 deletion integrations/access/jira/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/gravitational/teleport/integrations/lib/backoff"
"github.com/gravitational/teleport/integrations/lib/logger"
"github.com/gravitational/teleport/integrations/lib/watcherjob"
"github.com/gravitational/teleport/lib/utils"
)

const (
Expand Down Expand Up @@ -233,7 +234,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
log.Error("Unable to get Teleport server version")
return pong, trace.Wrap(err)
}
err = lib.AssertServerVersion(pong, minServerVersion)
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
return pong, trace.Wrap(err)
}

Expand Down
3 changes: 2 additions & 1 deletion integrations/access/opsgenie/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/gravitational/teleport/integrations/lib/backoff"
"github.com/gravitational/teleport/integrations/lib/logger"
"github.com/gravitational/teleport/integrations/lib/watcherjob"
"github.com/gravitational/teleport/lib/utils"
)

const (
Expand Down Expand Up @@ -168,7 +169,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
log.Error("Unable to get Teleport server version")
return pong, trace.Wrap(err)
}
err = lib.AssertServerVersion(pong, minServerVersion)
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
return pong, trace.Wrap(err)
}

Expand Down
3 changes: 2 additions & 1 deletion integrations/access/pagerduty/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/gravitational/teleport/integrations/lib/backoff"
"github.com/gravitational/teleport/integrations/lib/logger"
"github.com/gravitational/teleport/integrations/lib/watcherjob"
"github.com/gravitational/teleport/lib/utils"
)

const (
Expand Down Expand Up @@ -186,7 +187,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
log.Error("Unable to get Teleport server version")
return pong, trace.Wrap(err)
}
err = lib.AssertServerVersion(pong, minServerVersion)
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
return pong, trace.Wrap(err)
}

Expand Down
3 changes: 2 additions & 1 deletion integrations/access/servicenow/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/gravitational/teleport/integrations/lib/backoff"
"github.com/gravitational/teleport/integrations/lib/logger"
"github.com/gravitational/teleport/integrations/lib/watcherjob"
"github.com/gravitational/teleport/lib/utils"
)

const (
Expand Down Expand Up @@ -180,7 +181,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
log.Error("Unable to get Teleport server version")
return pong, trace.Wrap(err)
}
err = lib.AssertServerVersion(pong, minServerVersion)
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
return pong, trace.Wrap(err)
}

Expand Down
12 changes: 6 additions & 6 deletions integrations/lib/testing/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"sync"
"time"

"github.com/coreos/go-semver/semver"
"github.com/gravitational/trace"
"github.com/hashicorp/go-version"
"google.golang.org/grpc"

"github.com/gravitational/teleport/api/client"
Expand All @@ -47,7 +47,7 @@ import (
const IntegrationAdminRole = "integration-admin"
const DefaultLicensePath = "/var/lib/teleport/license.pem"

var regexpVersion = regexp.MustCompile(`^Teleport( Enterprise)? ([^ ]+)`)
var regexpVersion = regexp.MustCompile(`^Teleport( Enterprise)? v([^ ]+)`)

type Integration struct {
mu sync.Mutex
Expand Down Expand Up @@ -85,7 +85,7 @@ type Service interface {
}

type Version struct {
*version.Version
*semver.Version
IsEnterprise bool
}

Expand All @@ -97,12 +97,12 @@ type SignTLSPaths struct {

const serviceShutdownTimeout = 10 * time.Second

func requireBinaryVersion(ctx context.Context, path string, targetVersion *version.Version) error {
func requireBinaryVersion(ctx context.Context, path string, targetVersion *semver.Version) error {
v, err := getBinaryVersion(ctx, path)
if err != nil {
return trace.Wrap(err, "failed to get %s version", filepath.Base(path))
}
if !targetVersion.Equal(v.Version) {
if !targetVersion.Equal(*v.Version) {
return trace.Errorf("%s version %s does not match target version %s", filepath.Base(path), v.Version, targetVersion)
}

Expand Down Expand Up @@ -522,7 +522,7 @@ func getBinaryVersion(ctx context.Context, binaryPath string) (Version, error) {
return Version{}, trace.Wrap(err)
}

version, err := version.NewVersion(submatch[2])
version, err := semver.NewVersion(submatch[2])
if err != nil {
return Version{}, trace.Wrap(err)
}
Expand Down
39 changes: 0 additions & 39 deletions integrations/lib/versions.go

This file was deleted.

0 comments on commit 2b76656

Please sign in to comment.