diff --git a/pkg/inject/envoy_test.go b/pkg/inject/envoy_test.go index 9604d795..b3925797 100644 --- a/pkg/inject/envoy_test.go +++ b/pkg/inject/envoy_test.go @@ -76,7 +76,7 @@ func Test_envoyMutator_mutate(t *testing.T) { Namespace: "my-ns", Name: "my-pod", Annotations: map[string]string{ - "appmesh.k8s.aws/sidecarEnv": "DD_ENV=prod, APPMESH_VIRTUAL_NODE_NAME=random_val", + "appmesh.k8s.aws/sidecarEnv": "DD_ENV=prod, APPMESH_RESOURCE_ARN=random_val, APPMESH_VIRTUAL_NODE_NAME=random_val", }, }, Spec: corev1.PodSpec{ @@ -258,6 +258,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -401,6 +405,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -543,6 +551,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -725,6 +737,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -878,6 +894,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1030,6 +1050,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1177,6 +1201,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1335,6 +1363,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1518,6 +1550,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1683,6 +1719,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1826,6 +1866,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -1984,6 +2028,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -2149,6 +2197,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -2348,6 +2400,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -2507,6 +2563,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -2669,6 +2729,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -2798,7 +2862,7 @@ func Test_envoyMutator_mutate(t *testing.T) { Namespace: "my-ns", Name: "my-pod", Annotations: map[string]string{ - "appmesh.k8s.aws/sidecarEnv": "DD_ENV=prod, APPMESH_VIRTUAL_NODE_NAME=random_val", + "appmesh.k8s.aws/sidecarEnv": "DD_ENV=prod, APPMESH_RESOURCE_ARN=random_val, APPMESH_VIRTUAL_NODE_NAME=random_val", }, }, Spec: corev1.PodSpec{ @@ -2842,6 +2906,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", @@ -2997,6 +3065,10 @@ func Test_envoyMutator_mutate(t *testing.T) { FailureThreshold: 3, }, Env: []corev1.EnvVar{ + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualNode/my-vn_my-ns", diff --git a/pkg/inject/sidecar_builder.go b/pkg/inject/sidecar_builder.go index 76589aff..d046b119 100644 --- a/pkg/inject/sidecar_builder.go +++ b/pkg/inject/sidecar_builder.go @@ -60,6 +60,7 @@ func updateEnvMapForEnvoy(vars EnvoyTemplateVariables, env map[string]string, vn // 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 diff --git a/pkg/inject/virtualgateway_envoy_test.go b/pkg/inject/virtualgateway_envoy_test.go index dc8590ca..7ad717bc 100644 --- a/pkg/inject/virtualgateway_envoy_test.go +++ b/pkg/inject/virtualgateway_envoy_test.go @@ -143,6 +143,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "TEST_ENV", Value: "test_val", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "incorrect_node_name", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "incorrect_node_name", @@ -325,6 +329,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -441,6 +449,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -562,6 +574,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -663,6 +679,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "TEST_ENV", Value: "test_val", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -780,6 +800,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "TEST_ENV", Value: "test_val", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -897,6 +921,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "TEST_ENV", Value: "test_val", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1029,6 +1057,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1188,6 +1220,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1323,6 +1359,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1461,6 +1501,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1586,6 +1630,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1705,6 +1753,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "APPMESH_SDS_SOCKET_PATH", Value: "/run/spire/sockets/agent.sock", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1839,6 +1891,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "AWS_REGION", Value: "us-west-2", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", @@ -1958,6 +2014,10 @@ func Test_virtualGatewayEnvoyMutator_mutate(t *testing.T) { Name: "APPMESH_SDS_SOCKET_PATH", Value: "/run/spire/sockets/agent.sock", }, + { + Name: "APPMESH_RESOURCE_ARN", + Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns", + }, { Name: "APPMESH_VIRTUAL_NODE_NAME", Value: "mesh/my-mesh/virtualGateway/my-vg_my-ns",