diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc new file mode 100644 index 000000000..e87170eec --- /dev/null +++ b/CHANGELOG.next.asciidoc @@ -0,0 +1,3 @@ +==== Bugfixes + +- Return a better error on enrolling and the Elasticsearch version is incompatible. {pull}1211[1211] diff --git a/cmd/fleet/main.go b/cmd/fleet/main.go index 8eeaaa104..7858086c4 100644 --- a/cmd/fleet/main.go +++ b/cmd/fleet/main.go @@ -15,11 +15,12 @@ import ( "sync" "time" - "github.com/elastic/go-ucfg" - "github.com/elastic/go-ucfg/yaml" "go.elastic.co/apm" apmtransport "go.elastic.co/apm/transport" + "github.com/elastic/go-ucfg" + "github.com/elastic/go-ucfg/yaml" + "github.com/elastic/fleet-server/v7/internal/pkg/action" "github.com/elastic/fleet-server/v7/internal/pkg/build" "github.com/elastic/fleet-server/v7/internal/pkg/bulk" @@ -41,14 +42,15 @@ import ( "github.com/elastic/fleet-server/v7/internal/pkg/status" "github.com/elastic/fleet-server/v7/internal/pkg/ver" - "github.com/elastic/elastic-agent-client/v7/pkg/client" - "github.com/elastic/elastic-agent-client/v7/pkg/proto" "github.com/hashicorp/go-version" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" + + "github.com/elastic/elastic-agent-client/v7/pkg/client" + "github.com/elastic/elastic-agent-client/v7/pkg/proto" ) const ( @@ -785,8 +787,11 @@ func (f *FleetServer) runSubsystems(ctx context.Context, cfg *config.Config, g * esCli := bulker.Client() // Check version compatibility with Elasticsearch - err = ver.CheckCompatibility(ctx, esCli, f.bi.Version) + remoteVersion, err := ver.CheckCompatibility(ctx, esCli, f.bi.Version) if err != nil { + if len(remoteVersion) != 0 { + return fmt.Errorf("failed version compatibility check with elasticsearch (Agent: %s, Elasticsearch: %s): %w", f.bi.Version, remoteVersion, err) + } return fmt.Errorf("failed version compatibility check with elasticsearch: %w", err) } diff --git a/internal/pkg/ver/check.go b/internal/pkg/ver/check.go index e504bf727..a577f2b4b 100644 --- a/internal/pkg/ver/check.go +++ b/internal/pkg/ver/check.go @@ -13,9 +13,10 @@ import ( esh "github.com/elastic/fleet-server/v7/internal/pkg/es" - "github.com/elastic/go-elasticsearch/v7" "github.com/hashicorp/go-version" "github.com/rs/zerolog/log" + + "github.com/elastic/go-elasticsearch/v7" ) var ( @@ -23,18 +24,18 @@ var ( ErrMalformedVersion = errors.New("malformed version") ) -func CheckCompatibility(ctx context.Context, esCli *elasticsearch.Client, fleetVersion string) error { +func CheckCompatibility(ctx context.Context, esCli *elasticsearch.Client, fleetVersion string) (string, error) { log.Debug().Str("fleet_version", fleetVersion).Msg("check version compatibility with elasticsearch") esVersion, err := esh.FetchESVersion(ctx, esCli) if err != nil { log.Error().Err(err).Msg("failed to fetch elasticsearch version") - return err + return "", err } log.Debug().Str("elasticsearch_version", esVersion).Msg("fetched elasticsearch version") - return checkCompatibility(fleetVersion, esVersion) + return esVersion, checkCompatibility(fleetVersion, esVersion) } func checkCompatibility(fleetVersion, esVersion string) error {