Skip to content

Commit 1e49ab0

Browse files
committed
reserved opentelemetry.io namespace
1 parent 41295b4 commit 1e49ab0

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

pkg/instrumentation/sdk.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,91 @@ func chooseServiceVersion(pod corev1.Pod, index int) string {
401401
return tag
402402
}
403403

404+
405+
/*
406+
Desire for a Reserved Namespace:
407+
There's a desire to reserve a specific namespace, in this case, .opentelemetry.io/, for special instructions or configurations related to OpenTelemetry.
408+
409+
User-Defined Values in the Namespace:
410+
Users are expected to set values within this reserved namespace, such as 'resource.opentelemetry.io/service.name' or 'resource.opentelemetry.io/my.attribute: some-value' on a pod or deployment.
411+
412+
Recognition by OpenTelemetry Operator:
413+
The OpenTelemetry Operator should be designed to recognize and understand these user-defined values within the reserved namespace.
414+
415+
Purpose of Recognition:
416+
Upon recognizing these values, the OpenTelemetry Operator is expected to perform certain actions or configurations based on the provided instructions.
417+
For example, if a user sets 'resource.opentelemetry.io/service.name' on a pod, the operator should understand that this is an instruction to set the service name for that specific pod.
418+
419+
Dynamic Configuration Based on Annotations:
420+
Annotations on Kubernetes resources (e.g., pods or deployments) are used as a means of providing configuration instructions.
421+
If an annotation like 'resource.opentelemetry.io/my.attribute: some-value' is set, the OpenTelemetry Operator should interpret this as an instruction to set a specific attribute (e.g., my.attribute) with a particular value (some-value) for the associated resource.
422+
423+
424+
425+
TODO
426+
according to the issue the end result should be something like this:
427+
for example, if I was to set 'resource.opentelemetry.io/service.name' on a pod, then use instrumentation CRDs to add instrumentation, the value of that annotation would be propagated to the instrumentation.
428+
429+
the above example is doing that in the following way: if a user sets 'resource.opentelemetry.io/service.name' on a pod, the operator should understand that this is an instruction to set the service name for that specific pod.
430+
then the operator should interpret this as an instruction to set a specific attribute (e.g., my.attribute) with a particular value (some-value) for the associated resource.
431+
and finally the operator should propagate the value of that annotation to the instrumentation.
432+
433+
in simple words the operator should understand that this is an instruction to set the service name for that specific pod and then propagate the value of that annotation to the instrumentation.
434+
propogate means that the operator should interpret this as an instruction to set a specific attribute (e.g., my.attribute) with a particular value (some-value) for the associated resource.
435+
436+
*/
437+
438+
/*
439+
Add a new namespace as a reserved namespace (e.g., *.opentelemetry.io/*).
440+
Add a new function to the operator to recognize and understand user-defined values within the reserved namespace.
441+
Add a new function to the operator to perform certain actions or configurations based on the provided instructions.
442+
Add a new function to the operator to set the service name for that specific pod.
443+
Add a new function to the operator to set a specific attribute (e.g., my.attribute) with a particular value (some-value) for the associated resource.
444+
Add a new function to the operator to interpret this as an instruction to set a specific attribute (e.g., my.attribute) with a particular value (some-value) for the associated resource.
445+
In the createResourceMap function, add code to parse the reserved namespace and set the associated values as resource attributes.
446+
*/
447+
448+
// create/reserve namespace
449+
450+
func (i *sdkInjector) createReservedNamespace(ctx context.Context) (corev1.Namespace, error) {
451+
ns := corev1.Namespace{}
452+
ns.Name = "opentelemetry.io"
453+
err := i.client.Create(ctx, &ns)
454+
if err != nil {
455+
return ns, err
456+
}
457+
return ns, nil
458+
}
459+
460+
// Add a new function to the operator to recognize and understand user-defined values within the reserved namespace.
461+
462+
func (i *sdkInjector) recognizeUserDefinedValues(ctx context.Context, ns corev1.Namespace) (corev1.Namespace, error) {
463+
// what we need to do here is to recognize and understand user-defined values within the reserved namespace.
464+
// what kind of user-defined values? the ones that are set on a pod or deployment.
465+
// how do we do that? we need to use annotations on Kubernetes resources (e.g., pods or deployments) as a means of providing configuration instructions.
466+
// what kind of annotations? the ones that are set on a pod or deployment.
467+
// we will use recognise if the user set the value as open-telemetry.io/attribute: some-value
468+
// then we will use the value of that annotation to set a specific attribute (e.g., my.attribute) with a particular value (some-value) for the associated resource.
469+
470+
// check for the namespace is created or not if the namespace is not created then create it else throw an error
471+
472+
err := i.client.Get(ctx, types.NamespacedName{Name: ns.Name}, &ns)
473+
if err != nil {
474+
return ns, err
475+
}
476+
477+
// Get the all pods in the givennamespace
478+
479+
480+
// TODO - use the annotations to recognize and understand user-defined values within the reserved namespace
481+
// TODO - use the annotations to set the specific attribute with a particular value for the associated resource
482+
483+
return ns, nil
484+
485+
}
486+
487+
488+
404489
// createResourceMap creates resource attribute map.
405490
// User defined attributes (in explicitly set env var) have higher precedence.
406491
func (i *sdkInjector) createResourceMap(ctx context.Context, otelinst v1alpha1.Instrumentation, ns corev1.Namespace, pod corev1.Pod, index int) map[string]string {

0 commit comments

Comments
 (0)