forked from elastic/fleet-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax version checks for snapshot builds (elastic#3039)
- Loading branch information
1 parent
67f9e3d
commit cc779a1
Showing
9 changed files
with
160 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
changelog/fragments/1697230491-Relax-version-checks-in-snapshot-builds.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: enhancement | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Relax version checks in snapshot builds | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
description: | | ||
Relax version checking fleet-server does to client communication when built with SNAPSHOT=true. | ||
Versions allowed will be <=X.Y+1.Z, that is to say snapshots will allow the next minor version to communicate. | ||
This is done to avoid the chicken and egg prpoblem we face in automated testing when releasing new minor versions. | ||
# Affected component; a word indicating the component this changeset affects. | ||
component: | ||
|
||
# PR URL; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
#pr: https://github.com/owner/repo/1234 | ||
|
||
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
issue: 2960 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build !snapshot | ||
|
||
package api | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/go-version" | ||
) | ||
|
||
// BuildVersionConstraint turns the version into a constraint to ensure that the connecting Elastic Agent's are | ||
// a supported version. | ||
func BuildVersionConstraint(verStr string) (version.Constraints, error) { | ||
ver, err := version.NewVersion(verStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
verStr = maximizePatch(ver) | ||
return version.NewConstraint(fmt.Sprintf(">= %s, <= %s", MinVersion, verStr)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build snapshot | ||
|
||
package api | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-version" | ||
) | ||
|
||
// BuildVersionConstraint turns the version into a constraint to ensure that the connecting Elastic Agent's are | ||
// a supported version. | ||
// For snapshot builds we allow the minor version to be newer in order to allow automated testing to proceed. | ||
func BuildVersionConstraint(verStr string) (version.Constraints, error) { | ||
ver, err := version.NewVersion(verStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
verStr = bumpMinor(ver) | ||
return version.NewConstraint(fmt.Sprintf(">= %s, <= %s", MinVersion, verStr)) | ||
} | ||
|
||
// bumpMinor returns a version string where 1 is added to the minor version | ||
func bumpMinor(ver *version.Version) string { | ||
segments := ver.Segments() | ||
if len(segments) < 2 { | ||
return ver.String() | ||
} | ||
segments[1] += 1 | ||
strs := make([]string, 0, len(segments)) | ||
for _, seg := range segments { | ||
strs = append(strs, strconv.Itoa(seg)) | ||
} | ||
return strings.Join(strs, ".") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build !integration && snapshot | ||
|
||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestVersionConstraint(t *testing.T) { | ||
tests := []struct { | ||
version string | ||
succeed bool | ||
}{{ | ||
version: "8.0.0", | ||
succeed: true, | ||
}, { | ||
version: "8.1.0", | ||
succeed: true, | ||
}, { | ||
version: "8.2.0", | ||
succeed: false, | ||
}} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.version, func(t *testing.T) { | ||
vc, err := BuildVersionConstraint("8.0.0") | ||
require.NoError(t, err) | ||
ver, err := version.NewVersion(tc.version) | ||
require.NoError(t, err) | ||
|
||
require.Equalf(t, tc.succeed, vc.Check(ver), "vc is %s", vc.String()) | ||
}) | ||
} | ||
} |