diff --git a/.changelog/3916.txt b/.changelog/3916.txt new file mode 100644 index 0000000000..a653f63480 --- /dev/null +++ b/.changelog/3916.txt @@ -0,0 +1,3 @@ +```release-note:bug +control-plane: add missing `$HOST_IP` environment variable to to consul-dataplane sidecar containers +``` diff --git a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go index 6fcb136099..fb509df400 100644 --- a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go +++ b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go @@ -153,6 +153,12 @@ func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod cor Name: "DP_CREDENTIAL_LOGIN_META2", Value: "pod-uid=$(POD_UID)", }, + { + Name: "HOST_IP", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.hostIP"}, + }, + }, }, VolumeMounts: []corev1.VolumeMount{ { diff --git a/control-plane/connect-inject/webhook/consul_dataplane_sidecar_test.go b/control-plane/connect-inject/webhook/consul_dataplane_sidecar_test.go index ea33f60133..1506f06835 100644 --- a/control-plane/connect-inject/webhook/consul_dataplane_sidecar_test.go +++ b/control-plane/connect-inject/webhook/consul_dataplane_sidecar_test.go @@ -221,7 +221,7 @@ func TestHandlerConsulDataplaneSidecar(t *testing.T) { } require.Equal(t, expectedProbe, container.ReadinessProbe) require.Nil(t, container.StartupProbe) - require.Len(t, container.Env, 9) + require.Len(t, container.Env, 10) require.Equal(t, container.Env[0].Name, "TMPDIR") require.Equal(t, container.Env[0].Value, "/consul/connect-inject") require.Equal(t, container.Env[2].Name, "DP_SERVICE_NODE_NAME") @@ -235,6 +235,7 @@ func TestHandlerConsulDataplaneSidecar(t *testing.T) { require.Equal(t, container.Env[7].Value, "pod=$(POD_NAMESPACE)/$(POD_NAME)") require.Equal(t, container.Env[8].Name, "DP_CREDENTIAL_LOGIN_META2") require.Equal(t, container.Env[8].Value, "pod-uid=$(POD_UID)") + require.Equal(t, container.Env[9].Name, "HOST_IP") }) } } diff --git a/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar.go b/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar.go index e49e3b44e3..7ea1379c5a 100644 --- a/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar.go +++ b/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar.go @@ -118,6 +118,12 @@ func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod cor Name: "DP_CREDENTIAL_LOGIN_META1", Value: "pod=$(POD_NAMESPACE)/$(POD_NAME)", }, + { + Name: "HOST_IP", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.hostIP"}, + }, + }, }, VolumeMounts: []corev1.VolumeMount{ { diff --git a/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar_test.go b/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar_test.go index e5eb319a02..1b3dcc0493 100644 --- a/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar_test.go +++ b/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar_test.go @@ -220,7 +220,7 @@ func TestHandlerConsulDataplaneSidecar(t *testing.T) { } require.Equal(t, expectedProbe, container.ReadinessProbe) require.Nil(t, container.StartupProbe) - require.Len(t, container.Env, 7) + require.Len(t, container.Env, 8) require.Equal(t, container.Env[0].Name, "TMPDIR") require.Equal(t, container.Env[0].Value, "/consul/mesh-inject") require.Equal(t, container.Env[2].Name, "POD_NAME") @@ -229,6 +229,7 @@ func TestHandlerConsulDataplaneSidecar(t *testing.T) { require.Equal(t, container.Env[4].Value, "$(POD_NAME)") require.Equal(t, container.Env[5].Name, "DP_CREDENTIAL_LOGIN_META") require.Equal(t, container.Env[5].Value, "pod=$(POD_NAMESPACE)/$(POD_NAME)") + require.Equal(t, container.Env[7].Name, "HOST_IP") }) } }