func updateEnvMapForEnvoy()

in pkg/inject/sidecar_builder.go [59:190]


func updateEnvMapForEnvoy(vars EnvoyTemplateVariables, env map[string]string, vname string) error {
	// add all the controller managed env to the map so
	// 1) we remove duplicates
	// 2) we don't allow overriding controller managed env with pod annotations
	env["APPMESH_RESOURCE_ARN"] = vname
	env["APPMESH_VIRTUAL_NODE_NAME"] = vname
	env["AWS_REGION"] = vars.AWSRegion

	// For usage outside traditional EC2 / Fargate IAM based profiles, this is needed to
	// propagate permissions to envoy. This is a rare use-case that's mostly just for testing.
	if len(vars.AwsAccessKeyId) > 0 {
		env["AWS_ACCESS_KEY_ID"] = vars.AwsAccessKeyId
	}
	if len(vars.AwsSecretAccessKey) > 0 {
		env["AWS_SECRET_ACCESS_KEY"] = vars.AwsSecretAccessKey
	}
	if len(vars.AwsSessionToken) > 0 {
		env["AWS_SESSION_TOKEN"] = vars.AwsSessionToken
	}

	env["ENVOY_ADMIN_ACCESS_ENABLE_IPV6"] = strconv.FormatBool(vars.EnableAdminAccessForIpv6)

	env["APPMESH_DUALSTACK_ENDPOINT"] = vars.UseDualStackEndpoint

	env["APPMESH_FIPS_ENDPOINT"] = vars.UseFipsEndpoint
	// Set the value to 1 to connect to the App Mesh Preview Channel endpoint.
	// See https://docs.aws.amazon.com/app-mesh/latest/userguide/preview.html
	env["APPMESH_PREVIEW"] = vars.Preview

	// Specifies the log level for the Envoy container
	// Valid values: trace, debug, info, warning, error, critical, off
	env["ENVOY_LOG_LEVEL"] = vars.LogLevel

	if vars.EnableSDS {
		env["APPMESH_SDS_SOCKET_PATH"] = vars.SdsUdsPath
	}

	if vars.AdminAccessPort != 0 {
		// Specify a custom admin port for Envoy to listen on
		// Default: 9901
		env["ENVOY_ADMIN_ACCESS_PORT"] = strconv.Itoa(int(vars.AdminAccessPort))
	}

	if vars.AdminAccessLogFile != "" {
		// Specify a custom path to write Envoy access logs to
		// Default: /tmp/envoy_admin_access.log
		env["ENVOY_ADMIN_ACCESS_LOG_FILE"] = vars.AdminAccessLogFile
	}

	if vars.EnableXrayTracing {

		// Enables X-Ray tracing using 127.0.0.1:2000 as the default daemon endpoint
		// To enable, set the value to 1
		env["ENABLE_ENVOY_XRAY_TRACING"] = "1"

		// Specify a port value to override the default X-Ray daemon port: 2000
		env["XRAY_DAEMON_PORT"] = strconv.Itoa(int(vars.XrayDaemonPort))

		// Override the default sampling rate of 0.05 (5%) for AWS X-Ray tracer
		// The value should be specified as a decimal between 0 and 1.00 (100%)
		samplingRate, ok := env["XRAY_SAMPLING_RATE"]
		if ok {
			// `podAnnotations` contains the sampling rate and gets preference over helm configuration
			// For now delete this value from env so that we can validate before adding again
			delete(env, "XRAY_SAMPLING_RATE")
		} else {
			// `podAnnotations` doesn't contain the sampling rate so get value from helm configuration
			samplingRate = vars.XraySamplingRate
		}

		fixedRate, err := strconv.ParseFloat(samplingRate, 32)
		if err != nil || float64(0) > fixedRate || float64(1) < fixedRate {
			// The value is not a decimal between 0 and 1.00
			return errors.Errorf("tracing.samplingRate should be a decimal between 0 & 1.00, "+
				"but instead got %s %v", samplingRate, err)
		} else {
			fixedRate = math.Round(fixedRate*100) / 100
			env["XRAY_SAMPLING_RATE"] = strconv.FormatFloat(fixedRate, 'f', -1, 32)
		}
	}

	if vars.EnableDatadogTracing {
		// Enables Datadog trace collection using 127.0.0.1:8126
		// as the default Datadog agent endpoint. To enable, set the value to 1
		env["ENABLE_ENVOY_DATADOG_TRACING"] = "1"

		// Specify a port value to override the default Datadog agent port: 8126
		env["DATADOG_TRACER_PORT"] = strconv.Itoa(int(vars.DatadogTracerPort))

		// Specify an IP address or hostname to override the default Datadog agent address: 127.0.0.1
		env["DATADOG_TRACER_ADDRESS"] = vars.DatadogTracerAddress

	}

	if vars.EnableStatsTags {
		env["ENABLE_ENVOY_STATS_TAGS"] = "1"
	}

	if vars.EnableStatsD {
		// Enables DogStatsD stats using 127.0.0.1:8125
		// as the default daemon endpoint. To enable, set the value to 1
		env["ENABLE_ENVOY_DOG_STATSD"] = "1"

		// Specify a port value to override the default DogStatsD daemon port.
		// This value will be overridden if `STATSD_SOCKET_PATH` is specified.
		env["STATSD_PORT"] = strconv.Itoa(int(vars.StatsDPort))

		// Specify an IP address value to override the default DogStatsD daemon IP address
		// Default: 127.0.0.1. This variable can only be used with version 1.15.0 or later
		// of the Envoy image. This value will be overridden if `STATSD_SOCKET_PATH` is specified.
		env["STATSD_ADDRESS"] = vars.StatsDAddress

		// Specify a unix domain socket for DogStatsD daemon. If not specified and if DogStatsD
		// is enabled then defaults to DogStatsD daemon IP address port [default: 127.0.0.1:8125].
		// This variable can only be used with version v1.19.1 or later.
		if statsDSocketPath := strings.TrimSpace(vars.StatsDSocketPath); statsDSocketPath != "" {
			env["STATSD_SOCKET_PATH"] = statsDSocketPath
		}
	}

	if vars.EnableJaegerTracing {
		env["ENABLE_ENVOY_JAEGER_TRACING"] = "1"
		env["JAEGER_TRACER_PORT"] = vars.JaegerPort
		env["JAEGER_TRACER_ADDRESS"] = vars.JaegerAddress
	}

	env["APPMESH_PLATFORM_K8S_VERSION"] = vars.K8sVersion
	env["APPMESH_PLATFORM_APP_MESH_CONTROLLER_VERSION"] = vars.ControllerVersion
	env["APPNET_AGENT_ADMIN_MODE"] = "uds"
	env["APPNET_AGENT_ADMIN_UDS_PATH"] = "/tmp/agent.sock"
	return nil
}