@@ -31,6 +31,7 @@ import (
31
31
"go.opentelemetry.io/otel/attribute"
32
32
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
33
33
appsv1 "k8s.io/api/apps/v1"
34
+ batchv1 "k8s.io/api/batch/v1"
34
35
corev1 "k8s.io/api/core/v1"
35
36
apierrors "k8s.io/apimachinery/pkg/api/errors"
36
37
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -380,10 +381,10 @@ func chooseServiceName(pod corev1.Pod, resources map[string]string, index int) s
380
381
if name := resources [string (semconv .K8SDaemonSetNameKey )]; name != "" {
381
382
return name
382
383
}
383
- if name := resources [string (semconv .K8SJobNameKey )]; name != "" {
384
+ if name := resources [string (semconv .K8SCronJobNameKey )]; name != "" {
384
385
return name
385
386
}
386
- if name := resources [string (semconv .K8SCronJobNameKey )]; name != "" {
387
+ if name := resources [string (semconv .K8SJobNameKey )]; name != "" {
387
388
return name
388
389
}
389
390
if name := resources [string (semconv .K8SPodNameKey )]; name != "" {
@@ -502,6 +503,26 @@ func (i *sdkInjector) addParentResourceLabels(ctx context.Context, uid bool, ns
502
503
if uid {
503
504
resources [semconv .K8SJobUIDKey ] = string (owner .UID )
504
505
}
506
+
507
+ // parent of Job can be CronJob which we are interested to know
508
+ j := batchv1.Job {}
509
+ nsn := types.NamespacedName {Namespace : ns .Name , Name : owner .Name }
510
+ backOff := wait.Backoff {Duration : 10 * time .Millisecond , Factor : 1.5 , Jitter : 0.1 , Steps : 20 , Cap : 2 * time .Second }
511
+
512
+ checkError := func (err error ) bool {
513
+ return apierrors .IsNotFound (err )
514
+ }
515
+
516
+ getJob := func () error {
517
+ return i .client .Get (ctx , nsn , & j )
518
+ }
519
+
520
+ // use a retry loop to get the Job. A single call to client.get fails occasionally
521
+ err := retry .OnError (backOff , checkError , getJob )
522
+ if err != nil {
523
+ i .logger .Error (err , "failed to get job" , "job" , nsn .Name , "namespace" , nsn .Namespace )
524
+ }
525
+ i .addParentResourceLabels (ctx , uid , ns , j .ObjectMeta , resources )
505
526
case "cronjob" :
506
527
resources [semconv .K8SCronJobNameKey ] = owner .Name
507
528
if uid {
0 commit comments