From 6982b65ec569b71bb987240ad984a76a7e4da272 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 16 Apr 2024 14:07:13 -0700 Subject: [PATCH 1/8] Add HOST_IP environment variable to consul_dataplane_sidecar.go This environment variable must be set in order to utilize HOST_IP as part of statsd or dogstatsd sinks. If this variable is unset and the sink is configured to use HOST_IP, the sidecar won't start and pods won't coe up healthy. --- .../connect-inject/webhook/consul_dataplane_sidecar.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go index dc9ca0d0bf..ff624eb219 100644 --- a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go +++ b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go @@ -139,6 +139,12 @@ func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod cor FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.uid"}, }, }, + { + Name: "HOST_IP", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.hostIP"}, + }, + }, { Name: "DP_CREDENTIAL_LOGIN_META", Value: "pod=$(POD_NAMESPACE)/$(POD_NAME)", From 63df1186f352575202f5b38438e7b8b0b4504936 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 16 Apr 2024 14:10:13 -0700 Subject: [PATCH 2/8] Update consul_dataplane_sidecar.go --- .../webhook/consul_dataplane_sidecar.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go index ff624eb219..5617dcc130 100644 --- a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go +++ b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go @@ -139,12 +139,6 @@ func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod cor FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.uid"}, }, }, - { - Name: "HOST_IP", - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.hostIP"}, - }, - }, { Name: "DP_CREDENTIAL_LOGIN_META", Value: "pod=$(POD_NAMESPACE)/$(POD_NAME)", @@ -159,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{ { From fadb91efb9bb8cd1ab08c69f71654ae7c40edfd7 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 16 Apr 2024 14:11:36 -0700 Subject: [PATCH 3/8] Add tests --- .../connect-inject/webhook/consul_dataplane_sidecar_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 4a8386c493..1c1f3cdbf7 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") }) } } From 6e0710585db5956f7611fd714e4407c70f5685a5 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 16 Apr 2024 14:17:11 -0700 Subject: [PATCH 4/8] Add changelog entry --- control-plane/connect-inject/webhook/3916.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 control-plane/connect-inject/webhook/3916.txt diff --git a/control-plane/connect-inject/webhook/3916.txt b/control-plane/connect-inject/webhook/3916.txt new file mode 100644 index 0000000000..a653f63480 --- /dev/null +++ b/control-plane/connect-inject/webhook/3916.txt @@ -0,0 +1,3 @@ +```release-note:bug +control-plane: add missing `$HOST_IP` environment variable to to consul-dataplane sidecar containers +``` From 7f7aa406671fa886196a6e30ca9bed9a1fe2324c Mon Sep 17 00:00:00 2001 From: woz5999 Date: Tue, 16 Apr 2024 14:20:32 -0700 Subject: [PATCH 5/8] fix changelog --- {control-plane/connect-inject/webhook => .changelog}/3916.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {control-plane/connect-inject/webhook => .changelog}/3916.txt (100%) diff --git a/control-plane/connect-inject/webhook/3916.txt b/.changelog/3916.txt similarity index 100% rename from control-plane/connect-inject/webhook/3916.txt rename to .changelog/3916.txt From 2bae8a516f8614c82fab41528518d74d24f87064 Mon Sep 17 00:00:00 2001 From: woz5999 Date: Tue, 16 Apr 2024 14:20:39 -0700 Subject: [PATCH 6/8] webhook v2 --- .../connect-inject/webhookv2/consul_dataplane_sidecar.go | 6 ++++++ .../webhookv2/consul_dataplane_sidecar_test.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar.go b/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar.go index d94dbeaaac..d69f1de31f 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 3b5fb3c0c7..a98c26bd36 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[6].Name, "HOST_IP") }) } } From f20395b795f60082516f1875d78037beef76b16f Mon Sep 17 00:00:00 2001 From: woz5999 Date: Tue, 16 Apr 2024 14:35:57 -0700 Subject: [PATCH 7/8] Update consul_dataplane_sidecar_test.go --- .../connect-inject/webhookv2/consul_dataplane_sidecar_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a98c26bd36..0b3687babe 100644 --- a/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar_test.go +++ b/control-plane/connect-inject/webhookv2/consul_dataplane_sidecar_test.go @@ -229,7 +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[6].Name, "HOST_IP") + require.Equal(t, container.Env[7].Name, "HOST_IP") }) } } From fbee95e9873c06d28d8c493e6de72434ea4c03dc Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 29 Aug 2024 14:45:33 -0700 Subject: [PATCH 8/8] Update .changelog/3916.txt Co-authored-by: Nathan Coleman --- .changelog/3916.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/3916.txt b/.changelog/3916.txt index a653f63480..4c9b43866b 100644 --- a/.changelog/3916.txt +++ b/.changelog/3916.txt @@ -1,3 +1,3 @@ ```release-note:bug -control-plane: add missing `$HOST_IP` environment variable to to consul-dataplane sidecar containers +control-plane: add missing `$HOST_IP` environment variable to consul-dataplane sidecar containers ```