Skip to content

Commit

Permalink
chore(cli): Adding version validation to and
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Sep 20, 2024
1 parent 4147cb3 commit 706ea37
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
7 changes: 1 addition & 6 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ func setupVersion() {

func validateVersionMismatch() {
if !isVersionMatch && os.Getenv("TRACETEST_DEV") == "" {
fmt.Fprintf(os.Stderr, versionText+`
✖️ Error: Version Mismatch
The CLI version and the server version are not compatible. To fix this, you'll need to make sure that both your CLI and server are using compatible versions.
We recommend upgrading both of them to the latest available version. Check out our documentation https://docs.tracetest.io/configuration/upgrade for simple instructions on how to upgrade.
Thank you for using Tracetest! We apologize for any inconvenience caused.
`)
fmt.Fprintf(os.Stderr, versionText+config.ErrVersionMismatch.Error())
ExitCLI(1)
}
}
13 changes: 11 additions & 2 deletions cli/cmd/configure_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"context"
"errors"
"fmt"
"net/url"

agentConfig "github.com/kubeshop/tracetest/agent/config"
Expand All @@ -28,7 +30,7 @@ var configureCmd = &cobra.Command{
SkipVerify: skipVerify,
}

config, err := config.LoadConfig("")
cfg, err := config.LoadConfig("")
if err != nil {
return "", err
}
Expand All @@ -49,7 +51,14 @@ var configureCmd = &cobra.Command{
flags.OrganizationID = configParams.OrganizationID
}

return "", configurator.Start(ctx, &config, flags)
// early exit if the versions are not compatible
err = configurator.Start(ctx, &cfg, flags)
if errors.Is(err, config.ErrVersionMismatch) {
fmt.Println(err.Error())
ExitCLI(1)
}

return "", err
})),
PostRun: teardownCommand,
}
Expand Down
8 changes: 8 additions & 0 deletions cli/cmd/start_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"

agentConfig "github.com/kubeshop/tracetest/agent/config"
Expand Down Expand Up @@ -76,7 +78,13 @@ var startCmd = &cobra.Command{
cfg.EnvironmentID = flags.EnvironmentID
}

// early exit if the versions are not compatible
err = agentRunner.Run(ctx, cliLogger, cliConfig, flags, verbose)
if errors.Is(err, config.ErrVersionMismatch) {
fmt.Println(err.Error())
ExitCLI(1)
}

return "", err
})),
PostRun: teardownCommand,
Expand Down
15 changes: 15 additions & 0 deletions cli/config/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"errors"
"fmt"
"net/http"
"os"
Expand All @@ -18,6 +19,15 @@ import (

type onFinishFn func(context.Context, Config)

var (
ErrVersionMismatch = errors.New(`
✖️ Version Mismatch
The CLI version and the server version are not compatible. To fix this, you'll need to make sure that both your CLI and server are using compatible versions.
We recommend upgrading both of them to the latest available version. Check out our documentation https://docs.tracetest.io/configuration/upgrade for simple instructions on how to upgrade.
Thank you for using Tracetest! We apologize for any inconvenience caused`)
)

type Configurator struct {
logger *zap.Logger
resources *resourcemanager.Registry
Expand Down Expand Up @@ -106,6 +116,11 @@ func (c Configurator) Start(ctx context.Context, prev *Config, flags agentConfig
return nil
}

versionText, isMatching := GetVersion(ctx, cfg)
if !isMatching && os.Getenv("TRACETEST_DEV") == "" {
return fmt.Errorf("%s %w", versionText, ErrVersionMismatch)
}

if c.flags.CI {
c.logger.Debug("CI environment detected, skipping OAuth")
_, err = Save(ctx, cfg)
Expand Down

0 comments on commit 706ea37

Please sign in to comment.