Skip to content

Commit c75f0e1

Browse files
committed
Invoke the shell script in the container properly
1 parent f3a3707 commit c75f0e1

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

pkg/instrumentation/podmutator_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,8 @@ func TestMutatePod(t *testing.T) {
13261326
{
13271327
Name: pythonInitContainerName,
13281328
Image: "otel/python:1",
1329-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath, "||", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath},
1329+
Command: []string{"/bin/sh"},
1330+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
13301331
VolumeMounts: []corev1.VolumeMount{{
13311332
Name: pythonVolumeName,
13321333
MountPath: pythonInstrMountPath,
@@ -1535,7 +1536,8 @@ func TestMutatePod(t *testing.T) {
15351536
{
15361537
Name: pythonInitContainerName,
15371538
Image: "otel/python:1",
1538-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath, "||", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath},
1539+
Command: []string{"/bin/sh"},
1540+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
15391541
VolumeMounts: []corev1.VolumeMount{{
15401542
Name: pythonVolumeName,
15411543
MountPath: pythonInstrMountPath,
@@ -3667,7 +3669,8 @@ func TestMutatePod(t *testing.T) {
36673669
{
36683670
Name: pythonInitContainerName,
36693671
Image: "otel/python:1",
3670-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath, "||", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath},
3672+
Command: []string{"/bin/sh"},
3673+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
36713674
VolumeMounts: []corev1.VolumeMount{{
36723675
Name: pythonVolumeName,
36733676
MountPath: pythonInstrMountPath,

pkg/instrumentation/python.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int, plat
128128
}})
129129

130130
// copy the default glibc based dir if the autoInstrumentationSrc does not exist to not break compat with old images
131+
shellCmd := fmt.Sprintf("test -d %[1]s && cp -r %[1]s %[2]s || cp -r %[3]s %[2]s", autoInstrumentationSrc, pythonInstrMountPath, glibcLinuxAutoInstrumentationSrc)
131132
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{
132133
Name: pythonInitContainerName,
133134
Image: pythonSpec.Image,
134-
Command: []string{"test", "-d", autoInstrumentationSrc, "&&", "cp", "-r", autoInstrumentationSrc, pythonInstrMountPath, "||", "cp", "-r", glibcLinuxAutoInstrumentationSrc, pythonInstrMountPath},
135+
Command: []string{"/bin/sh"},
136+
Args: []string{"-c", shellCmd},
135137
Resources: pythonSpec.Resources,
136138
VolumeMounts: []corev1.VolumeMount{{
137139
Name: pythonVolumeName,

pkg/instrumentation/python_test.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func TestInjectPythonSDK(t *testing.T) {
6060
{
6161
Name: "opentelemetry-auto-instrumentation-python",
6262
Image: "foo/bar:1",
63-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
63+
Command: []string{"/bin/sh"},
64+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
6465
VolumeMounts: []corev1.VolumeMount{{
6566
Name: "opentelemetry-auto-instrumentation-python",
6667
MountPath: "/otel-auto-instrumentation-python",
@@ -137,7 +138,8 @@ func TestInjectPythonSDK(t *testing.T) {
137138
{
138139
Name: "opentelemetry-auto-instrumentation-python",
139140
Image: "foo/bar:1",
140-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
141+
Command: []string{"/bin/sh"},
142+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
141143
VolumeMounts: []corev1.VolumeMount{{
142144
Name: "opentelemetry-auto-instrumentation-python",
143145
MountPath: "/otel-auto-instrumentation-python",
@@ -215,7 +217,8 @@ func TestInjectPythonSDK(t *testing.T) {
215217
{
216218
Name: "opentelemetry-auto-instrumentation-python",
217219
Image: "foo/bar:1",
218-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
220+
Command: []string{"/bin/sh"},
221+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
219222
VolumeMounts: []corev1.VolumeMount{{
220223
Name: "opentelemetry-auto-instrumentation-python",
221224
MountPath: "/otel-auto-instrumentation-python",
@@ -292,7 +295,8 @@ func TestInjectPythonSDK(t *testing.T) {
292295
{
293296
Name: "opentelemetry-auto-instrumentation-python",
294297
Image: "foo/bar:1",
295-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
298+
Command: []string{"/bin/sh"},
299+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
296300
VolumeMounts: []corev1.VolumeMount{{
297301
Name: "opentelemetry-auto-instrumentation-python",
298302
MountPath: "/otel-auto-instrumentation-python",
@@ -445,7 +449,8 @@ func TestInjectPythonSDK(t *testing.T) {
445449
{
446450
Name: "opentelemetry-auto-instrumentation-python",
447451
Image: "foo/bar:1",
448-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
452+
Command: []string{"/bin/sh"},
453+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
449454
VolumeMounts: []corev1.VolumeMount{{
450455
Name: "opentelemetry-auto-instrumentation-python",
451456
MountPath: "/otel-auto-instrumentation-python",
@@ -549,7 +554,8 @@ func TestInjectPythonSDK(t *testing.T) {
549554
{
550555
Name: "opentelemetry-auto-instrumentation-python",
551556
Image: "foo/bar:1",
552-
Command: []string{"test", "-d", "/autoinstrumentation-musl/.", "&&", "cp", "-r", "/autoinstrumentation-musl/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
557+
Command: []string{"/bin/sh"},
558+
Args: []string{"-c", "test -d /autoinstrumentation-musl/. && cp -r /autoinstrumentation-musl/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
553559
VolumeMounts: []corev1.VolumeMount{{
554560
Name: "opentelemetry-auto-instrumentation-python",
555561
MountPath: "/otel-auto-instrumentation-python",
@@ -615,7 +621,8 @@ func TestInjectPythonSDK(t *testing.T) {
615621
{
616622
Name: "opentelemetry-auto-instrumentation-python",
617623
Image: "foo/bar:1",
618-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python", "||", "cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
624+
Command: []string{"/bin/sh"},
625+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
619626
VolumeMounts: []corev1.VolumeMount{{
620627
Name: "opentelemetry-auto-instrumentation-python",
621628
MountPath: "/otel-auto-instrumentation-python",

pkg/instrumentation/sdk_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,8 @@ func TestInjectPython(t *testing.T) {
12111211
{
12121212
Name: pythonInitContainerName,
12131213
Image: "img:1",
1214-
Command: []string{"test", "-d", "/autoinstrumentation/.", "&&", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath, "||", "cp", "-r", "/autoinstrumentation/.", pythonInstrMountPath},
1214+
Command: []string{"/bin/sh"},
1215+
Args: []string{"-c", "test -d /autoinstrumentation/. && cp -r /autoinstrumentation/. /otel-auto-instrumentation-python || cp -r /autoinstrumentation/. /otel-auto-instrumentation-python"},
12151216
VolumeMounts: []corev1.VolumeMount{{
12161217
Name: pythonVolumeName,
12171218
MountPath: pythonInstrMountPath,

0 commit comments

Comments
 (0)