connect: remove unusable path for fallback envoy image names (#17044)

This PR does some cleanup of an old code path for versions of Consul that
did not support reporting the supported versions of Envoy in its API. Those
versions are no longer supported for years at this point, and the fallback
version of envoy hasn't been supported by any version of Consul for almost
as long. Remove this code path that is no longer useful.
This commit is contained in:
Seth Hoenig 2023-05-02 09:48:44 -05:00 committed by GitHub
parent e8d53ea30b
commit e9fec4ebc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 20 deletions

3
.changelog/17044.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:deprecation
envoy: remove support for envoy fallback image
```

View File

@ -5,6 +5,7 @@ package taskrunner
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@ -38,9 +39,8 @@ func newEnvoyVersionHookConfig(alloc *structs.Allocation, proxiesClient consul.S
// envoyVersionHook is used to determine and set the Docker image used for Consul // envoyVersionHook is used to determine and set the Docker image used for Consul
// Connect sidecar proxy tasks. It will query Consul for a set of preferred Envoy // Connect sidecar proxy tasks. It will query Consul for a set of preferred Envoy
// versions if the task image is unset or references ${NOMAD_envoy_version}. Nomad // versions if the task image is unset or references ${NOMAD_envoy_version}. If
// will fallback the image to the previous default Envoy v1.11.2 if Consul is too old // Consul does not report its supported envoy versions then the hood will fail.
// to support the supported proxies API.
type envoyVersionHook struct { type envoyVersionHook struct {
// alloc is the allocation with the envoy task being rewritten. // alloc is the allocation with the envoy task being rewritten.
alloc *structs.Allocation alloc *structs.Allocation
@ -165,12 +165,12 @@ func (h *envoyVersionHook) needsVersion(config map[string]interface{}) bool {
return strings.Contains(image, envoy.VersionVar) return strings.Contains(image, envoy.VersionVar)
} }
// tweakImage determines the best Envoy version to use. If supported is nil or empty // tweakImage determines the best Envoy version to use. If no supported versions were
// Nomad will fallback to the legacy envoy image used before Nomad v1.0. // detected from the Consul API just return an error.
func (h *envoyVersionHook) tweakImage(configured string, supported map[string][]string) (string, error) { func (h *envoyVersionHook) tweakImage(configured string, supported map[string][]string) (string, error) {
versions := supported["envoy"] versions := supported["envoy"]
if len(versions) == 0 { if len(versions) == 0 {
return envoy.FallbackImage, nil return "", errors.New("Consul did not report any supported envoy versions")
} }
latest, err := semver(versions[0]) latest, err := semver(versions[0])

View File

@ -79,9 +79,8 @@ func TestEnvoyVersionHook_tweakImage(t *testing.T) {
image := envoy.ImageFormat image := envoy.ImageFormat
t.Run("legacy", func(t *testing.T) { t.Run("legacy", func(t *testing.T) {
result, err := (*envoyVersionHook)(nil).tweakImage(image, nil) _, err := (*envoyVersionHook)(nil).tweakImage(image, nil)
must.NoError(t, err) must.Error(t, err)
must.Eq(t, envoy.FallbackImage, result)
}) })
t.Run("unexpected", func(t *testing.T) { t.Run("unexpected", func(t *testing.T) {
@ -350,7 +349,7 @@ func TestTaskRunner_EnvoyVersionHook_Prestart_skip(t *testing.T) {
must.MapNotContainsKey(t, request.Task.Config, "image") must.MapNotContainsKey(t, request.Task.Config, "image")
} }
func TestTaskRunner_EnvoyVersionHook_Prestart_fallback(t *testing.T) { func TestTaskRunner_EnvoyVersionHook_Prestart_no_fallback(t *testing.T) {
ci.Parallel(t) ci.Parallel(t)
logger := testlog.HCLogger(t) logger := testlog.HCLogger(t)
@ -382,10 +381,7 @@ func TestTaskRunner_EnvoyVersionHook_Prestart_fallback(t *testing.T) {
var response ifs.TaskPrestartResponse var response ifs.TaskPrestartResponse
// Run the hook // Run the hook
must.NoError(t, h.Prestart(context.Background(), request, &response)) must.Error(t, h.Prestart(context.Background(), request, &response))
// Assert the Task.Config[image] is the fallback image
must.Eq(t, "envoyproxy/envoy:v1.11.2@sha256:a7769160c9c1a55bb8d07a3b71ce5d64f72b1f665f10d81aa1581bc3cf850d09", request.Task.Config["image"])
} }
func TestTaskRunner_EnvoyVersionHook_Prestart_error(t *testing.T) { func TestTaskRunner_EnvoyVersionHook_Prestart_error(t *testing.T) {

View File

@ -47,12 +47,6 @@ const (
// VersionVar will be replaced with the Envoy version string when // VersionVar will be replaced with the Envoy version string when
// used in the meta.connect.sidecar_image variable. // used in the meta.connect.sidecar_image variable.
VersionVar = "${NOMAD_envoy_version}" VersionVar = "${NOMAD_envoy_version}"
// FallbackImage is the image set in the node meta by default
// to be used by Consul Connect sidecar tasks. As of Nomad 1.0, this value
// is only used as a fallback when the version of Consul does not yet support
// dynamic envoy versions.
FallbackImage = "envoyproxy/envoy:v1.11.2@sha256:a7769160c9c1a55bb8d07a3b71ce5d64f72b1f665f10d81aa1581bc3cf850d09"
) )
// PortLabel creates a consistent port label using the inputs of a prefix, // PortLabel creates a consistent port label using the inputs of a prefix,