-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Consul Compatibility Checking (#15818)
* add functions for returning the max and min Envoy major versions - added an UnsupportedEnvoyVersions list - removed an unused error from TestDetermineSupportedProxyFeaturesFromString - modified minSupportedVersion to use the function for getting the Min Envoy major version. Using just the major version without the patch is equivalent to using `.0` * added a function for executing the envoy --version command - added a new exec.go file to not be locked to unix system * added envoy version check when using consul connect envoy * added changelog entry * added docs change
- Loading branch information
1 parent
74b11c4
commit 1b28b89
Showing
10 changed files
with
350 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```release-note:enhancement | ||
connect: for early awareness of Envoy incompatibilities, when using the `consul connect envoy` command the Envoy version will now be checked for compatibility. If incompatible Consul will error and exit. | ||
``` | ||
```release-note:breaking-change | ||
connect: Consul will now error and exit when using the `consul connect envoy` command if the Envoy version is incompatible. To ignore this check use flag `--ignore-envoy-compatibility` | ||
``` |
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,30 @@ | ||
package proxysupport | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProxySupportOrder(t *testing.T) { | ||
versions := make([]*version.Version, len(EnvoyVersions)) | ||
beforeSort := make([]*version.Version, len(EnvoyVersions)) | ||
for i, raw := range EnvoyVersions { | ||
v, _ := version.NewVersion(raw) | ||
versions[i] = v | ||
beforeSort[i] = v | ||
} | ||
|
||
// After this, the versions are properly sorted | ||
// go-version has a collection container, but it only allows for sorting in ascending order | ||
sort.Slice(versions, func(i, j int) bool { | ||
return versions[j].LessThan(versions[i]) | ||
}) | ||
|
||
// Check that we already have a sorted list | ||
for i := range EnvoyVersions { | ||
assert.True(t, versions[i].Equal(beforeSort[i])) | ||
} | ||
} |
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,44 @@ | ||
package envoy | ||
|
||
import ( | ||
"errors" | ||
"os/exec" | ||
"regexp" | ||
) | ||
|
||
const ( | ||
envoyVersionFlag = "--version" | ||
) | ||
|
||
// execCommand lets us mock out the exec.Command function | ||
var execCommand = exec.Command | ||
|
||
func execEnvoyVersion(binary string) (string, error) { | ||
cmd := execCommand(binary, envoyVersionFlag) | ||
|
||
output, err := cmd.Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
version, err := parseEnvoyVersionNumber(string(output)) | ||
if err != nil { | ||
return "", err | ||
} | ||
return version, nil | ||
} | ||
|
||
func parseEnvoyVersionNumber(fullVersion string) (string, error) { | ||
// Use a regular expression to match the major.minor.patch version string in the fullVersion | ||
// Example input: | ||
// `envoy version: 69958e4fe32da561376d8b1d367b5e6942dfba24/1.24.1/Distribution/RELEASE/BoringSSL` | ||
re := regexp.MustCompile(`(\d+\.\d+\.\d+)`) | ||
matches := re.FindStringSubmatch(fullVersion) | ||
|
||
// If no matches were found, return an error | ||
if len(matches) == 0 { | ||
return "", errors.New("unable to parse Envoy version from output") | ||
} | ||
|
||
// Return the first match (the major.minor.patch version string) | ||
return matches[0], nil | ||
} |
Oops, something went wrong.