github.com/hernad/nomad@v1.6.112/helper/envoy/envoy.go (about)

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