open-nomad/helper/envoy/envoy.go
Seth Hoenig e9fec4ebc8
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.
2023-05-02 09:48:44 -05:00

61 lines
2.5 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Package envoy provides a high level view of the variables that go into
// selecting an envoy version.
package envoy
import (
"fmt"
)
const (
// SidecarMetaParam is the parameter name used to configure the connect sidecar
// at the client level. Setting this option in client configuration takes the
// lowest precedence.
//
// If this meta option is not set in client configuration, it defaults to
// ImageFormat, so that Nomad will defer envoy version selection to Consul.
SidecarMetaParam = "connect.sidecar_image"
// SidecarConfigVar is used as the default config.image value for connect
// sidecar proxies, when they are injected in the job connect mutator.
SidecarConfigVar = "${meta." + SidecarMetaParam + "}"
// GatewayMetaParam is the parameter name used to configure the connect gateway
// at the client level. Setting this option in client configuration takes the
// lowest precedence.
//
// If this meta option is not set in client configuration, it defaults to
// ImageFormat, so that Nomad will defer envoy version selection to Consul.
GatewayMetaParam = "connect.gateway_image"
// GatewayConfigVar is used as the default config.image value for connect
// gateway proxies, when they are injected in the job connect mutator.
GatewayConfigVar = "${meta." + GatewayMetaParam + "}"
// ImageFormat is the default format string used for official envoy Docker
// images with the tag being the semver of the version of envoy. Nomad fakes
// interpolation of ${NOMAD_envoy_version} by replacing it with the version
// string for envoy that Consul reports as preferred.
//
// Folks wanting to build and use custom images while still having Nomad refer
// to specific versions as preferred by Consul would set meta.connect.sidecar_image
// to something like: "custom/envoy:${NOMAD_envoy_version}".
ImageFormat = "docker.io/envoyproxy/envoy:v" + VersionVar
// VersionVar will be replaced with the Envoy version string when
// used in the meta.connect.sidecar_image variable.
VersionVar = "${NOMAD_envoy_version}"
)
// PortLabel creates a consistent port label using the inputs of a prefix,
// service name, and optional suffix. The prefix should be the Kind part of
// TaskKind the envoy is being configured for.
func PortLabel(prefix, service, suffix string) string {
if suffix == "" {
return fmt.Sprintf("%s-%s", prefix, service)
}
return fmt.Sprintf("%s-%s-%s", prefix, service, suffix)
}