@@ -29,6 +29,7 @@ func TestInjectPythonSDK(t *testing.T) {
29
29
name string
30
30
v1alpha1.Python
31
31
pod corev1.Pod
32
+ platform string
32
33
expected corev1.Pod
33
34
err error
34
35
}{
@@ -42,6 +43,7 @@ func TestInjectPythonSDK(t *testing.T) {
42
43
},
43
44
},
44
45
},
46
+ platform : "glibc" ,
45
47
expected : corev1.Pod {
46
48
Spec : corev1.PodSpec {
47
49
Volumes : []corev1.Volume {
@@ -118,6 +120,7 @@ func TestInjectPythonSDK(t *testing.T) {
118
120
},
119
121
},
120
122
},
123
+ platform : "glibc" ,
121
124
expected : corev1.Pod {
122
125
Spec : corev1.PodSpec {
123
126
Volumes : []corev1.Volume {
@@ -195,6 +198,7 @@ func TestInjectPythonSDK(t *testing.T) {
195
198
},
196
199
},
197
200
},
201
+ platform : "glibc" ,
198
202
expected : corev1.Pod {
199
203
Spec : corev1.PodSpec {
200
204
Volumes : []corev1.Volume {
@@ -271,6 +275,7 @@ func TestInjectPythonSDK(t *testing.T) {
271
275
},
272
276
},
273
277
},
278
+ platform : "glibc" ,
274
279
expected : corev1.Pod {
275
280
Spec : corev1.PodSpec {
276
281
Volumes : []corev1.Volume {
@@ -423,6 +428,7 @@ func TestInjectPythonSDK(t *testing.T) {
423
428
},
424
429
},
425
430
},
431
+ platform : "glibc" ,
426
432
expected : corev1.Pod {
427
433
Spec : corev1.PodSpec {
428
434
Volumes : []corev1.Volume {
@@ -499,6 +505,7 @@ func TestInjectPythonSDK(t *testing.T) {
499
505
},
500
506
},
501
507
},
508
+ platform : "glibc" ,
502
509
expected : corev1.Pod {
503
510
Spec : corev1.PodSpec {
504
511
Containers : []corev1.Container {
@@ -515,11 +522,171 @@ func TestInjectPythonSDK(t *testing.T) {
515
522
},
516
523
err : fmt .Errorf ("the container defines env var value via ValueFrom, envVar: %s" , envPythonPath ),
517
524
},
525
+ {
526
+ name : "musl platform defined" ,
527
+ Python : v1alpha1.Python {Image : "foo/bar:1" },
528
+ pod : corev1.Pod {
529
+ Spec : corev1.PodSpec {
530
+ Containers : []corev1.Container {
531
+ {},
532
+ },
533
+ },
534
+ },
535
+ platform : "musl" ,
536
+ expected : corev1.Pod {
537
+ Spec : corev1.PodSpec {
538
+ Volumes : []corev1.Volume {
539
+ {
540
+ Name : pythonVolumeName ,
541
+ VolumeSource : corev1.VolumeSource {
542
+ EmptyDir : & corev1.EmptyDirVolumeSource {
543
+ SizeLimit : & defaultVolumeLimitSize ,
544
+ },
545
+ },
546
+ },
547
+ },
548
+ InitContainers : []corev1.Container {
549
+ {
550
+ Name : "opentelemetry-auto-instrumentation-python" ,
551
+ Image : "foo/bar:1" ,
552
+ Command : []string {"cp" , "-r" , "/autoinstrumentation-musl/." , "/otel-auto-instrumentation-python" },
553
+ VolumeMounts : []corev1.VolumeMount {{
554
+ Name : "opentelemetry-auto-instrumentation-python" ,
555
+ MountPath : "/otel-auto-instrumentation-python" ,
556
+ }},
557
+ },
558
+ },
559
+ Containers : []corev1.Container {
560
+ {
561
+ VolumeMounts : []corev1.VolumeMount {
562
+ {
563
+ Name : "opentelemetry-auto-instrumentation-python" ,
564
+ MountPath : "/otel-auto-instrumentation-python" ,
565
+ },
566
+ },
567
+ Env : []corev1.EnvVar {
568
+ {
569
+ Name : "PYTHONPATH" ,
570
+ Value : fmt .Sprintf ("%s:%s" , "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation" , "/otel-auto-instrumentation-python" ),
571
+ },
572
+ {
573
+ Name : "OTEL_EXPORTER_OTLP_PROTOCOL" ,
574
+ Value : "http/protobuf" ,
575
+ },
576
+ {
577
+ Name : "OTEL_TRACES_EXPORTER" ,
578
+ Value : "otlp" ,
579
+ },
580
+ {
581
+ Name : "OTEL_METRICS_EXPORTER" ,
582
+ Value : "otlp" ,
583
+ },
584
+ {
585
+ Name : "OTEL_LOGS_EXPORTER" ,
586
+ Value : "otlp" ,
587
+ },
588
+ },
589
+ },
590
+ },
591
+ },
592
+ },
593
+ err : nil ,
594
+ },
595
+ {
596
+ name : "platform not defined" ,
597
+ Python : v1alpha1.Python {Image : "foo/bar:1" },
598
+ pod : corev1.Pod {
599
+ Spec : corev1.PodSpec {
600
+ Containers : []corev1.Container {
601
+ {},
602
+ },
603
+ },
604
+ },
605
+ platform : "" ,
606
+ expected : corev1.Pod {
607
+ Spec : corev1.PodSpec {
608
+ Volumes : []corev1.Volume {
609
+ {
610
+ Name : pythonVolumeName ,
611
+ VolumeSource : corev1.VolumeSource {
612
+ EmptyDir : & corev1.EmptyDirVolumeSource {
613
+ SizeLimit : & defaultVolumeLimitSize ,
614
+ },
615
+ },
616
+ },
617
+ },
618
+ InitContainers : []corev1.Container {
619
+ {
620
+ Name : "opentelemetry-auto-instrumentation-python" ,
621
+ Image : "foo/bar:1" ,
622
+ Command : []string {"cp" , "-r" , "/autoinstrumentation/." , "/otel-auto-instrumentation-python" },
623
+ VolumeMounts : []corev1.VolumeMount {{
624
+ Name : "opentelemetry-auto-instrumentation-python" ,
625
+ MountPath : "/otel-auto-instrumentation-python" ,
626
+ }},
627
+ },
628
+ },
629
+ Containers : []corev1.Container {
630
+ {
631
+ VolumeMounts : []corev1.VolumeMount {
632
+ {
633
+ Name : "opentelemetry-auto-instrumentation-python" ,
634
+ MountPath : "/otel-auto-instrumentation-python" ,
635
+ },
636
+ },
637
+ Env : []corev1.EnvVar {
638
+ {
639
+ Name : "PYTHONPATH" ,
640
+ Value : fmt .Sprintf ("%s:%s" , "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation" , "/otel-auto-instrumentation-python" ),
641
+ },
642
+ {
643
+ Name : "OTEL_EXPORTER_OTLP_PROTOCOL" ,
644
+ Value : "http/protobuf" ,
645
+ },
646
+ {
647
+ Name : "OTEL_TRACES_EXPORTER" ,
648
+ Value : "otlp" ,
649
+ },
650
+ {
651
+ Name : "OTEL_METRICS_EXPORTER" ,
652
+ Value : "otlp" ,
653
+ },
654
+ {
655
+ Name : "OTEL_LOGS_EXPORTER" ,
656
+ Value : "otlp" ,
657
+ },
658
+ },
659
+ },
660
+ },
661
+ },
662
+ },
663
+ err : nil ,
664
+ },
665
+ {
666
+ name : "platform not supported" ,
667
+ Python : v1alpha1.Python {Image : "foo/bar:1" },
668
+ pod : corev1.Pod {
669
+ Spec : corev1.PodSpec {
670
+ Containers : []corev1.Container {
671
+ {},
672
+ },
673
+ },
674
+ },
675
+ platform : "not-supported" ,
676
+ expected : corev1.Pod {
677
+ Spec : corev1.PodSpec {
678
+ Containers : []corev1.Container {
679
+ {},
680
+ },
681
+ },
682
+ },
683
+ err : fmt .Errorf ("provided instrumentation.opentelemetry.io/otel-python-platform annotation value 'not-supported' is not supported" ),
684
+ },
518
685
}
519
686
520
687
for _ , test := range tests {
521
688
t .Run (test .name , func (t * testing.T ) {
522
- pod , err := injectPythonSDK (test .Python , test .pod , 0 )
689
+ pod , err := injectPythonSDK (test .Python , test .pod , 0 , test . platform )
523
690
assert .Equal (t , test .expected , pod )
524
691
assert .Equal (t , test .err , err )
525
692
})
0 commit comments