2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 22:48:58 +00:00
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
package xdscommon
|
2020-07-09 22:04:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
2020-07-09 22:04:51 +00:00
|
|
|
"github.com/hashicorp/go-version"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-07-31 20:52:49 +00:00
|
|
|
// minSupportedVersion is the oldest mainline version we support. This should always be
|
2023-02-06 17:14:35 +00:00
|
|
|
// the zero'th point release of the last element of xdscommon.EnvoyVersions.
|
|
|
|
minSupportedVersion = version.Must(version.NewVersion(GetMinEnvoyMinorVersion()))
|
2021-04-29 18:54:05 +00:00
|
|
|
|
2021-02-22 21:00:15 +00:00
|
|
|
specificUnsupportedVersions = []unsupportedVersion{}
|
2020-07-09 22:04:51 +00:00
|
|
|
)
|
|
|
|
|
2020-10-06 22:09:13 +00:00
|
|
|
type unsupportedVersion struct {
|
|
|
|
Version *version.Version
|
|
|
|
UpgradeTo string
|
|
|
|
Why string
|
|
|
|
}
|
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
type SupportedProxyFeatures struct {
|
2022-04-18 16:36:07 +00:00
|
|
|
// Put feature switches here when necessary. For reference, The most recent remove of a feature flag was removed in
|
|
|
|
// <insert PR here>.
|
2020-07-09 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
func DetermineSupportedProxyFeatures(node *envoy_core_v3.Node) (SupportedProxyFeatures, error) {
|
2023-06-08 14:26:11 +00:00
|
|
|
version := DetermineEnvoyVersionFromNode(node)
|
2020-07-31 20:52:49 +00:00
|
|
|
return determineSupportedProxyFeaturesFromVersion(version)
|
|
|
|
}
|
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
func DetermineSupportedProxyFeaturesFromString(vs string) (SupportedProxyFeatures, error) {
|
2020-07-31 20:52:49 +00:00
|
|
|
version := version.Must(version.NewVersion(vs))
|
|
|
|
return determineSupportedProxyFeaturesFromVersion(version)
|
|
|
|
}
|
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
func determineSupportedProxyFeaturesFromVersion(version *version.Version) (SupportedProxyFeatures, error) {
|
2020-07-09 22:04:51 +00:00
|
|
|
if version == nil {
|
2020-07-31 20:52:49 +00:00
|
|
|
// This would happen on either extremely old builds OR perhaps on
|
|
|
|
// custom builds. Should we error?
|
2023-02-03 06:18:10 +00:00
|
|
|
return SupportedProxyFeatures{}, nil
|
2020-07-09 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:52:49 +00:00
|
|
|
if version.LessThan(minSupportedVersion) {
|
2023-02-03 06:18:10 +00:00
|
|
|
return SupportedProxyFeatures{}, fmt.Errorf("Envoy %s is too old and is not supported by Consul", version)
|
2020-07-09 22:04:51 +00:00
|
|
|
}
|
2020-07-31 20:52:49 +00:00
|
|
|
|
2020-10-06 22:09:13 +00:00
|
|
|
for _, uv := range specificUnsupportedVersions {
|
|
|
|
if version.Equal(uv.Version) {
|
2023-02-03 06:18:10 +00:00
|
|
|
return SupportedProxyFeatures{}, fmt.Errorf(
|
2020-10-06 22:09:13 +00:00
|
|
|
"Envoy %s is too old of a point release and is not supported by Consul because it %s. "+
|
|
|
|
"Please upgrade to version %s.",
|
|
|
|
version,
|
|
|
|
uv.Why,
|
|
|
|
uv.UpgradeTo,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
sf := SupportedProxyFeatures{}
|
2021-04-29 18:54:05 +00:00
|
|
|
|
2022-04-18 16:36:07 +00:00
|
|
|
// when feature flags necessary, populate here by calling version.LessThan(...)
|
2021-04-29 18:54:05 +00:00
|
|
|
|
|
|
|
return sf, nil
|
2020-07-09 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 14:26:11 +00:00
|
|
|
func DetermineEnvoyVersionFromNode(node *envoy_core_v3.Node) *version.Version {
|
2020-07-09 22:04:51 +00:00
|
|
|
if node == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if node.UserAgentVersionType == nil {
|
2021-02-22 21:00:15 +00:00
|
|
|
return nil
|
2020-07-09 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if node.UserAgentName != "envoy" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
bv, ok := node.UserAgentVersionType.(*envoy_core_v3.Node_UserAgentBuildVersion)
|
2020-07-09 22:04:51 +00:00
|
|
|
if !ok {
|
|
|
|
// NOTE: we could sniff for *envoycore.Node_UserAgentVersion and do more regex but official builds don't have this problem.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if bv.UserAgentBuildVersion == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
v := bv.UserAgentBuildVersion.Version
|
|
|
|
|
|
|
|
return version.Must(version.NewVersion(
|
|
|
|
fmt.Sprintf("%d.%d.%d",
|
|
|
|
v.GetMajorNumber(),
|
|
|
|
v.GetMinorNumber(),
|
|
|
|
v.GetPatch(),
|
|
|
|
),
|
|
|
|
))
|
|
|
|
}
|