From a803ee48729bced0b06ac91ea3e09cf8f8916eb4 Mon Sep 17 00:00:00 2001 From: IldarMinaev Date: Wed, 22 Jan 2025 19:31:57 +0400 Subject: [PATCH 1/2] Fix nginxCloneScriptTemplate for old shells dash version 0.5.10.2-5 return error for export command with spaces after = symbol: ``` # export qwe=nginx version: nginx/1.20.1 dash: 10: export: version:: bad variable name ``` --- pkg/instrumentation/nginx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/instrumentation/nginx.go b/pkg/instrumentation/nginx.go index 7bcc39d611..581ccc929e 100644 --- a/pkg/instrumentation/nginx.go +++ b/pkg/instrumentation/nginx.go @@ -96,7 +96,7 @@ func injectNginxSDK(_ logr.Logger, nginxSpec v1alpha1.Nginx, pod corev1.Pod, use nginxCloneScriptTemplate := ` cp -r %[2]s/* %[3]s && -export %[4]s=$( { nginx -v ; } 2>&1 ) && echo ${%[4]s##*/} > %[3]s/version.txt +export %[4]s="$( { nginx -v ; } 2>&1 )" && echo ${%[4]s##*/} > %[3]s/version.txt ` nginxAgentCommands := prepareCommandFromTemplate(nginxCloneScriptTemplate, nginxConfFile, From 118c91c95eaad7bb023eb021ea9da97be8ed52e7 Mon Sep 17 00:00:00 2001 From: IldarMinaev Date: Wed, 22 Jan 2025 22:31:18 +0400 Subject: [PATCH 2/2] Update Unit tests for nginxCloneScriptTemplate --- .chloggen/patch-1.yaml | 16 ++++++++++++++++ pkg/instrumentation/nginx_test.go | 10 +++++----- pkg/instrumentation/podmutator_test.go | 2 +- pkg/instrumentation/sdk_test.go | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100755 .chloggen/patch-1.yaml diff --git a/.chloggen/patch-1.yaml b/.chloggen/patch-1.yaml new file mode 100755 index 0000000000..2f5096b526 --- /dev/null +++ b/.chloggen/patch-1.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: auto-instrumentation + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix nginxCloneScriptTemplate for old shells + +# One or more tracking issues related to the change +issues: [3651] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/pkg/instrumentation/nginx_test.go b/pkg/instrumentation/nginx_test.go index b483c38cf4..2bdd10ed56 100644 --- a/pkg/instrumentation/nginx_test.go +++ b/pkg/instrumentation/nginx_test.go @@ -83,7 +83,7 @@ func TestInjectNginxSDK(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull, @@ -188,7 +188,7 @@ func TestInjectNginxSDK(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /opt/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /opt/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull, @@ -296,7 +296,7 @@ func TestInjectNginxSDK(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull, @@ -404,7 +404,7 @@ func TestInjectNginxSDK(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull, @@ -528,7 +528,7 @@ func TestInjectNginxUnknownNamespace(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull, diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 3fd085d539..e5047ef2f7 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -3183,7 +3183,7 @@ func TestMutatePod(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull, diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index 09e7ee427b..9393487cee 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -2003,7 +2003,7 @@ func TestInjectNginx(t *testing.T) { Name: nginxAgentCloneContainerName, Image: "", Command: []string{"/bin/sh", "-c"}, - Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=$( { nginx -v ; } 2>&1 ) && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, + Args: []string{"cp -r /etc/nginx/* /opt/opentelemetry-webserver/source-conf && export NGINX_VERSION=\"$( { nginx -v ; } 2>&1 )\" && echo ${NGINX_VERSION##*/} > /opt/opentelemetry-webserver/source-conf/version.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: nginxAgentConfigVolume, MountPath: nginxAgentConfDirFull,