@@ -402,6 +402,54 @@ func chooseServiceVersion(pod corev1.Pod, index int) string {
402
402
return tag
403
403
}
404
404
405
+ // create/reserve namespace
406
+
407
+ func (i * sdkInjector ) createReservedNamespace (ctx context.Context ) (bool , error ) {
408
+ err := i .client .Get (ctx , types.NamespacedName {Name : constants .ReservedNamespace }, & corev1.Namespace {})
409
+ if err != nil {
410
+ if apierrors .IsNotFound (err ) {
411
+ ns := corev1.Namespace {
412
+ ObjectMeta : metav1.ObjectMeta {
413
+ Name : constants .ReservedNamespace ,
414
+ },
415
+ }
416
+ err = i .client .Create (ctx , & ns )
417
+ if err != nil {
418
+ return false , err
419
+ }
420
+ }
421
+ }
422
+ return true , nil
423
+ }
424
+
425
+ // recognizeUserDefinedValues recognizes user defined values assigned with opentelemetry.io/ prefix
426
+ func (i * sdkInjector ) recognizeUserDefinedValues (ctx context.Context , ns corev1.Namespace , pod corev1.Pod , deployment appsv1.Deployment , index int ) map [string ]string {
427
+
428
+ existingRes := map [string ]bool {}
429
+ existingResourceEnvIdx := getIndexOfEnv (pod .Spec .Containers [index ].Env , constants .EnvOTELResourceAttrs )
430
+
431
+ if existingResourceEnvIdx > - 1 {
432
+ existingResArr := strings .Split (pod .Spec .Containers [index ].Env [existingResourceEnvIdx ].Value , "," )
433
+ for _ , kv := range existingResArr {
434
+ keyValueArr := strings .Split (strings .TrimSpace (kv ), "=" )
435
+ if len (keyValueArr ) != 2 {
436
+ continue
437
+ }
438
+ existingRes [keyValueArr [0 ]] = true
439
+ }
440
+ }
441
+
442
+ resMap := map [string ]string {}
443
+
444
+ for key := range existingRes {
445
+ if strings .HasPrefix (key , constants .ReservedNamespace + "/" ) {
446
+ // now if it has the prefix opentelemetry.io/ then we need to check if the attribute name is already present in the resource attributes
447
+ // then do the operation accordingly
448
+ }
449
+ }
450
+ return resMap
451
+ }
452
+
405
453
// creates the service.instance.id following the semantic defined by
406
454
// https://github.com/open-telemetry/semantic-conventions/pull/312.
407
455
func createServiceInstanceId (namespaceName , podName , containerName string ) string {
0 commit comments