github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/helper/envoy/envoy.go (about)

     1  // Package envoy provides a high level view of the variables that go into
     2  // selecting an envoy version.
     3  package envoy
     4  
     5  import (
     6  	"fmt"
     7  )
     8  
     9  const (
    10  	// SidecarMetaParam is the parameter name used to configure the connect sidecar
    11  	// at the client level. Setting this option in client configuration takes the
    12  	// lowest precedence.
    13  	//
    14  	// If this meta option is not set in client configuration, it defaults to
    15  	// ImageFormat, so that Nomad will defer envoy version selection to Consul.
    16  	SidecarMetaParam = "connect.sidecar_image"
    17  
    18  	// SidecarConfigVar is used as the default config.image value for connect
    19  	// sidecar proxies, when they are injected in the job connect mutator.
    20  	SidecarConfigVar = "${meta." + SidecarMetaParam + "}"
    21  
    22  	// GatewayMetaParam is the parameter name used to configure the connect gateway
    23  	// at the client level. Setting this option in client configuration takes the
    24  	// lowest precedence.
    25  	//
    26  	// If this meta option is not set in client configuration, it defaults to
    27  	// ImageFormat, so that Nomad will defer envoy version selection to Consul.
    28  	GatewayMetaParam = "connect.gateway_image"
    29  
    30  	// GatewayConfigVar is used as the default config.image value for connect
    31  	// gateway proxies, when they are injected in the job connect mutator.
    32  	GatewayConfigVar = "${meta." + GatewayMetaParam + "}"
    33  
    34  	// ImageFormat is the default format string used for official envoy Docker
    35  	// images with the tag being the semver of the version of envoy. Nomad fakes
    36  	// interpolation of ${NOMAD_envoy_version} by replacing it with the version
    37  	// string for envoy that Consul reports as preferred.
    38  	//
    39  	// Folks wanting to build and use custom images while still having Nomad refer
    40  	// to specific versions as preferred by Consul would set meta.connect.sidecar_image
    41  	// to something like: "custom/envoy:${NOMAD_envoy_version}".
    42  	ImageFormat = "envoyproxy/envoy:v" + VersionVar
    43  
    44  	// VersionVar will be replaced with the Envoy version string when
    45  	// used in the meta.connect.sidecar_image variable.
    46  	VersionVar = "${NOMAD_envoy_version}"
    47  
    48  	// FallbackImage is the image set in the node meta by default
    49  	// to be used by Consul Connect sidecar tasks. As of Nomad 1.0, this value
    50  	// is only used as a fallback when the version of Consul does not yet support
    51  	// dynamic envoy versions.
    52  	FallbackImage = "envoyproxy/envoy:v1.11.2@sha256:a7769160c9c1a55bb8d07a3b71ce5d64f72b1f665f10d81aa1581bc3cf850d09"
    53  )
    54  
    55  // PortLabel creates a consistent port label using the inputs of a prefix,
    56  // service name, and optional suffix. The prefix should be the Kind part of
    57  // TaskKind the envoy is being configured for.
    58  func PortLabel(prefix, service, suffix string) string {
    59  	if suffix == "" {
    60  		return fmt.Sprintf("%s-%s", prefix, service)
    61  	}
    62  	return fmt.Sprintf("%s-%s-%s", prefix, service, suffix)
    63  }